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.
Related
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.
Which library is best to write PDF from HTML using Code Igniter?
Right now I'm using TCPDF, and it's taking much time to load a library.
Following are some useful PDF libraries & Tutorials for Codeignitor
PDF generation using dompdf
TCPDF-CodeIgniter Integration
Generating PDF files using CodeIgniter
mPDF with CodeIgniter
generating PDF files
Check out this article. The PDF library used there is quite fast and easy to use.
Since you're looking to convert HTML to a PDF, I highly recommend the wkhtmltopdf. It uses Qt and WebKit to generate PDF files of rendered markup, and even handles moderately complex JavaScript and AJAX. This makes it really useful for generating PDFs of pages that you have already created views and templates for, with the added benefit of being able to tweak and debug these pages with your browser. It works great for generating platform agnostic print views in your web app by normalizing the many nuances of various combinations of operating systems, web browsers, and printer drivers.
It's a stand-alone binary, so you may have trouble implementing it on shared hosting, but I used it recently on a project and could not have been more happy with it.
wkhtmltopdf: http://code.google.com/p/wkhtmltopdf/
My personal favorite PHP Library and API for it:
https://github.com/mikehaertl/phpwkhtmltopdf
Check out R&OS library R&OS pdf
i find it easy to implement
What is, according to you, the best way to convert uploaded files of any kind (.doc, .docx,...) into a pdf-file using nothing but php. Is it even possible to do so?
I looked at FPDF, but this creates the pdf files from text.
An other solution previously given was to use the PDFlib library on your server, but unfortunately, my server doesn't support this library...
What is the best way to convert to files my users upload on my site to pdf files?
A simpler approach would be to restrict uploads to .PDF format programmatically and require your users to only upload .pdf files. Provide a link on the upload page to a free and open source pdf printer (e.g. Cuteftp) that the user can install to create .pdf documents from any file that can be printed.
Trying to do it through PHP will be problematic because the uploads could be generated from many different programs that would be impossible to cater for in their entirety. e.g. How would it handle Scribus or ABC Flowcharter or any other 'non-standard' application someone used to create a document?
Much better to filter the upload upfront.
The best server-side PDF generator from those I tried was, so far, wkhtmltopdf, a WebKit-based, self-contained invisible browser that can render any HTML+CSS and generate a PDF from it. Reasonably fast and fairly reliable, has some useful PDF options, such as page size, orientation, etc.
The second part of the job in your case is to convert documents to HTML prior to feeding them to wkhtmltopdf. If possible, have your users upload the docs in HTML (Word and Co. can export (crappy) HTML). If this is not an option, you will have to find a tool just for that, which, in my opinion, is much easier than finding a tool that converts Word docs directly into PDF.
Good thing about wkhtmltopdf is also that you can feed the output of your PHP script to it using the ob_xxx() functions.
PHP Excel best simple way to create doc, docx, xls, xlsx, pdf files with PHP. Its lot easier with clear documentation.
Use Microsoft Office to render Microsoft Office documents, if you care about accuracy at all. This is easily done by invoking Office over COM.
Get access to your server, and install what you need. Doing so would be far easier than monkeying around with sub-par solutions.
Well... I can think of one way of doing it quite easily, but it doesn't involve using PHP.
Upload your documents to a folder on your server, that are browsable by your users.
EG: http://mysite.com/docs/
Then get your users to install a virtual printer driver such as Primo PDF
http://www.primopdf.com/index.aspx
then they can load the document into their browser, and print to PDF for offline browsing.
If this is not an option, and your dealing with office documents that conform to the openXML standard, you could attempt to parse the XML doc into a PHP page for display in the browser, then use JavaScript to trigger a print.
Unfortunately, it does still depend on your user having a PDF printer installed.
Alternatively, you could just load the docs natively, and print to your own PDF printer, then upload the PDF's to the web server for download.
I can't think of any easy way of doing this otherwise, without installing all sorts of different document parser tool-kits and doing a huge amount of behind the scenes work.
i am building a simple system using PHP that allow people to Add, Delete, and View data.
Can anyone tell me how to view the uploaded data in PDF format?
There are a bunch of options. The ones I like are:
wkhtml2pdf - A command-line tool that uses the WebKit HTML rendering engine to generate PDFs from HTML docs. Very easy to use, assuming you're able to get it installed on your server, and your requirements aren't too stringent. You just generate HTML/CSS, and use PHP's shell-exec functions to run it, and voila.
Zend_Pdf - Part of the Zend Framework, but like almost all ZF components, you can use it stand-alone. Programmatically build PDFs.
tcpdf, fpdf (with fpdi if you want to import existing PDFs and write over the top of them) - older, uglier, but effective.
There's also the commercial PDFLib, which used to be the best thing around, but I don't remember much about it. Included for approximate completeness.
Take a look at PDFLib, or its deprecated predecessor.
I was wondering if there was any way of turning an entire HTML page into a png (or other kind of image?) I'm trying to create PDFs on the fly, but it's pulling across my styles as text, but I want the styles to stay the same as the page (cufon and all). Any help would be appreciated! :)
This doesn't look straightforward. The backend (PHP etc.) doesn't do rendering, layout. It merely generates content.
The layout and visual aspects of the website are done by your client (browser) and the backend has no way of accessing this.
However, given an HTML file, there are libraries that can render it into a PDF like Prince XML that seem to be capable of this.
The only way to generate an image identical, or even near, what a visitor sees in their browser when viewing your site is to launch a browser and take a screenshot. You need the browser's rendering engine to render the page. All the libraries you find to do it without a browser create something much different than what the visitor sees, and won't render cufon or other fancy things at all.
Companies that offer screenshot previews of a webpage now run many servers, each running many virtual PCs, each running a full operating system and real web browser. They have all those systems pulling jobs, opening the webpages in real browsers, taking screenshots and saving images. You won't replicate that with a little PHP script.
http://ipinfo.info/html/rendering_services.php
Turning web pages into images and PDFs is a royal pain using PHP. Solutions often require OS level scripting, fake printer drivers, or screen capturing, which can make for a rather fragile setup. I ran into the same issue a few years ago and started working on native PHP extension that leveraged the Gecko engine to render HTML to PDF, but never finished it.
The best answer I've seen doesn't quite turn a full web page into a PDF, but instead does XML to PDF. XEP by RenderX is the commercial tool Apple uses to produce developer documentation in many formats, including HTML and beautifully rendered PDFs, from an XML source. The great thing about using the XEP tool in conjunction with PHP is that PHP deals with XML very well, so you can pass generated XML to the XEP binary, let it do the conversion to PDF, then deal with the resulting PDF file in PHP.
consider building a regular PDF file that resembles your web page:
PHP::PDF - constructing using php.
PDF Reference - file structure.