logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Guest  
#1 Posted : Tuesday, December 26, 2017 11:24:21 AM(UTC)
Guest

Rank: Guest

Groups: Guests
Joined: 1/5/2016(UTC)
Posts: 162

Was thanked: 5 time(s) in 5 post(s)
When adding text to a page using your code from this post, I get inconsistent results if there are unpaired parentheses in the text. I believe that Pdfium.Net is not escaping the characters correctly in this situation.

For example, if I use:

Code:

txtObj.TextUnicode = ")";


the resulting pdfPage will render to an image correctly with code like this:

Code:

pdfPage.Render(pdfBitmap, 0, 0, pdfBitmap.Width, pdfBitmap.Height, Patagames.Pdf.Enums.PageRotate.Normal, Patagames.Pdf.Enums.RenderFlags.FPDF_ANNOT);


however, saving the same PDF with this code:

Code:

pdfDocument.Save(memoryStream, SaveFlags.NoIncremental, 17);


results in an invalid file with unpredictable results. Acrobat might display a corrupted version of the encodedText in place of the parentthesis (e.g. Tj ET BT / 12 Tf 1 0 0 1 383.707 515.5225 Tm 255), or it might simply refuse to open the file at all.

On the other hand, if I manually escape all parenthesis before calling EncodeText like this:

Code:

pdfTextObject.TextAnsi = pdfTextObject.TextAnsi.Replace("(", @"\(").Replace(")", @"\)");


...then pdfDocument.Save works as expected, but now pdfPage.Render now displays the extra backslash used to escape the parenthesis, and this is true whether the parenthesis are paired or unpaired.

I am creating a PDF from scratch using your EncodeTextObject() function, then using pdfPage.Render() to preview the PDF in a web application, and finally pdfDocument.Save() to create a PDF file, but I think these two functions are handling escape characters in either an incorrect or inconsistent way.

Edited by user Tuesday, December 26, 2017 11:26:26 AM(UTC)  | Reason: correcting double negative

Guest  
#2 Posted : Thursday, January 18, 2018 9:25:35 AM(UTC)
Guest

Rank: Guest

Groups: Guests
Joined: 1/5/2016(UTC)
Posts: 162

Was thanked: 5 time(s) in 5 post(s)
One workaround for inconsistent behavior between the PDF and the rendered pages is to save and reload the PdfDocument to and from a MemoryStream - after modifying the PDF, but before rendering the page.

Code:
MemoryStream memoryStream = new MemoryStream;
PdfPage.Document.Save(memoryStream, saveFlags, 17);
pdfDocument = PdfDocument.Load(memoryStream);
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.