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

我想在特定位置的 iTextSharp中的pdf文档上使用zapfdingbatslist设置复选标记。

到目前为止我可以做的是我可以显示复选标记,但它全部位于文档的一侧,而不是我想要的特定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 ,…类),如果你花一些时间阅读,我会很感激。 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_RIGHTALIGN_LEFT ,而不是ALIGN_LEFT

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