Hello,
Main Issue:
I'm having some issues with using the AddText method. The text for most of the fonts I've tried cuts off the top of some of the characters.
I tried using the TextFormated TextHeight and TextWidth properties to over come this, but it did not help.
A another issue:
This is a minor issue, the TextWidth value return from the TextFormated object I believe is too small. See attached pdf when I created LocalLinks around the text.
Some documentation issues:
While troubleshooting the above I found a couple of confusing documentation items.
1. The constructor for FormattedText says fontName - The font name or the full ttf file name with the absolute path. Documentation should be updated to say the postscript name of the font since that's what is being used. It took me a while to figure out why my fonts were not working until I opened the fonts in a font software program and tried each font name listed. Ie. ComicSansMS works while Comic Sans MS does not work.
2. From the Aspose.PDF.Kit.chm file: The title of the PdfFileMend.AddText shows the parameters of single instead of float. This threw me off a bit thinking the TextWidth issue was an issue converting from float to single.
PdfFileMend.AddText Method (FormattedText, Int32, Single, Single)
Code used for adding text and link in the attached pdf:
PdfFileMend pfm = new PdfFileMend(this.textBoxOutputFolder.Text, "C:\\tfs\\test.pdf" );
FormattedText ft1 = new FormattedText("Comic Sans MS - 2", Color.Red, "ComicSansMS", EncodingType.Winansi, true, 12);
FormattedText ft2 = new FormattedText("Comic Sans MS - 2", Color.Red, "ComicSansMS", EncodingType.Winansi, true, 12);
FormattedText ft3 = new FormattedText("Times Roman with TextWidth and TextHeight - 2", Color.Red, Aspose.Pdf.Kit.FontStyle.TimesRoman, EncodingType.Winansi, false, 12);
FormattedText ft4 = new FormattedText("Times Roman - 2", Color.Red, Aspose.Pdf.Kit.FontStyle.TimesRoman, EncodingType.Winansi, false, 12);
pfm.AddText(ft1, 1, 50f, 30f);
pfm.AddText(ft2, 1, 50f, 50f, 50f + ft2.TextWidth, 50f + ft2.TextHeight);
pfm.AddText(ft3, 1, 50f, 80f, 50f + ft3.TextWidth, 80f + ft3.TextHeight);
pfm.AddText(ft4, 1, 50f, 100f);
pfm.Close();
// New a object of Class PdfContentEditor.
PdfContentEditor editor = new PdfContentEditor();
// Bind target pdf document .
editor.BindPdf("C:\\tfs\\test.pdf");
//Create Link.
editor.CreateLocalLink(new Rectangle(50, 30, (int)Math.Ceiling(ft1.TextWidth), (int)Math.Ceiling(ft1.TextHeight)), 2, 1, Color.Green);
editor.CreateLocalLink(new Rectangle(50, 50, (int)Math.Ceiling(ft2.TextWidth), (int)Math.Ceiling(ft2.TextHeight)), 2, 1, Color.Green);
editor.CreateLocalLink(new Rectangle(50, 80, (int)Math.Ceiling(ft3.TextWidth), (int)Math.Ceiling(ft3.TextHeight)), 2, 1, Color.Green);
editor.CreateLocalLink(new Rectangle(50, 100, (int)Math.Ceiling(ft4.TextWidth), (int)Math.Ceiling(ft4.TextHeight)), 2, 1, Color.Green);
editor.Save("C:\\tfs\\test_link.pdf");
Thanks,
Chris