facebooktwittermenuarrow-up

GemBox Support Forum

Adding text to a page of existing PDF file

How do I add text to a page of an existing pdf when I don’t know what fonts exist in the document? Can I just use /F1, or would I need to add a font? If adding, how do I know what to name when the number of existing fonts (n) is unknown, /F(n+1)?

Thanks!

Hi Brian,

Are you perhaps referring to Content Stream example?

If yes, note that this example uses a simple Type1 Font (Helvetica) which is one of the Standard 14 Fonts that don’t need to be embedded in a PDF file. But for other fonts, their usage will be more complex.

Nevertheless, I’m afraid that current GemBox.Pdf lacks an easy-to-use API for creating new or editing existing PDF text content.
However, note that we’re actually working on it at this moment, these new planned improvements and API will simplify such tasks.

In the meantime, I would recommend you to try using both GemBox.Pdf and GemBox.Document to accomplish this. For example, please check the AddText.zip project.

In short, this project uses GemBox.Document to create a new PDF file with the desired content and then uses GemBox.Pdf to append (or prepend) that content to the existing PDF. Using this approach you can add any content that you want (paragraphs, images, tables, hyperlinks, headers, footers, etc.).

As an FYI, for this requirement, you can feel free to use the GemBox.Document Free.
The Free mode enables you to create an unlimited number of documents that have up to 20 paragraphs and thus you can create an unlimited number of new PDF files and append their content to your existing PDF file.

Regards,
Mario

That sounds great. I am looking forward to the new features. As far as using GemBox.Document, we really can’t do that for this application since we receive the PDFs from third parties.

Hi,

Note, you won’t use GemBox.Document to open or read that existing PDF file from the third party.
Instead, you would use GemBox.Document as a sort of an intermediate for creating new text content (or any other content) for that existing PDF file.

In other words, you would use GemBox.Document to create a PDF that would have just the text that you want to insert and then you would use GemBox.Pdf to append the content of that new PDF into some page of the existing PDF.

I hope this explains better this approach, if not please let me know and I’ll try again.

Regards,
Mario