How do you create a PDF on the fly? And save it.
Posted: Wed Feb 27, 2013 9:57 am
Hi
I will soon need to be able to create PDF documents on the fly, via HTML code. Creating the layout with logos and information.
How is this done?
Is there some "bible" where people learnt to do this online?
Once created on the fly, can it be saved on the server, tho it's probably best if the PDF is created again on the fly, for the customer.
Thanks.
UPDATE:
Have tried this:
But it doesn't work. The image file is correctly entered.
Error is:
I will soon need to be able to create PDF documents on the fly, via HTML code. Creating the layout with logos and information.
How is this done?
Is there some "bible" where people learnt to do this online?
Once created on the fly, can it be saved on the server, tho it's probably best if the PDF is created again on the fly, for the customer.
Thanks.
UPDATE:
Have tried this:
Code: Select all
<?php
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_begin_page($mypdf, 595, 842);
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Sample PDF, constructed by PHP in real-time.", 50, 750);
PDF_show_xy($mypdf, "Made with the PDF libraries for PHP.", 50, 730);
PDF_show_xy($mypdf, "A JPEG image, on 60 % of its original size.", 50, 710);
$myimage = PDF_open_image_file($mypdf, "jpeg", "/images/logo.jpg");
PDF_place_image($mypdf, $myimage, 50, 650, 0.6);
PDF_end_page($mypdf);
PDF_close($mypdf);
$mybuf = PDF_get_buffer($mypdf);
$mylen = strlen($mybuf);
header("Content-type: application/pdf");
header("Content-Length: $mylen");
header("Content-Disposition: inline; filename=gen02.pdf");
print $mybuf;
PDF_delete($mypdf);
?>Error is:
Fatal error: Uncaught exception 'PDFlibException' with message 'pdf_open_image_file() expects exactly 5 parameters, 3 given' in C:\xampp\phpMyAdmin\site\createpdf.php:10 Stack trace: #0 C:\xampp\phpMyAdmin\site\createpdf.php(10): pdf_open_image_file(Resource id #2, 'jpeg', '/images/logo.jp...') #1 {main} thrown in C:\xampp\phpMyAdmin\site\createpdf.php on line 10