tags:

views:

1009

answers:

3

Hi!

I'm using itextsharp to generate the PDFs, but I need to change some text dynamically. I know that it's possible to change if there's any AcroField, but my PDF doen's have any of it. It just has some pure texts and I need to change some of them.

Does anyone know how to do it?

Thanks in advance!

+2  A: 

I haven't used itextsharp, but I have been using PDFNet SDK to explore the content of a large pile of PDFs for localisation over the last few weeks.

I would say that what you require is absolutely achievable, but how difficult it is will depend entirely on how much control you have over the quality of the files. In my case, the files can be constructed from any combination of images, text in any random order, tables, forms, paths, single pixel graphics and scanned pages, some of which are composed from hundreds of smaller images. Let's just say we're having fun with it.

In the PDFTron way of doing things, you would have to implement a viewer (sample available), and add some code over a text selection. Given the complexities 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 whatever other fundamental object is used to make up text). The string could then be edited and applied by copying the entire page of the document into a new page, replacing the selected elements with your new string. You would probably have to do some mathematics to get this to work well though, as just about everything in PDF is located on the page by means of an affine transform.

Good luck. I'm sure there are people on here with some experience of itextsharp and PDF in general.

IanGilham
Thanks Ian! I will take a look at it! :-)
AndreMiranda
A: 

Generally speaking this is not possible. Check out this FAQ question which discusses the issue. The FAQ addresses iText (the Java version project from which iTextSharp was derived) but applies to iTextSharp as well.

Jay Riggs
+1  A: 

Actually, I have a blog post on how to do it! But like IanGilham said, it depends on whether you have control over the original PDF. The basic idea is you setup a form on the page and replace the form fields with the text you want. (You can style the form so it doesn't look like a form)

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

Here is a link to the full post:

Using a template to programmatically create PDFs with C# and iTextSharp

SkippyFire