pdftk and the
fill_form function to populate several .pdf files from two .fdf files. The issue is that whichever .fdf file is applied last overwrites blanks over all the data that it doesn’t have.
One .fdf has personalized data for each unique .pdf and the other is global data that’s common on all the .pdf files. So there are many personalized .fdf files generated on an as needed basis and one global .fdf. Since the .pdf files are all the same layout, the .fdf files are all the same layout as well. Hence why they are overwriting each other.
Is there a simple way to replace specific lines of one document with the exact same lines from another document?
My thought is to just use
sed to brute force the data into one .fdf file and then fill each .pdf from that. But that would require all these lines of
sed in my script multiplied by the number of .pdf files I need to create. Seems really clunky to me.
I’m not familiar with pdftk (I generate my PDFs from ezPDF and php). But, is it possible that the last fdf file has a background that is merely covering the previously loaded files? the sed manipulation would be a creative solution but maybe not your best option.
BTW, for the curious here is what I use: GitHub - rospdf/pdf-php: Official R&OS PHP Pdf repository
I have code that I wrote with the above package 18 years ago and it runs daily in a production environment and is as stable as a large rock.
I didnt know you can progromaticly fill forms, that is awesome
I’m studying the Adobe PDF file specifications and I found this line
Unless otherwise indicated in the table, importing a field causes the values of the entries in the FDF field dictionary to replace those of the corresponding entries in the field with the same fully qualified name in the target document.
This appears to be what’s happening with my script. One .fdf fills the fields and the other .fdf overwrites blanks in those fields because the .fdf files are identical and therefore have the same “fully qualified name” for all the fields.
I will do more studying to see if there is some sort of flag in the file I can write in to disable this behaviour.
In the meantime I have added some lines of
sed to my “global” .fdf script that replaces the lines that specify the fields that my “personal” .fdf file fills. So it replaces the lines with blank space (so that the line numbers wouldn’t change and mess up the rest of the script) and it doesn’t overwrite those fields any longer.
The script functions now as I intended, albiet, rather clunkily I think. I will definitely be refining it and adding functionality once I figure out the original issue properly.