How to write zapfdingbatslist in a specific place in a pdf document using iTextSharp

I want to checkmark using zapfdingbatslist in my pdf in iTextSharp at a specific location .

What I can do so far, I can show a checkmark, but all this is on the side of the document, and not on the specific X, Y coordinate that I want. I have the code below, which I hope will give you an idea of ​​what I'm talking about.

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

Any idea?

0
c # pdf itextsharp
source share
1 answer

By the way, I am the author of most of the iText documentation (as well as the original iText developer, including Document , PdfWriter , ZapfdingbatsList , ... classes), and I would appreciate if you spent some time reading the iText documentation.

Let's start with Chapter 2 and take a look at some C # examples that show the Font class.

For example:

 Font font = new Font(Font.FontFamily.ZAPFDINGBATS, 12); 

Once you have a Font object, you can create a Phrase (also explained in chapter 2):

 Phrase phrase = new Phrase(zapfstring, font); 

Where zapfstring is a string containing any Zapfdingbats character you want.

To add this phrase to an absolute position, you need to read chapter 3. Take a look at examples for inspiration, for example FoobarFilmfestival.cs :

 PdfContentByte canvas = writer.DirectContent; ColumnText.ShowTextAligned(canvas, Element.ALIGN_CENTER, phrase, 200, 500, 0); 

Where 200 and 500 are the X and Y coordinates, and 0 is the angle, expressed in degrees. Instead of ALIGN_CENTER you can also choose ALIGN_RIGHT or ALIGN_LEFT .

In your code example, you added a Zapfdingbats glyph to a document using a list. Please take some time to put me in my place. Don't you think you're the inventor of the sock at the Red Hot Chili Peppers concert?

+3
source share

All Articles