I want to create a PDF file from my PHP (HTML+CSS) but I positioning DIVs with CSS and I tried many PHP libs and no one could make me 100% same as HTML.
My positioned divs always under unpositioned items.
Can you tell me how can I position a picture and 2 text to a specified place of what kind of lib should I use?
Thanks!
The final solution was exporting HTML as a JPG file than use GD library to write PHP variables on it, than I used mPDF library to export as PDF.
Hope this way will help you to get the same as HTML.
Related
I want to create a PDF file out of a part of my DOM with a field (div width and height given) and place inside fields with text (position them relatively to this div).
Also I need to be able to rotate those text layers and apply skew on them.
Tried to use TCPDF and mPDF but unfortunately I couldn't achieve it.
Any ideas how to do it and which library would be the best?
With mPDF/TCPDF, you cannot use simple div and style to build page like as HTML. The way is to use table
If you want to use major of CSS 2 features, i thinks you can use the DOMPDF librairy
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.
I'd like to ask whether its possible to take a bit of CSS on a page with a PHP extension, and add the PHP header to define the page as a PNG, and have a dynamic image? From what I've heard this isn't possible, but if it isn't, is there a way easier than the conventional method of creating a PHP image?
Edit*
To elaborate, I want to do something like draw a bordered 200x200p box in CSS with styling and HTML, and have this HTML/CSS box on a .PHP page, and get this page to become a PNG image with the .PNG extension using the PHP header tag.
Thank You!
Karan
You can make use of wkhtmltopdf which can convert html to pdf using webkit (qtwebkit) which supports CSS properly. There even exists a PHP binding for it.
You can then convert the PDF file to a PNG (e.g. with ImageMagick) and serve it from within PHP.
Related: Website screenshots using PHP
If I understand your question properly, I am not sure how this would be possible using only PHP but you could use ImageMagick on server side to convert the HTML page to a png.
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.
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();
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.
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.
Use wkhtmltoimage or wkhtmltopdf.
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?
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
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.