ILPDFKit icon indicating copy to clipboard operation
ILPDFKit copied to clipboard

Save over the original editable pdf?

Open ty-sang opened this issue 10 years ago • 18 comments

As the topic, is that possible to save some inputs to editable pdf?

ty-sang avatar Sep 25 '15 23:09 ty-sang

@shieer Would you were able to do it?

paresh-navadiya avatar Aug 24 '16 12:08 paresh-navadiya

very much needed... or otherwise need a method to pass form xml to PDF Doc so that it populates all the values before rendering

yasirmturk avatar Nov 01 '16 10:11 yasirmturk

Is there any progress on this? @paresh-navadiya @yasirmturk

hllGitHub avatar Jan 23 '17 08:01 hllGitHub

Saving inputs means be able to save a PDF with AcroForms. CoreGraphics desn't support AcroForms writing so a proper low level PDF writing functionality is needed. It may be very difficult to implement on top of CoreGraphics ...

lubbo avatar Jan 26 '17 09:01 lubbo

how these guys are handling it? http://www.pdftron.com/pdfnet/downloads.html https://pspdfkit.com/

yasirmturk avatar Mar 08 '17 15:03 yasirmturk

They use a proprietary PDF writer

lubbo avatar Mar 09 '17 19:03 lubbo

I'm about 3 days into the iOS/AcroForm/Edit/SaveBackAsAcroForm attempt. :) ILPDFKit is great if client is cool with flat PDF, but unfortunately mine isn't. What direction did you guys go?

back-40 avatar Mar 19 '17 20:03 back-40

same situation here... @back-40 this app https://itunes.apple.com/us/app/mupdf/id482941798?mt=8&ign-mpt=uo%3D4 does it perfectly and they claim to be open source.. but their forms are not overlay

yasirmturk avatar Mar 20 '17 13:03 yasirmturk

@yasirmturk Thanks I'll take a look at it. Have you used it before?

back-40 avatar Mar 20 '17 13:03 back-40

nops i m still trying to use @ILPDFKit

yasirmturk avatar Mar 20 '17 14:03 yasirmturk

Still digging on this. Does ILPDFKit have the ability to create a PDF with AcroForms?

back-40 avatar Mar 20 '17 20:03 back-40

no

yasirmturk avatar Mar 21 '17 07:03 yasirmturk

Careful: muPDF is open source but AGPL - you can't use that in the App Store and it's also viral. It's has commercial licensing options.

At https://pspdfkit.com (our commercial PDF SDK) we've spent a few years with around 15 people to get forms working, including a lot of edge cases, drawing appearance streams, nested fields and of course also JavaScript validations and all related event logic. It's a lot of work and we have a few thousand test cases that run on our CI. To write the data back you need to fully parse the PDF (especially fun if it has a user or owner password defined and is encrypted)

We're only today launched Forms on Android, that project also took a year and we leveraged a lot of code that we share between iOS and Android. Next up: Forms on our Web SDK.

Here's all the documentation you need to write your own parser. Check out Chapter 12.7 "Interactive Forms" of the PDF32000_2008.pdf and to generate the object tree work through Chapter 7 (Page 11 to 108). To generate the appearance streams you need to read most of Chapter 8/9 (Page 110-292; Fonts are hard). If you skip that than there'll be many documents where you fill in the form content but they either don't render at all or render invalid content. (Preview on macOS is especially bad on that) https://pspdfkit.com/guides/ios/current/features/rendering-pdf/

steipete avatar Apr 13 '17 21:04 steipete

we don't need it for the app store.. thanks for the info

yasirmturk avatar Apr 14 '17 11:04 yasirmturk

I ended up writing my own parser from scratch and then recreating the PDF with the form values put in. I maintained the acroforms so it is still editable via PDF viewers. Not an easy job, but I've done similar in the past. A few years back I wrote software that made extremely large PDFs with vector objects and serialized text for digital printing press systems.

back-40 avatar Apr 14 '17 13:04 back-40

great.. can did u made it available?

yasirmturk avatar Apr 17 '17 09:04 yasirmturk

Sorry, but I've too many hours in it make it free.

back-40 avatar Apr 18 '17 01:04 back-40

I suggest to save values in dictionary with key as formName and populate the PDF back after loading it.

like , I have PDF with TextField , its formName is "firstName" , then i enter some Text in it say "Saurabh" and while click on save button , i get the value from pdf , which i stored in dictionary! Now while loading same form again i will iterate through dictionary keys to get all saved values.

//saving values
NSDictionary *dict = [[NSMutableDictionary alloc]init];
for (ILPDFForm *form in pdf.document.forms)
{
    if(form.value.length)
    [dict setObject:form.value forKey:form.name];
}

//retrive values

for(NSString *strKey in dict.allKeys)
{
        [pdf.document.forms setValue:[dict objectForKey:strKey] forFormWithName:strKey];
}

Also you can save this dictionary to database if there is multiple PDF files to save & populate PDF back as per selection. However the SDK i am using is Old.Hope it will help.

SaurabhPrajapati avatar Jul 12 '17 10:07 SaurabhPrajapati