Advertisement
obernardovieira

Edit PDF files

Jan 21st, 2015
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. /*download fpdfi at - http://www.setasign.com/products/fpdi/downloads/
  2. and fpdf at - http://www.fpdf.org/
  3. original code example - http://stackoverflow.com/questions/7364/pdf-editing-in-php
  4. because this example doens't work for me, I made a new one*/
  5.  
  6. require_once('fpdf.php');
  7. require_once('fpdi.php');
  8. $pdf = new FPDI();
  9.  
  10. $pdf->AddPage();
  11.  
  12. $pdf->setSourceFile('file.pdf');
  13.  
  14. // import page 1
  15. $tplIdx = $pdf->importPage(1);
  16. //use the imported page and place it at point 0,0; calculate width and height
  17. //automaticallay and ajust the page size to the size of the imported page
  18. $pdf->useTemplate($tplIdx, 0, 0, 0, 0, true);
  19.  
  20. // now write some text above the imported page
  21. $pdf->SetFont('Arial', '', '13');
  22. $pdf->SetTextColor(0,0,0);
  23. //set position in pdf document
  24. $pdf->SetXY(30, 25);
  25. //first parameter defines the line height
  26. $pdf->Write(0, 'gift code');
  27. //force the browser to download the output
  28. $pdf->Output('file_generated.pdf', 'D');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement