我有使用短語生成 PdfCell 的簡單代碼(iTextShar 庫):
//I create new Phrase
Phrase p = new("Lorem ipsum", myFont);
//I set leading for Phrase
p.setFixedLeading(10f);
//I create new Table Cell end insert Phrase
PdfPCell cell = new(p);
為什么我不能直接在 PdfPCell 上生成 Phrase 并同時運行方法 .setFixedLeading。有這樣的想法?
PdfPCell cell = new(Phrase p("Lorem ipsum", myFont).setFixedLeading(10f));
在創建新的 Phrase 物件時,有什么方法可以使用 .setFixedLeading 方法設定 Lead 嗎?
uj5u.com熱心網友回復:
您可以撰寫自己的方法:
private Phrase CreatePhraseWithFixedLeading(string text, Font font, float fixedLeading)
{
Phrase p = new(text, font);
p.setFixedLeading(fixedLeading);
return p;
}
用法是
Phrase p = CreatePhraseWithFixedLeading("lorem ipsum", myFont, 10f);
PdfPCell cell = new(p);
或者,如果您在創建單元格后不需要該短語
PdfPCell cell = new(CreatePhraseWithFixedLeading("lorem ipsum", myFont, 10f));
如果您在創建短語后有更多方法可以呼叫,您可以查看構建器模式。
但另一方面,你應該問問你從中得到了什么。您提供的代碼非常好。不要試圖將盡可能多的內容放在一行中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/352979.html
下一篇:如何從底部垂直列印?
