Pino Posted April 23, 2008 Share Posted April 23, 2008 Hi All, I have some template PDF's and I need to insert text values on the fly in PHP. Now I've been looking at http://www.ros.co.nz/pdf/ and its great for creating new PDF's. However I need the ability to edit a template and insert text (Of any font) at a set position. Did I miss something in the link above or is there another way? I cant warrant the $999 for PdfLib. Just to add this is PHP5 Kind Regards Link to comment https://forums.phpfreaks.com/topic/102585-solved-pdf-editing-without-pdflib/ Share on other sites More sharing options...
DarkWater Posted April 23, 2008 Share Posted April 23, 2008 Use the PEAR PDF modules. They should be able to do it, but you'll need to read the documentation. Link to comment https://forums.phpfreaks.com/topic/102585-solved-pdf-editing-without-pdflib/#findComment-525350 Share on other sites More sharing options...
Pino Posted April 23, 2008 Author Share Posted April 23, 2008 Thanks for the quick reply. Are there any other options? Just trying to cover all bases Thanks Again Link to comment https://forums.phpfreaks.com/topic/102585-solved-pdf-editing-without-pdflib/#findComment-525354 Share on other sites More sharing options...
DarkWater Posted April 23, 2008 Share Posted April 23, 2008 The PEAR PDF class is pretty solid and well-documented, and it's free, so I'd use it. I'm not sure if there's any other good, free options. >_> Link to comment https://forums.phpfreaks.com/topic/102585-solved-pdf-editing-without-pdflib/#findComment-525359 Share on other sites More sharing options...
BlueSkyIS Posted April 23, 2008 Share Posted April 23, 2008 i use fpdf.org for everything. Link to comment https://forums.phpfreaks.com/topic/102585-solved-pdf-editing-without-pdflib/#findComment-525374 Share on other sites More sharing options...
Pino Posted April 23, 2008 Author Share Posted April 23, 2008 BlueSKy does that allow editing? I've looked at that allready and there are no obvious signs that it does. Thanks Link to comment https://forums.phpfreaks.com/topic/102585-solved-pdf-editing-without-pdflib/#findComment-525377 Share on other sites More sharing options...
BlueSkyIS Posted April 23, 2008 Share Posted April 23, 2008 yes, there is an extension/class built from fpdf, called fpdi. i use this also: http://www.setasign.de/products/pdf-php-solutions/fpdi/ i use this to add text to W-2 PDFs, etc. Link to comment https://forums.phpfreaks.com/topic/102585-solved-pdf-editing-without-pdflib/#findComment-525382 Share on other sites More sharing options...
Pino Posted April 23, 2008 Author Share Posted April 23, 2008 Looks like it will do the trick, however when installing I get the following errors Warning: FPDF::include(helvetica.php) [function.FPDF-include]: failed to open stream: No such file or directory in C:\xampp\php\PEAR\fpdf.php on line 550 Warning: FPDF::include() [function.include]: Failed opening 'helvetica.php' for inclusion (include_path='.;C:\xampp\php\pear\') in C:\xampp\php\PEAR\fpdf.php on line 550 FPDF error: Could not include font metric file Link to comment https://forums.phpfreaks.com/topic/102585-solved-pdf-editing-without-pdflib/#findComment-525398 Share on other sites More sharing options...
BlueSkyIS Posted April 23, 2008 Share Posted April 23, 2008 i've never installed it with pear. i downloaded the fpdf and fdpi code, put them in a directory near my code and followed the examples. Link to comment https://forums.phpfreaks.com/topic/102585-solved-pdf-editing-without-pdflib/#findComment-525406 Share on other sites More sharing options...
Pino Posted April 23, 2008 Author Share Posted April 23, 2008 Thats what I did.... Does it come installed with PHP 5 or something? Link to comment https://forums.phpfreaks.com/topic/102585-solved-pdf-editing-without-pdflib/#findComment-525408 Share on other sites More sharing options...
Pino Posted April 23, 2008 Author Share Posted April 23, 2008 I've resolved it. On my local copy for some reason the fpdf class was in the pear directory and when the code referanced this it went there. If I make sure the fpdf class is in the same directory it works fine. Link to comment https://forums.phpfreaks.com/topic/102585-solved-pdf-editing-without-pdflib/#findComment-525415 Share on other sites More sharing options...
Pino Posted April 24, 2008 Author Share Posted April 24, 2008 Ok thanks for the help so far. I've got the classes working ok now. However I have one question. My overall aim is to take a template PDF 'copy it' add some text at x/y then save the new one. require_once('fpdi.php'); // initiate FPDI $pdf =& new FPDI(); // add a page $pdf->AddPage(); // set the sourcefile $pdf->setSourceFile('test.pdf'); // import page 1 $tplIdx = $pdf->importPage(1); $pdf->useTemplate($tplIdx, 0, 0, 60,90); // now write some text above the imported page $pdf->SetFont('Arial'); $pdf->SetTextColor(255,0,0); $pdf->SetXY(25, 25); $pdf->Write(0, "This is just a simple text"); $pdf->Output('newpdf.pdf', 'D'); This works well, however the origional PDF is 2.36x3.54 Inch the one that is produced from the template is massive. Any suggestions on how I can keep the size the same? I've tried to specify the size in MM (60x90) useTemplate($tplIdx, 0, 0, 60,90); Has no real effect. Thanks Again Link to comment https://forums.phpfreaks.com/topic/102585-solved-pdf-editing-without-pdflib/#findComment-525854 Share on other sites More sharing options...
Pino Posted April 24, 2008 Author Share Posted April 24, 2008 Solution for all those who are interested. $pageSize = array(60,90); // initiate FPDI $pdf =& new FPDI("p","mm",$pageSize); Link to comment https://forums.phpfreaks.com/topic/102585-solved-pdf-editing-without-pdflib/#findComment-525885 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.