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

Asked

Viewed 1,527 times

2

Galley,

I’m having trouble generating text PDF that contains tag <table>. In this case I am creating a module for contract generation.

The text comes from the database and is created from a WYSIWYNG (elrte plugin). Table formatting is not rendered in PDF, causing word stacking in the table.

For PDF generation I am using mPDF.

Has anyone been through this? Any solution?

$mpdf = new mPDF();

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

$mpdf->Output('contrato.pdf' , 'D');    
  • I have a similar problem currently, but it decreases the problems considerably in the generation of PDFS by removing the standard CSS that it defines in config.php

  • You have removed in the Leandro file itself, or is there any method to disable the upload?

  • I manually removed in the config.php file of mPDF, has an array there with some default styles that it even applies at the time you have the PDF generated, which implies the problems you had. but not everything it generates correctly.

  • I get it. I’ll try to remove and see if I have a better result.

  • yes, look at the example at the end of code http://pastebin.com/DsaXUPyf

  • It did not work in this case Leandro, even removing the default formatting.

  • take a look at the documentation http://mpdf1.com/manual/index.php?tid=34, I don’t know if it will help you, in this case the staff decided to do with another pdf generator, called Snappy https://github.com/KnpLabs/snappy

  • It is his documentation is very vague... does not give me examples of using tables.

  • with tables he proved horrible.

  • Guys, I still can’t find a solution to this question I need more suggestions... someone?

  • got it? if we don’t look for a solution together! =)

  • I use mPDF with Smarty and call css via link rel (<link rel="stylesheet" href="css/pdf.css">) in my template, and it works perfectly. already tried to put the reference to css directly?

Show 7 more comments

2 answers

2

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

The best alternative is probably to use a Webkit HTML renderer that converts to PDF or PNG, as you prefer. The http://wkhtmltopdf.org/ 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, as you wish) 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 is already a project that does this port: https://github.com/mikehaertl/phpwkhtmltopdf

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

0

The HTML2PDF library can present some very interesting results even with Htmls involving tables. I guess you could try using it and see if it fits your needs.

One of the problems of WYSIWYNG editors is that they usually "dirty" the HTML, making it difficult to work this type of converter.

Library link http://html2pdf.fr/en/default

Browser other questions tagged

You are not signed in. Login or sign up in order to post.