What's the best approach for modifying PDF interactive form fields on iOS?
Asked Answered
O

1

6

I've been doing some head banging on this one and solicit your advice.

I am building an app that as part of it's features is to present PDF forms; meaning display them, allow fields to be changed and save the modified PDF file back out. UIWebViews do not support PDF interactive forms.

Using the CGPDF apis (and benefit from other questions posted here and elsewhere), I can certainly present the PDF (without the form fields/widgets), scan and find the fields in the document, figure out where on the screen to draw something and make them interactive.

What I can't seem to figure out is how to change the CGPDFDictionary objects and write them back out to a file. One could use the CGPDF Apis to create a new PDF document from whole cloth, but how do you use it to modify an existing file?

Should I be looking elsewhere such as 3rd party PDF libs like PoDoFo or libHaru?

I'd love to hear from anyone who has successfully modified a PDF and written it back out as to your approach.

Oaks answered 14/1, 2011 at 21:19 Comment(2)
I've asked this question a few times (with bounty) to no results. From a lot of research and work into this, you need to write a library to do it using C/C++. PoDoFo doesn't save back, and libHaru doesn't open existing pdfs (based on memory, could be backwards). I have since just moved on from that project and tried to forget the horrors of CGPDF* API. shudderVelasquez
Agreed. You will most likely have to roll your own. If you don't require the result to be editable, you could perhaps also create a PDF from scratch (UIGraphicsBeginPDFContextToFile) and render your existing PDF plus any additional overlays/text that you create into it. This will be pretty slow though and the result wouldn't be interactive anymore.Maitilde
R
6

I once did this incredibly cheaply by munging through the PDF -- I mean using regular expressions -- and just dirtily changing the actual raw text of the raw PDF data file.

It can work perfectly in simple situations where you are easily able to find the value in question.

No idea what you're trying to do here but a lateral thought! Hope it helps!

Ruth answered 18/1, 2011 at 22:15 Comment(3)
Thanks everybody for your comments.Oaks
@joe Blow, Could you explain a bit more on how you did that. May be by some example code etc. ThanksJobyna
@joe Blow, This sounds like a perfect solution for me. Can you elaborate on how raw pdf data is read in objective-c?Loughlin

© 2022 - 2024 — McMap. All rights reserved.