HTML To PDF High Resolution [duplicate] - php

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Convert HTML + CSS to PDF with PHP?
I want to convert a web page to a high-resolution PDF suitable for printing. How can I do this?

If you want to do it in code, have a look at HTML2PDF or FPDF, they are php libraries designed to create PDF documents with code.
If you combine HTML2PDF with PHP's output buffering functions
ie
<?php
ob_start();
?>
// put all your html in here
<?php
$data = ob_get_contents();
require('html2pdf.php');
$pdf = new HTML2FPDF();
$pdf->AddPage();
$pdf->WriteHTML($data);
$pdf->Output();
?>
Obviously that is a very rough example but I have used that before within php to generate pdfs. It does have some issues with stylesheets, it seems to ignore most of them. But more control can be gained by using FPDF by itself and manually building the documents.

Try: "wkhtmltopdf" it just work great (and its -open source-). It uses webkit engine (used by safari, chrome browsers) and it is very easy to use :
wkhtmltopdf stackoverflow.com/questions/1878512/ output.pdf
Try it! for Linux and Windows as well. Easy to install. If you use ubuntu, type:
aptitude install wkhtmltopdf

if you want to convert web page using browser, you can use sofware in windows like cutepdf, dopdf etc.
but if you want to convert a web page into pdf by php code (on the fly), there are several ways to convert:
Using library provided, you can try html2pdf (php).
In java / .net a library like pd4ml can be used (even it is not free).
You can use open office converter. It can open multiple doc type, and convert into pdf. Open office provide API (I have tried in java, not php). The flow is same like you open the document, then convert into pdf, but you just do it in your coding. Must have open office server daemon to listen the converter via your code. See here http://oodaemon.sourceforge.net/
If you want quick solution in PHP, maybe you can use html2pdf.
The advantage you use open office converter is the output will be same as you see in browser (I already test it use oodaemon). If using library I am not sure 100% it will be same if you open in browser, because the layout is depend on CSS. pd4ml generate layout in pdf base on html and css (has it owns CSS parser I think)

Related

PDF PHP library that converts html tag containing images to PDF

I just want to ask if there are any free/opensource or are there even any existing PHP class library that can convert HTML to PHP using the tags as its image source?
Because I have created a web app that contains Google Maps in it and now I want to save the generated map, instead of saving it using printscrn I would like to convert it to PDF. Is it even possible?
Can you give me guys a link to the library if ever there are existing ones?
I have already looked for fpdf and tcpdf but on their examples all images is contained on the file directory.
Thanks
There is the library HTML2PDF (on github) licensed under LGPL. It is based on TCPDF and very easy to use.
I have tried and successfully converted html to pdf using wkhtmltopdf[1] binary sometime back (including images).
Download wkhtmltopdf binary which is compatible to your base server o/s and use a php wrapper class similar to this[2] (i haven't tested this wrapper class[2] but it should serve your purpose)
There are plenty of php wrappers available for wkhtmltopdf binary, so you can find one easily if this[2] didn't work well for your purpose.
[1] http://wkhtmltopdf.org/
[2] http://mikehaertl.github.io/phpwkhtmltopdf/

Convert html or pdf document in postscript over web (PHP, JS)

I need print a document directly over PHP. It works by php_printer. Now I need convert HTML ou PDF document to PostScript.
It's possible over web? By Js ou PHP?
Thanks!
With PHP you can use wkhtmltopdf, you will have to install it on server though. It's a command line tool, but there are some PHP libraries, like phpwkhtmltopdf to simplify the usage.

Converting HTML with Mathematical Symbols to PDF with Javascript support PHP

I have a web page which has mathematical symbols in it which is rendered using JavaScript. I have used ASCII Math plugin and ASCIISVG plugin to create and display mathematical expressions in web page. Now I have a requirement to convert this web page to PDF. I have tried dompdf and fpdf, but both failed since these convertors do not support Javascript.
Is there any way to achieve this?
If you rely on JavaScript you have two options:
Render on the client and capture the generated document content. You can then send that content to the server for rendering to PDF. dompdf does not currently support SVG, so with this method you would have to use another output format or another library (I'm not sure which ones support SVG). The main drawback is that this does require user interaction.
Use a headless browser. These are full browser engines compiled into a command line client. These usually support the full web stack (HTML, CSS, JavaScript, SVG). The web content is rendered in memory after which you can export to PDF and image formats. The best I've seen so far is PhantomJS. The only drawback is that you have to be able to install binaries on your system and execute them.

reports in PDF with tables in PHP

I have to generate few reports in PDF format with some inventory stats (no graphs, only tables). Additionally, I have to generate some pdf labels for the placed orders and units in a nice tabular format (taking care of landscape orientation and line wrapping) for the web platform. Which PHP API/Library would be best suitable for this purpose. I am using Zend framework but Zend's PDF API is not rich enough to serve the cause.
One option I am considering is to use LateX for generating PDFs.
Advices? Suggestions?
There are several PDF generation libraries and executables.
I've used:
TCPDF
DOMPDF
html2pdf as #redreggae suggested
wkhtmltopdf
Many other alive & dead solutions
They all rendered HTML to PDF. The problem of all (except wkhtmltopdf) was that they all used different (non-standard) rendering engines and results were often different between them and unsatisfying. wkhtmltopdf uses WebKit to interpret the HTML and create a pdf file. I personally prefer wkhtmltopdf after trying/using (in production) all other of the ones listed.. There is one drawback to it - it is an executable and as such it must be called with exec() however this should not be a big issue when proper coding is applied such that you prevent code injection.
If you want something higher level than HTML to PDF converters, you can try PHPJasperXML, it's a renderer for JasperReports on pure PHP.

PHP CodeIigniter - PDF generator

Need help in PDF generation because I am doing a project with PHP CodeIgniter.
I need to convert some HTML documents (of min 10 pages) into PDF.
I heard that wkhtmltopdf is good compared to others.
But how to incorporate it into the web pages, since I see it as command line converter.
Any example would be more helpful or any suggestion for a good PDF generator?
Here is a PHP class built on top of wkhtmltopdf: http://code.google.com/p/wkhtmltopdf/wiki/IntegrationWithPhp

Categories