Spinning a PDF by passing url and $ _GET parameters?

I've spent a lot of time trying to get the dompdf ( http://www.digitaljunkies.ca/dompdf/ ) but I keep running into problems all the time. I am trying to create a PDF from a PHP script that generates a rather complex completed web form. The script takes a $ _GET (record number) parameter and fills the form accordingly with the data from the database. I have no problem getting this data into a script as a string or any value type. What I'm wondering is what is the best approach to convert this data type to PDF?

The flow looks like this: the user fills out the form and is sent to the confirmation page, which I would like to add a Save as PDF button. One of two things can happen at this point: the page currently displayed in the browser can be linked directly to the pdf, or a call to itself (scriptname.php? Id = xyz) can be done using something like PHP http_get ( ) and store HTML as a string. From there I am having trouble preparing an accurate PDF representation.

I've heard some talk about fpdf, but their examples don't really lead me to believe that you can use dynamic data as a source, but please correct me if I'm wrong about that.

Any input would be appreciated.

- Nicholas

0


a source to share


2 answers


Well I didn't know dompdf. The weird thing is that it uses either a commercial library (PDFlib) or an outdated (?) One (CPDF not updated in 3 years). But ok so far it works (the concept is interesting).

I don’t understand what you mean by “using dynamic data as a source” (more precisely, I see no point in creating a static PDF!), But FPDF is used to generate various dynamic documents such as invoices in e-commerce products. I've seen people using forks (like TCPDF ) to process Unicode data.



You cannot convert an HTML page to PDF using FPDF, but you have pretty fine control over the layout using the concept of data cells.
You can see some code here: http://svn.prestashop.com/trunk/classes/PDF.php

0


a source


Having faced this problem in the past, I have used FPDF to host PDF data. Then, with the appropriate HTTP header set, force the browser to open the Load / Save As panel so that the user can save the specified PDF file.

In a class that extends FPDF / FPDI appropriately, you can use the following to generate a PDF from a PDF template you created: http://www.setasign.de/products/pdf-php-solutions/fpdi/ ):

$this->setSourceFile('pdf_template.pdf');
$template_page = $this->importPage(1, '/MediaBox');
$this->useTemplate($template_page, 0, 0);

      



Then, FPDF will generate a PDF for output using:

$this->Output();

      

You can also extend FPDF to accept (limited) HTML for formatting with a script found here: http://www.fpdf.org/en/script/script41.php

0


a source







All Articles