Is there a way to replace text in a PDF using itextsharp?

I use itextsharp to create PDF files, but I need to change the text dynamically. I know what can be changed if there is AcroField, but my PDF-doen has some of this. He just has some blank texts, and I need to change some of them.

Does anyone know how to do this?

+6
c # itextsharp
source share
3 answers

Actually, I have a blog post on how to do this! But, as Jan Gilham said, it depends on whether you have control over the original PDF. The main idea is that you customize the form on the page and replace the form fields with the desired text. (You can create a form so that it does not look like a form)

If you do not have control over the PDF, let me know how to do it!

Here is the link to the full post:

Using a template to programmatically create PDF files with C # and iTextSharp

+4
source share

I did not use itextsharp, but I used the PDFNet SDK to examine the contents of a large pile of PDF files for localization over the past few weeks.

I would say that what you need is absolutely achievable, but how difficult it is depends entirely on how much you control the quality of the files. In my case, files can be created from any combination of images, text in any random order, tables, shapes, paths, single pixel graphics and scanned pages, some of which consist of hundreds of smaller images. Let me just say that we are having fun with him.

In the way PDFTron works, you will need to implement a viewer (sample is available) and add code for text selection. Given the complexity of the format, it may be necessary to implement a simple editor in a secondary dialog with the ability to expand the selection to the next line (or any other fundamental object used to compose the text). Then this line can be edited and applied by copying the entire page of the document to a new page, replacing the selected elements with a new line. You may have to do some math to make it work well, since almost everything in the PDF file is on the page using the affine transform .

Good luck. I am sure that there are people with some experience with itextsharp and PDF in general.

+2
source share

This question arises from time to time on the mailing list . The same answer is given again and again - NO . See this thread for an official response from the person who created iText .

This question should be a frequently asked question in the wiki tag.

-one
source share

All Articles