Jump to content

Modify an existing PDF


TobesC

Recommended Posts

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.

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. :P

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.