Khurram Ijaz
Khurram Ijaz

Reputation: 1864

Can I make html table into image to embed into pdf

I have been reading about this but I have to do some thing. I have a table with diagonal text in the heading columns and horizontal text in the rows. I was able to make text diagonal using CSS rotation thing, table data is coming from db and I want to generate the same html into the pdf. I don't know who to write diagonal text in the pdf. The solution is to create an image of the visible html table with data and then store it and then make pdf and embed that image there. I have been reading the GD library but how can I make table in GD library I am stuck , Stack Overflow is the last resort. Please help.

Upvotes: 4

Views: 1812

Answers (6)

tonoslfx
tonoslfx

Reputation: 3442

try this ezpdf class http://www.ros.co.nz/pdf/readme.pdf. they got some sample code to rotate text and how to embed image into 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();

Upvotes: 1

Patrick
Patrick

Reputation: 623

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

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

Upvotes: 0

George Reith
George Reith

Reputation: 13476

Do you need to do this only once or does this need to be an ondemand service? If not why not just load the html page take a screenshot and crop it down to the table?

Upvotes: 0

CSᵠ
CSᵠ

Reputation: 10169

For image generation in PHP you can use GD functions (fast) or iMagick (not so wide spread, docs are WorkInProgress, but you could do almost anything you can imagine with it).

GD should be enough.

A simple idea about making text diagonal would be to just rotate the image, once you output text from the db onto it.

Upvotes: 1

BrianS
BrianS

Reputation: 13914

If you want to go directly from your HTML code to PDF, and if you need something entirely in PHP you can try dompdf. The 0.6.0 release will include CSS transform support.

Upvotes: 1

Stephen
Stephen

Reputation: 18917

Use wkhtmltoimage or wkhtmltopdf.

Upvotes: 0

Related Questions