Codeigniter View to PDF - php

I have used DOMpdf, mpdf, tcpdf and is not succeeded with the output.
I am putting here everything I have tried, including HTML.
OUTPUT PREVIEW :
Direct View File: http://jsfiddle.net/QdhdW/
DOMpdf and mPDF Output: https://www.box.com/s/f7cb2283d196db530702
ISSUES :
DOM pdf :
Bad looking CSS (and not exact as per required)
leaves 6-7 page
brakes in pdf the records are out of page then doesn't come to next page
mPDF :
makes output as small as possible, so that all records are covered in one page. (doesn't good as it is for A4 Page)
The Borders between each rows. (in HTML there is no borders between the rows.)
I don't mind using any pdf generator library and even if we change CSS
or make CSS inline, doesn't matter. The thing is I am seeking the PDF
output same as displayed in view File.
Please Help me, to figure it out. Struggling since yesterday.

Take a look at wkhtmltopdf it's a shell utility to convert html to pdf using the webkit rendering engine, and qt.
This will give you a much better result than the others as it's not trying to parse the html/css in php.

Finally I got it Solved.
Thanx to everyone for trying.
Solved it in DOM Pdf only, via changing the CSS.
Edited:
Make it worked through this
http://code.google.com/p/dompdf/issues/detail?id=507
If anyone else is having issue.

PhantomJS uses the webkit renderer and can output to PDF.
http://code.google.com/p/phantomjs/wiki/QuickStart

pdfcrowd is a web service for converting HTML to PDF.

Related

php - generate pdf with html table and save it on file server

I am working with a tool which lets user upload a .csv file.
That csv file contains an address column. I have to use the address from each row in another HTML template. That HTML template is like this
. After creating that template I then need to convert it into a PDF, store the PDF on a file server and give the user a link to the PDF.
I've finished the first two steps - csv upload and created complete template with address, but I'm stuck on how I can convert a template into a PDF.
I have looked into a few php-pdf libraries like fpdf mpdf. I'm facing a problem in creating pdf with html template.
A link to a library wich convert HTML to PDF and works pretty well.
First the link to the library
HTML2PDF
Then some code* to create your PDF using your own generated HTML, where $content is your HTML string.
$html2pdf = new HTML2PDF('P','A4','fr');
$html2pdf->WriteHTML($content);
$html2pdf->Output('exemple.pdf');
*Code taken from the "example page" of the site.
I have used tcpdf in many cases, https://tcpdf.org/
Works well with tables, I have made receipts and accounting related stuff with it. Handle UTF-8 without problems, why it's my way to go.
Only downside is that code is bit long and complicated and it doesn't keep tables as tables in pdf and turns them to divs, so paddings and other styles might be bit trickier to do.
One way is to use webkit based HTML to PDF converter.
Pros are that it is easy to customize and style and to see in the browser how it will look and then you can be sure that it will look as same in PDF as well. You could use CSS and JavaScript as well to style and modify.
Cons are that it is hard to install it on the production server sometimes. But there are web services and APIs that get you covered.
For example one service is https://pdfapi.io. It is free to use. Only when your amounts get bigger, then it will charge like a cup of coffee.
Hope that helps.

How to paginate the PDF while using mpdf to generate PDF file from HTML

I'm using MPDF to generate PDF from HTML. It works perfectly fine while I made the HTML string and pass it to the PDF generator. But I find out it's not enough. How could I change the current page to the next page. I mean in HTML string. For example, if you're making some PDF for the delivery forms on your website. You want to make every form start with a fresh new page. But the MPDF will auto paginate the HTML content which might cannot fit your need. How can I deal with this part? I'm getting confused. I try to read the source code,but the code is too much. And there's not enough comment inside. I hope there's some one who familiar with the MPDF lib. The version of MPDF which I'm using is v5.4 by the way.
Even i had the problem of breaking the page in mpdf. For that you should use addPage() of mpdf or <pagebreak />
$mpdf->AddPage();
or
<pagebreak />
using either of the above, you can force page breaks in mpdf,
check this for more reference
Unclear exactly what you need, but this might get you going.
If you have a multiple forms and you want those forms to be on their own pages, you have a couple possible solutions:
You could iterate over the forms and use $mpdf->AddPage(); at the end of each form
If you have an entire string and the forms are all together, you could use the html tag <pagebreak /> to signal a break where you'd like.
Reference the docs for further information, if needed. Hope it helps.

Convert html to pdf file with php

I need to convert the html receipt to pdf file. in html file I also have php information.
How can I provide such a thing?
could you suggest me with codes.
This is going to be a listing question, but we've used DOMPDF as #skippy suggested, and rejected it because it is a REAL troublemaker when tables surpass a page.
We've moved to http://code.google.com/p/wkhtmltopdf/ , which is -in my opinion- way better. It's being used in a production environment sending out lots of pdfs per day. It uses the webkit rendering enginge (you know, the one that chrome uses) and is therefore awesome :)
Have you taken a look at the DOMPDF project ? It simply rockz...
If that is not enough, you may want to browse StackOverflow itself :
Convert HTML + CSS to PDF with PHP?
Try using this to automagically convert html to pdf:
www.tcpdf.org
Try this
http://code.google.com/p/wkhtmltopdf/
it works like a charm. :)
My company has a product called DocRaptor that converts HTML to PDF using an HTTP POST request.
DocRaptor is built using Prince, and produces higher quality results than similar programs.
Here's a link to DocRaptor's homepage:
DocRaptor
I am using this code there is no need to installation of any thing .
http://sourceforge.net/projects/html2fpdf/

Generate PDF from HTML PHP

I want to generate PDF from a PHP file that includes HTML controls like textbox, and textarea. I attached CSS in the same. I tried FPDF, DOMPDF and TCPDF, but still I don't get exactly what I want. How do I pass HTML controls with PHP variables and CSS to these libraries?
mpdf is another option that you could try.
EDIT :
Found another solution for it, TCPDF is a FLOSS PHP class for generating PDF documents. Looks more dominating library.
"PRINCEXML" is a good library (not completely free now).
Others:
If your meaning is to create a PDF file from PHP, pdflib will help you (as some other suggested).
Else, if you want to convert an HTML page in PDF via PHP, you'll find
a little trouble outta here.. For three years I have been trying to do it as best as I
can.
So, the options I know are:
HTML2PS: same of DOMPDF, but this one convert first in .ps
(Ghostscript), then, in whatever format you need (PDF, JPEG, PNG). For
me it is a little better than dompdf, but I have the same speed problem.. Oh,
it has better compatibility with CSS.
Those two are PHP classes, but if you can install some software on the
server, and access it through passthru() or system(), have a look at
these too:
wkhtmltopdf: based on webkit (safari's wrapper), is really fast and
powerful... It seem like it is the best one (atm) for converting HTML pages to PDF on the fly, taking only two seconds for a three pages XHTML document
with CSS 2. It is a recent project. Anyway, the Google Code page is often
updated.
htmldoc: this one is a tank, it really never stops orcrashes... The project
seems to have died in 2007, but anyway if you don't need CSS compatibility
this can be nice for you.
** Thumbs Up For Strae.
If I understand your needs correctly I don't think any PHP-PDF class would do that.
Mostly you could insert only text and images to a PDF file, so if you would want something that looks like an HTML element you would need to insert it as an image.
Usually just putting HTML doesn't mean all your elements would stay intact in the PDF . (Different world, after all)
http://www.fpdf.org/ is the site having a great HTML-to-PDF class which work well. I am using it, but you have to first study its functionality and then start.

Creating PDF's using PHP

What I am wanting to do is create a PDF ideally from HTML code. I found a class called dompdf but I'm having issues with font and page breaks.
Does anyone know of another script or even a better way in general to generate PDF files?
The reason why I am converting HTML to PDF is because I want someone to use a WYSIWYG editor to create the contents and click save to generate their PDF file...
Any input would be greatly apprecaited
Due to the different nature of PDF and HTML you'll always have to make a few comprimises when trying to convert HTML into PDF.
If this doesn't bother you too much, I'd get started with TCPDF. Its easy to use and has a fairly good grasp of colors, sizes and some other style related HTML attributes.
i use this class TCPDF :
http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf
If you don't mind a bit of work then you can use Cairo to generate PDFs.
You can take a look at html2fpdf. It can accept very basic html and css.

Categories