I have a form that takes user input, posts to itself and stores my php code into a string variable and saves that string data to a .html file on my server. I'd like to do away with the .html file and instead save to .pdf with html2pdf but I'm running into an issue.
I have the following code in my php file:
require_once(dirname(__FILE__).'/html2pdf_v4.03/html2pdf.class.php');
$html2pdf = new HTML2PDF('P','Letter','en');
$html2pdf->WriteHTML($current);
$html2pdf->Output('/var/www/Inspection/Quote/exemple.pdf');
When I comment out the third line "$html2pdf->WriteHTML($current);" I get an error of "TCPDF ERROR: Some data has already been output, can't send PDF file".
When I comment out the third and fourth lines the rest of my page carries out without issue. . . I just don't get my .pdf.
I've seen some posts regarding flushing out something right before the write line but none of them were clear enough for me to work through.
Also, if I use a much simplified code I can generate the pdf properly. . . I'm lost as to why this is possible.
Here is what works:
$content = "
Exemple d'utilisation
Ceci est un exemple d'utilisation
de HTML2PDF.
";
require_once(dirname(__FILE__).'/html2pdf_v4.03/html2pdf.class.php');
$html2pdf = new HTML2PDF('P','A4','fr');
$html2pdf->WriteHTML($content);
$html2pdf->Output('exemple.pdf');
* EDIT *
$current =
General Order Information | ||
---|---|---|
Order Num: | 1 | |
Order Rev: | 3 | |
Quote Num: | 1 | |
Order Date: | 1970-01-01 | |
Customer Name: | 1 | |
Customer Buyer: | 1 | |
Sold By: | ED | |
Sales Rep: | DR | |
Prog Mgr: | VJ |
Terms: | 1 |
FOB: | 1 |
Shipping Co: | 1 |
Ship Acct Num: | 1 |
Shipping Method: | 1 |
Order Comments: | 1 |
Cust SO Upload: | The file 1-1-3.jpg has been uploaded, and Quote 1 has been added to the Quote directory |
Line | Cust PN / Rev | PN / Rev | Description | Qty | UOM | Sale Price | Line Total | Required Date | Program |
1 | 1 - 1 | 1 - 1 | 1 | 1 | 1 | 1.00 | 1.00 | 1970-01-01 | 1 |
The Order Total is 1.00 |
wkhtmltopdf is something I'd like to stay away from as it requires an x-server. . . something I'd like to avoid if possible.
Thanks in advance.