Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with XGraphics and XTextFormatter Draw methods #445

Open
debirus opened this issue Jun 11, 2024 · 0 comments
Open

Problem with XGraphics and XTextFormatter Draw methods #445

debirus opened this issue Jun 11, 2024 · 0 comments

Comments

@debirus
Copy link

debirus commented Jun 11, 2024

I found that after using any Draw method of the XGraphics object it is no longer possible to use the DrawString method of the XTextFormatter on the same object, example:

//-----
XGraphics graf = XGraphics.FromPdfPage(page);
//-----
graf.DrawImage(img, new XRect(x, y, w, h));
//-----
tf = new XTextFormatter(graf);
tf.Alignment = format;
tf.DrawString(text, fontCache.FontChar, fontCache.Brush, rect, XStringFormats.TopLeft);

When I save the PDF at the end, the img is present on the page while the text is not, it cannot be seen even if it is in effect present as text on the document, but remains invisible.

By reversing the order, i.e. using tf.DrawString first and then graf.DrawImage, both img and text can be seen clearly on the final PDF.

The same problem is present after using any graf Draw method.

After several attempts I found a workaround to solve the problem, after using a graf Draw method I recall these instructions:

PdfPage page = graf.PdfPage;
graf.Dispose();
graf = XGraphics.FromPdfPage(page);

Somehow it returns the graf object to its original state while maintaining the changes made to the pdf page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant