Can I turn an html table into an image to be inserted in pdf

I read about it, but I have something to do. I have a table with diagonal text in the header columns and horizontal text in the rows. I was able to make a text diagonal using the CSS rotation function, the table data comes from db, and I want to create the same html in pdf. I do not know who to write the diagonal text in pdf. The solution is to create an image of a visible html table with data, and then save it, then make a PDF and embed this image in it. I read the GD library, but how can I make a table in the GD library that I am stuck in? Stack Overflow is the last resort. Please help.

+4
source share
7 answers

try this ezpdf class http://www.ros.co.nz/pdf/readme.pdf . they got some sample code to rotate the text and how to embed the image in pdf. Example

for ($angle=0;$angle<360;$angle=$angle+20){ $r=rand(0,100)/100; $g=rand(0,100)/100; $b=rand(0,100)/100; $pdf->setColor($r,$g,$b); $pdf->addText(300+cos(deg2rad($angle))*40,300- sin(deg2rad($angle))*40,20,$demotext,$angle); { $pdf->stream(); 
+1
source

If you want to go directly from your HTML to PDF, and if you need something completely in PHP, you can try dompdf . Version 0.6.0 will include support for CSS conversion.

+1
source

To generate images in PHP, you can use the GD (fast) or iMagick functions (not so widespread, documents are WorkInProgress, but you can do almost everything you can imagine).

GD should be enough.

The simplest idea to create a text diagonal would be to simply rotate the image as soon as you output the text from db to it.

+1
source

Use wkhtmltoimage or wkhtmltopdf.

0
source

This post Converts HTML + CSS to PDF with PHP? Discusses pretty much what you are trying to do, and lists a lot of options.

0
source

Do you need to do this only once, or is it necessary for the ondemand service? If not, why not just load the html page screenshot and crop it to a table?

0
source

Instead of trying to convert HTML directly to a PDF document, you can try creating a PDF library to create the document directly in PHP. This way, you get more control over what the PDF looks like, and it may be the best solution that tries to convert your HTML output.

https://stackoverflow.com/questions/560583/which-is-the-best-pdf-library-for-php

0
source

Source: https://habr.com/ru/post/1339291/


All Articles