繁体   English   中英

如何使用iTextSharp在pdf文档的特定位置写入zapfdingbatslist

[英]How to write in a specific location the zapfdingbatslist in a pdf document using iTextSharp

我想使用zapfdingbatslistiTextSharp中的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的原始开发人员,包括DocumentPdfWriterZapfdingbatsList ,...类),如果您花了一些时间阅读ZapfdingbatsList ,我将不胜感激。 iText文档。

让我们从第2章开始,看一些介绍Font类的C#示例

例如:

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); 

其中200500是X和Y坐标, 0是以度表示的角度。 除了ALIGN_CENTER ,您还可以选择ALIGN_RIGHTALIGN_LEFT

在代码示例中,您正在使用列表将Zapfdingbats字形添加到文档中。 请花点时间把自己放在我的位置。 感觉像您是参加Red Hot Chili Peppers音乐会的袜子的发明者吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM