TobesC Posted July 31, 2008 Share Posted July 31, 2008 Hi everyone - I have the pdf of a form that i need to fill out with different information every time. that data is in my database - is there a way to have php create a new pdf using the existing document as a template, and writing the data to a desired location on the page? i know its a bit complicated, but any help would be greatly appreciated. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/117647-modify-an-existing-pdf/ Share on other sites More sharing options...
zq29 Posted August 3, 2008 Share Posted August 3, 2008 I'm not sure if it can be done with this, but have you taken a look at the FPDF class? Quote Link to comment https://forums.phpfreaks.com/topic/117647-modify-an-existing-pdf/#findComment-606781 Share on other sites More sharing options...
willpower Posted August 15, 2008 Share Posted August 15, 2008 anyone got an answer to this? Quote Link to comment https://forums.phpfreaks.com/topic/117647-modify-an-existing-pdf/#findComment-617025 Share on other sites More sharing options...
NerdConcepts Posted August 17, 2008 Share Posted August 17, 2008 Yeah, seriously? Anyone? This is on going HUGE problem that I am having to finish up some stuff I've been working on a long time. Tried lots of things, I attempted to just open the file using what build in PDF stuff with a build in library on my server, HA, not even close. Tried a few other classes. tcpdf seemed like it may work, but it has so much junk tied with it I am not sure if that would be the way to go, since I am still not sure if you can simply open the existing form PDF, add text to it (using x,y) then save it. I know you can do the adding and saving and what not, but the whole opening an existing PDF is beyond me. I am checking to see if I can do a simple "background" image on a table and use PHP to fill in the variables and use tcpdf to use that PHP file to generate a PDF, but again, not sure if this is possible, since it seems to be overly complicated at this point. Haven't had a whole lot of time to check it out but I thought I would bring this to light to maybe the people having problems might also figure it out or find it useful. Quote Link to comment https://forums.phpfreaks.com/topic/117647-modify-an-existing-pdf/#findComment-618432 Share on other sites More sharing options...
Mchl Posted August 17, 2008 Share Posted August 17, 2008 FPDF won't work for this, but you can ask this question on their forum http://www.fpdf.org/ They've much experience dealing with PHP and PDF Quote Link to comment https://forums.phpfreaks.com/topic/117647-modify-an-existing-pdf/#findComment-618434 Share on other sites More sharing options...
JonnoTheDev Posted August 17, 2008 Share Posted August 17, 2008 I dont think that opening an existing PDF and writing data to it can be done although I have not looked at the FPDF library. I have used the PDF libraries in the ZEND framework (think its ZEND_pdf) to create a pdf document using user inputted data and using x,y coords to place the data which worked well, especially for creating hings like invoices on ecommerce apps. Quote Link to comment https://forums.phpfreaks.com/topic/117647-modify-an-existing-pdf/#findComment-618462 Share on other sites More sharing options...
Barand Posted August 17, 2008 Share Posted August 17, 2008 Using FPDF all you need to do is create a subclass of the fpdf class to create your form and have method/s to set the bits that change each time. Quote Link to comment https://forums.phpfreaks.com/topic/117647-modify-an-existing-pdf/#findComment-618485 Share on other sites More sharing options...
Mchl Posted August 17, 2008 Share Posted August 17, 2008 But FPDF can't use existing PDF as an template. It'd be necessary to create a code, that would produce same output as 'template' document. Quote Link to comment https://forums.phpfreaks.com/topic/117647-modify-an-existing-pdf/#findComment-618487 Share on other sites More sharing options...
Barand Posted August 17, 2008 Share Posted August 17, 2008 ... create a subclass of the fpdf class to create your form ... Yes, that's what I said Quote Link to comment https://forums.phpfreaks.com/topic/117647-modify-an-existing-pdf/#findComment-618518 Share on other sites More sharing options...
Mchl Posted August 17, 2008 Share Posted August 17, 2008 Wasn't obvious to me Quote Link to comment https://forums.phpfreaks.com/topic/117647-modify-an-existing-pdf/#findComment-618519 Share on other sites More sharing options...
NerdConcepts Posted August 19, 2008 Share Posted August 19, 2008 is there a way to convert an outside PHP file into a PDF? That may do the job for a few of us. I know it would me. It would allow me to recreate the PDF into HTML and PHP to fill in the needed values and then covert the code over to PDF. Quote Link to comment https://forums.phpfreaks.com/topic/117647-modify-an-existing-pdf/#findComment-619686 Share on other sites More sharing options...
Guest Xanza Posted August 19, 2008 Share Posted August 19, 2008 Sorry if this seems rude, but you guys keep asking the same question that Barand already answered - yes this can be done, but NOT from an existing PDF, you'll have to recreate a template from a subclass to create your form then a class to add the data that you want to customize it. If anyone has WaMu Online Banking you can view a simple class in action by clicking: "Set up Direct Deposit". Once you click it - it will take you to a page that will allow you to download a PDF file that already contains most of the information personalized from your account - then you print it out and hand it in to your employer. It's a really good example, you can try and Google the results if you would like... That's always a good place to start. Quote Link to comment https://forums.phpfreaks.com/topic/117647-modify-an-existing-pdf/#findComment-619750 Share on other sites More sharing options...
NerdConcepts Posted August 19, 2008 Share Posted August 19, 2008 The thing is, there was an "answer" but people do like to actually get a solution. Not just, write a class. But maybe an existing class? And, yes here it is and how to do it! Go and download this... http://sourceforge.net/project/shownotes.php?release_id=620047 1) Drop the contents of the download into a subdirectory of your website. Example of mine: http://localhost/testapp/tcpdf/ 2) Write a PHP file to contains your form. Make sure to read the documentation (some HTML is no acceptable)..for example... "form2pdf.php" 3) Create a PHP file that contains the following code. require_once('tcpdf/config/lang/eng.php'); require_once('tcpdf/tcpdf.php'); $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true); $pdf->SetCreator(PDF_CREATOR); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); $pdf->setLanguageArray($l); $pdf->AliasNbPages(); $pdf->SetFont("helvetica", "", 10); $pdf->AddPage(); $htmlcontent = file_get_contents("form2pdf.php", false); $pdf->writeHTML($htmlcontent, true, 0, true, 0); $pdf->Output("example.pdf", "I"); And run the this PHP file, it will auto generate the PDF and display it on the screen. That is just a simple test that I just now did for my solution. Still going through the TCPDF coding to change somethings on it to personalize it to work better for what I am doing. Also go through the examples, there are LOTS of different applications for this class file. Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/117647-modify-an-existing-pdf/#findComment-619833 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.