3

Let's say I have stamp.pdf or stamp.html and original.pdf.

stamp.pdf (stamp.html) contains a stamp and I want to place stamp.pdf over original.pdf in a certain position and generate a new pdf - original_stamped.pdf.

I would like to insert stamp.pdf as a pdf (vector graphic) or as html, but not converting to raster image and then insert into original_stamped.pdf.

I am talking about stamping or watermarking (over the page), but not just adding an additional page to pdf.

halfer
  • 19,824
  • 17
  • 99
  • 186
ihtus
  • 2,673
  • 13
  • 40
  • 58
  • FPDI...are you there?? http://www.setasign.de/products/pdf-php-solutions/fpdi/ – Hackerman May 31 '13 at 19:49
  • Robert Rozas: I am aware how to insert text or image into pdf. I am talking about stamping or watermarking (over the page), but not just adding an additional page to pdf. I need to insert a pdf or html. How do I do that with FPDi? – ihtus May 31 '13 at 19:51
  • http://www.setasign.de/products/pdf-php-solutions/fpdi/demos/simple-demo/ ....i think that can be accomplish using fpdi, read the manual and look at the demos. – Hackerman May 31 '13 at 19:58
  • I already did that, and I don't see how I can do that. – ihtus May 31 '13 at 20:01
  • $pdf->setSourceFile('PDFDocument.pdf'); that line set the source file(an already created pdf file)...and the other info is stamped over that file and outputed here $pdf->Output('newpdf.pdf', 'D'); – Hackerman May 31 '13 at 20:05
  • any more details on "...and the other info is stamped over that file"? – ihtus May 31 '13 at 20:09
  • Yes...all the info is stamped over the file....fpdi use a existing pdf as a template....and paste data over it – Hackerman May 31 '13 at 20:10
  • I would appreciate to get code for stamping.. I know how to setSourceFile and Output. – ihtus May 31 '13 at 20:12
  • "....and paste data over it" - the problem is that I cannot find a way how to paste data in form of another pdf or html. I only know how to paste it in form of text or image. – ihtus May 31 '13 at 20:19
  • Fpdi uses fpdf class, and fpdf can insert html code to a pdf....you can use a mix of both things – Hackerman May 31 '13 at 20:30
  • yes indeed, I tried WriteHTML (http://www.fpdf.org/en/script/script42.php), but I lost all styling and only pure text remained in pdf... – ihtus May 31 '13 at 20:33

1 Answers1

4

Answer is something like that:

$pdf=new FPDI();
$pdf->addPage();

// Form
$pdf->setSourceFile('form.pdf'); // Specify which file to import
$tplidx = $pdf->importPage(1); // Import first page
$pdf->useTemplate($tplidx,0,0); // Position at 0,0 and use original page size

// Stamp
$pdf->setSourceFile('stamp.pdf'); // Specify which file to import
$tplidx2 = $pdf->importPage(1); // Import first page
$pdf->useTemplate($tplidx2,10,10,($pdf->w / 2)); // Position at 10,10 and resize to 50% of current page width

$pdf->Output(); 
ihtus
  • 2,673
  • 13
  • 40
  • 58