Page 1 of 1

DrawText not working correctly

Posted: Tue Apr 14, 2020 9:48 pm
by shollyd
I am working with pdf documents, and I wrote an application for the folks in our document control to electronically 'stamp' the documents they received with a date. I essentially have used the sample in the DrawText (pdf) in the online documentation, except I use some math for dynamic positioning. For most documents, everything works as expected. But for a few documents, the text it writes is squished. The height of the text is what it should be, but the width is so skinny it looks like vertical lines. Anyone have any suggestions? I can post the code if it would help, but like I said, it is basically copy/paste from the sample.

Re: DrawText not working correctly

Posted: Wed Apr 15, 2020 1:17 pm
by Hugo
Hi Shollyd,

It would be helpful if you could provide the code+inout document used however before you do so please try this:
Use the NormalizePage method https://www.gdpicture.com/guides/gdpicture/Gd ... rmalize%2C . Use this before drawing the text on your PDF.
The normalize method should usually be used on PDFs before using drawing methods.

Let me know if this solves your issue.

Regards

Re: DrawText not working correctly

Posted: Wed Apr 15, 2020 2:34 pm
by shollyd
Well, it may have very well have fixed my issue. Unfortunately, I get a "NormalizePage is not a member of GdPicturePDF" error. I imagine this is because we are still using GdPicture 10. While it is possible I can convince my company to upgrade, that doesn't help me in the short term. Unless you have any other ideas, I may have to back up and punt. Ultimately, I convert these pdfs to tiffs for use with our online system. So, for these, I may convert to tiff, then draw the date on the tiff rather than drawing on the pdf and then converting to tiff.

Re: DrawText not working correctly

Posted: Wed Apr 15, 2020 6:01 pm
by shollyd
Not to get too far off subject here, but I am writing the code to convert to a tif first, then add the stamp (so I have more control over the text size), and I got everything to work fine, except when I save it, I only get one page.

Code: Select all

        Dim originalimage As Integer = oGdPictureImaging.TiffCreateMultiPageFromFile("C:\Original.tif")
        Dim TiffCompression As GdPicture10.TiffCompression = oGdPictureImaging.GetTiffCompression(originalimage)
        result = oGdPictureImaging.TiffSaveAsMultiPageFile(originalimage, "C:\Output.tif", TiffCompression)
I found examples elsewhere where I add each subsequent page with TiffAddToMultiPageFile, but why? Is there a method that saves all pages at once?

(I left out the drawtext method as it was irrelevant)

Re: DrawText not working correctly

Posted: Wed Jul 26, 2023 8:43 am
by admirem
It's actually better to use the self-design pattern. Ensure exportable PDF documents are in good condition. However, if you want the string rendered as an image, you'll need to employ a different method, which involves opening a graphics context, drawing the string into the context (as a bitmap), and then retrieving the picture shown by the context.