On Mar 20, 2008, at 7:14 AM, basecode wrote:
There is no "good" solution for this task I think.
Willie Alberty described why:
http://www.nabble.com/Zend_Pdf-replace-placeholders--
td4988495s16154.html#a5015716
Thanks for the link--I had forgotten about that message. After re-
reading that technical explanation, I realize I left out one
important piece of information:
Although you can open a PDF file in a text editor and more or less
follow its structure, it is not a text file. PDF documents are binary
files. You can irreparably damage a PDF by doing string replacement
operations.
The reason for this is the document trailer which appears at the end
of every PDF file. This is an array of byte offsets to the various
objects contained within the document. If you do a string replacement
that changes the byte length of the string, you've wrecked this
offsets table, and the PDF viewer will be unable to read the document.
If you're very careful to maintain the byte length of the strings
you're replacing, you can actually change existing PDF content in
this way, but you're treading on thin ice. If you keep the byte
offsets in document trailer updated, you can change string lengths
too, but this gets to be rather difficult.
Of course, this all assumes that the page's content stream is not
compressed and you can actually find the string you're looking to
replace. Most PDF generators compress content streams to save space,
as Kai observed with the example document from MS Publisher.
On Mar 19, 2008, at 4:39 PM, Kai Meder wrote:
does anyone know a good solution to:
- create a fully designed PDF template (e.g. from MS Publisher)
- replace embedded placeholders in this PDF to bulk-create PDFs.
It seems any PDF I create contains a binary data-stream and no raw-
text whatsoever. So whats the best way to create such Template-PDFs?
Is there any official Variable/Placeholder Syntax for PDFs?
The only real solution with Zend_Pdf today is to design your template
in such a way that you leave "holes" for the replacement text (think
form fields). You then use Zend_Pdf to then draw your new text in a
new layer on top of the page, effectively filling in these holes.
--
Willie Alberty, Owner
Spenlen Media
[EMAIL PROTECTED]
http://www.spenlen.com/