PDFs are collection of objects that will be rendered by a page renderer; modifying the blocks by "replacing placeholders" might work but, on the other hand, it might not. For example if you write "[[zip_code]]" in a document, chances are that it will be kerned into three or more chunks, and the PDF (once made readable - it might not be) will not contain the ASCII sequence "[[zip_code]]" at all.
Your best bet is to use PDFLib or CPDF to generate a blank pdf from a template where you will store the coordinates of each text block. Actually you could just do that in a single PHP file like this:
$tokens = array(
'zip' => array( 2500, 1730, ... ),
'address' => array( 2600, 1234, ... ),
...
);
foreach ($tokens as $token => $info) {
list ($x, $y /*, ..font... size...*/) = $info;
PDF_show_XY ($pdf, $record[$token], $x, $y );
}
PDF_end_document($pdf);
Then when you have the page to "overlay" over your chosen background, you can do that with a tool such as pdftk
:
pdftk foreground.pdf background background.pdf output merged.pdf
With the appropriate resolution unit (e.g. tenths of a mm), you can print the background and measure the positions of where you want the fields with an ordinary ruler.
The PDFs will be a bit bulkier than if you had generated them from scratch, but they will be print-perfect - the two layers will be "merged" on print, and won't otherwise interfere with each other.