[英]How to write in a specific location the zapfdingbatslist in a pdf document using iTextSharp
我想使用zapfdingbatslist在iTextSharp中的pdf文檔中的特定位置打一個復選標記。
到目前為止,我所能做的就是可以顯示對勾標記,但這都在文檔的側面,而不是在我希望的特定X,Y坐標上。 我下面有一段代碼,希望可以使您對我所談論的內容有所了解。
String outputFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf");
System.IO.FileStream fs;
Document doc = new Document(PageSize.A4, 20, 20, 10, 10);
PdfContentByte cb;
PdfWriter writer;
fs = new System.IO.FileStream(outputFile, System.IO.FileMode.Create);
writer = PdfWriter.GetInstance(doc, fs);
doc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
writer.AddViewerPreference(PdfName.PICKTRAYBYPDFSIZE, PdfBoolean.PDFTRUE);
doc.Open();
cb = writer.DirectContent;
List myList = new ZapfDingbatsList(52); // Check mark symbol from Dingbatslist
// I have some more code here but it is not needed for the problem
// and thererfore not shown
// I could shohw the dingbatslist check mark here
myList.Add(" ");
doc.Add(myList); // However I want to show it in a specific X, Y position
doc.Close();
writer.Close();
fs.Close();
任何想法?
順便說一句,我是大多數iText文檔的作者(以及iText的原始開發人員,包括Document
, PdfWriter
, ZapfdingbatsList
,...類),如果您花了一些時間閱讀ZapfdingbatsList
,我將不勝感激。 iText文檔。
例如:
Font font = new Font(Font.FontFamily.ZAPFDINGBATS, 12);
一旦有了Font對象,就可以創建一個Phrase
(也在第2章中說明):
Phrase phrase = new Phrase(zapfstring, font);
其中zapfstring
是包含所需的任何Zapfdingbats字符的string
。
要在絕對位置添加該短語,您需要閱讀第3章。看一下示例示例 ,例如FoobarFilmfestival.cs :
PdfContentByte canvas = writer.DirectContent;
ColumnText.ShowTextAligned(canvas, Element.ALIGN_CENTER, phrase, 200, 500, 0);
其中200
和500
是X和Y坐標, 0
是以度表示的角度。 除了ALIGN_CENTER
,您還可以選擇ALIGN_RIGHT
或ALIGN_LEFT
。
在代碼示例中,您正在使用列表將Zapfdingbats字形添加到文檔中。 請花點時間把自己放在我的位置。 感覺像您是參加Red Hot Chili Peppers音樂會的襪子的發明者嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.