Putting data into existing PDF
I have had to introduce data for NGO into an existing PDF. Why PDF ? Because yes, it is easy to print. but from a templating point of view it is a nightmare. by templating I understand putting data at specific places , like
First Name :
Last Name :
And filling in the blanks.
The solution: complicated. The pdf can have Form fields to be filled . I discovered
https://www.pdfescape.com/windows/
that can be used to put form fields into existing documents and save the pdf.
And I figured that this is all. Nope. Look here
109 0 obj
<</Subtype/Widget/Rect[119.52 347.25 565.92 358.77]/AP<</N 110 0 R>>/DA(/Helv 8.64 Tf 0 g)/F 4/FT/Tx/P 1 0 R/T(untitled22)/Q 0/V(*NumeONG*)>>
endobj
110 0 obj
<</Type/XObject/Subtype/Form/BBox[0 0 446.39999 11.51999]/Resources<</Font<</Helv 77 0 R>>>>/Filter/FlateDecode/Length 90>>stream
xœÓ©Ppòuær
á2PIå\†@ª
ÈNñ‹¸ô=RsÊ,ôÌLBÒ¸€ÐPÁHÁHÏÌL!$—+ZC˯47ÕßÏ]K36Ä‹Ë5„Ëh&endstream
endobj
The PDF format is a primitve form of XML. The 109 0 obj finishes with endobj . I figured that I will replace
*NumeONG*
with the name and all will be ok. Nope . The critical point is the stream at the next obj
110 0 obj
<</Type/XObject/Subtype/Form/BBox[0 0 446.39999 11.51999]/Resources<</Font<</Helv 77 0 R>>>>/Filter/FlateDecode/Length 90>>stream
xœÓ©Ppòuær
á2PIå\†@ª
ÈNñ‹¸ô=RsÊ,ôÌLBÒ¸€ÐPÁHÁHÏÌL!$—+ZC˯47ÕßÏ]K36Ä‹Ë5„Ëh&endstream
endobj
Not only is is encoded
Filter/FlateDecode
but also it says the length of the stream,
Filter/FlateDecode/Length 90
That is a problem, because the replacement for the name will be dynamic.
Solution?
The qpdf solftware http://qpdf.sourceforge.net that allows to transform those streams into something readable
qpdf –qdf –object-streams=disable m.pdf a.pdf
Leave a Reply