FPDF Encoding Issues - php

I've been using FPDF utility in order to export html output to pdf reoprt.
I'm successfully sending text and displaying it in the pdf file, but the problem comes up while trying to display real html structures- like tables and etc.In this case it seems like the encoding is not working well.
I've been trying to come up with a solution, but haven't had a success so far.
Any suggestions?
Thanks in advance

If you want to convert HTML to PDF in PHP you should have a look at MPDF. With FPDF you have to parse the HTML yourself, extracting paragraphs, formatting, images and tables and then need to call the FDPF functions for creating the elements in the PDF - you're basically rewriting MPDF functionality.

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.

large html table to pdf using fpdf

I am converting a html table to pdf using php and fpdf,the problem is that for a table with large number of columns the data is going outside the pdf page.
Try TCPDF, it allow you to control every mm of page. It's well documented.
See the example n.11 for table or use it to write html inside pdf.

Codeigniter View to PDF

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.

Exporting flash content to PDF?

I am using fpdf.php to export the PDF document from PHP. I'm still facing the problem that I couldn't export flash content in to the PDF
What do you mean by flash content? You should separate data generating code from data displaying code, so you can write two components for displaying data: one for flash and one for pdf.
If you mean to take a .swf file and convert it into a PDF then you will need to find a different solution since the fpdpf.php library, since it doesn't support converting .swf files into PDFs.

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