ZF: Problem generating PDF (with mPDF) from text (html) created with WYSIWYNG (elrte plugin)

2

Galera,

I'm having trouble generating PDF in text that contains tag <table> . In this case I'm creating a module for generating contracts.

The text comes from the database and is created from a WYSIWYNG ( plugin elrte ). Formatting in the table is not rendered in the PDF, causing stacking of the words contained in the table.

For PDF generation I am using mPDF .

Has anyone ever gone through this? Any solution?

$mpdf = new mPDF();

$mpdf->WriteHTML($lsConteudo); //$lsConteudo vem do BD.

$mpdf->Output('contrato.pdf' , 'D');    
    
asked by anonymous 08.04.2014 / 21:50

2 answers

2

Turning HTML into PDF is not always as simple as it is necessary to render content and then convert it. Solutions that attempt to convert HTML to style-based PDF or simplistic assumptions tend to have many limitations, such as table, img, etc.

The best alternative is probably to use a webkit HTML renderer that converts to PDF or PNG, however you prefer. The link is one of the best we have used for years in a very aggressive environment of converting everything that is document type, including with images, CSS, tables, headers and footers, custom margins, everything:

1) Install wkhtmltopdf on the server. 2) Create a script (PHP, Perl, whatever you want) that receives HTML, invoke the wkhtmltopdf command and output the application / pdf back to the client. 3) On the web page, via javascript give a POST of HTML content to the script created on the server-side.

If you are already on the server side and use PHP, there already exists a project that does this port: link

I made a direct IPC with the executable wkhtmltopdf to have full control gave no more than 10 lines (in my case in PERL). In PHP it should be pretty simple too.

    
15.04.2014 / 06:46
0

The HTML2PDF library can display some very interesting results even with HTMLs involving tables. I think you could try using it and see if it meets your needs.

One of the problems of WYSIWYNG editors is that they often "mess up" HTML, making it harder to work with this type of converter.

Library link link

    
17.04.2014 / 17:41