How to convert HTML to PDF using PHP? - php

I want to convert HTML with Google Charts reports to PDF,I used fpdf and other classes but I didnt get success.
please help me .

You can try using HTML 2 PDF available from sourceforge here

You could also try dompdf

Related

Create PDF Laravel 5.5?

I want to create a pdf page from html file in Laravel but I do not know how to do it. You can help me
https://github.com/barryvdh/laravel-dompdf
// Import in top of controller file
use Barryvdh\DomPDF\Facade as PDF;
// use below code to generate and download pdf file
$pdf = PDF::loadView('bladefilename', ['arrayname' => $array]);
return $pdf->download('filename.pdf');
Write Above code in the controller file
In Blade file (HTML file) set array data.
Show Below Link : https://github.com/barryvdh/laravel-dompdf/issues/126
I know I am a little bit late but hopefully this will help someone.
There are 2 ways:
Create HTML page and use jspdf to print this page. The best way is to use html2pdf: https://github.com/eKoopmans/html2pdf.js
You can use this one to convert html to canvas and print to pdf. All css will be kept but you have to change the page to fix the space between pages as there may be some bad cut at the end of each page.
Print the page using latex. You have to use laravel latex compiler: https://github.com/fvhockney/latexcompiler
It is a little bit harder to styling the page but there is no problem with paging.

Hyperlinks not working in PrinceXML

If I write below code in html file to convert it to PDF with prince factory it is not working properly.
http://google.com
This above link in pdf generated from prince xml is working properly, but it is pointing to google.com instead of example.com
Google
This link will not work as we have not written anything before google as http or https.
Can someone please help me on this?
Thanks.
You can try with css model
Html
<span class="linkContent">
CSS
.linkContent {
content: "http://google.com"
}
Refer doc: https://www.princexml.com/doc/8.1/gen-content/
Hope it can help you!
hi you have to check the "prince-pdf-link-type" property.
by default value is auto, try to change to "web" :
https://www.princexml.com/doc/properties/prince-pdf-link-type/
Apologies for this. But the problem was not with PrinceXML. later after so much investigation, I found that it was problem with merging 2 documents in FPDF.
I used Zend Merger for merging 2 documents which were created by PrinceXML and it worked perfect.
Apologies and Thank you all for your help.

how to convert dynamic contents of html page to pdf

In html page some tags are dynamically created using jquery and contents are loaded from msql db using jquery and php.
I want convert this dynamic page to pdf.
I have tried following code but it generate pdf of static part of html page.
<?php
ob_start();
?>
//html code and internal css, javascript used in external file with jquery library
<?php
include('dompdf/dompdf_config.inc.php');
$contents = ob_get_contents();
ob_end_clean();
$dompdf = new DOMPDF();
$dompdf->load_html($contents);
$dompdf->render();
$dompdf->stream('file.pdf');
?>
So how to store contents of dynamic html page in a php variable after processing it ( using javascript/php ) and convert it to pdf usin dompdf or other converter.
I'd suggest you take a look at wkhtmltopdf. I've had good results with getting it to render google charts, which are built dynamically from a javascript api.
http://code.google.com/p/wkhtmltopdf/
As Marc said, you have to read generated DOM with javascript.. something like $('html').html() and then post it to php to generate pdf
This may not meet exactly what you are looking for, but wkhtmltopdf could be what you need. Since PHP is a server-side technology, you will have a difficult time getting it to process any client-side javascript. wkhtmltopdf scans the page, javascript and all, then generates a pdf file on the server. Hope this helps you out!
Consider using a tool like wkhtmltopdf to directly generate a page as a PDF. It will run javascript and generate the page as WebKit would render it.

Converting google map to pdf in php

I am using TCPDF for generating PDF documents and i want to convert a google static image map into my pdf. How can i achieve this, some examples?
Why don't you try static google map to embed map in pdf. Static map generate image file which will easily added thorough document. I haven't tried but it should work...
For more detail see http://code.google.com/apis/maps/documentation/staticmaps/
Build the google static map link, docs can be found http://code.google.com/intl/nl-NL/apis/maps/documentation/staticmaps/
Use the writeHTML method of TCPDF to write the following:
<img src="http://yourgooglemapurl.com"/>

Convert text to PDF in PHP

What would be the simplest, shortest way to turn a text file into a PDF file with PHP? With some basic example code if possible.
I've seen this but the examples don't show how to use a text file as input.
http://uk3.php.net/manual/en/book.pdf.php
Thanks
TCPDF and FPDF can both render PDF output. If you're on a Linux system, you could also call the system's ghostscript to do it.
You'll definitely need a library to write PDFs. I'd say try FPDF.
TCPDF is the best way to convert text or HTML to PDF.
http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf
Throwing Zend_Pdf into the ring as well.
And a somewhat old tutorial to get you started in addition to the extensive docs in the ZF manual:
http://devzone.zend.com/article/2525
You can use MPDF.
I wrote a smalll instruction:
1) download Full version(http://www.mpdf1.com/mpdf/index.php?page=Download ) and extract inside anyfolder
2) create sample.php in anyfolder and insert like this:
<?php
include('./mpdf.php');
$mpdf=new mPDF();
$mpdf->WriteHTML('<div style="color:yellow;">SAMPLE TEXT, WITH HTML TAGS Too!</div>');
$mpdf->Output(); die('');
?>
3) then open sample.php in your browser to see the result!
MANY OTHER ONES - Convert HTML + CSS to PDF with PHP?

Categories