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
Related
We have a enveloping machine that is able to read optical character recognition codes (OMR). See: http://en.wikipedia.org/wiki/Optical_character_recognition
For that we want enrich our PDF output with such an OMR code. We use FPDF in PHP to generate our documents.
Is there a way to greate these codes maybe as a picture?
Thanks a lot!
Perhaps you could insert images into your PDF that your OMR enveloping machine could read.
If so, I can recommend this FPDF Script which writes out standard HTML which can include images into the PDF being created:
http://fpdf.org/en/script/script42.php
$pdf->WriteHTML("<img src="http://www.example.com/OMR_readable_image.gif">");
If you need to dynamically create images with page numbers, I can see a solution where you combine a circle background image with the page number text to create an image that you then use as your image source.
How to create an image dynamically:
http://www.php.net/manual/en/image.examples-png.php
I am brand new to the TCPDF library and after reading through the documentation I am not sure if it is possible to do what I need. I have an image file, lets call it background.tiff, and I want to place this image inside a new pdf and write some text ontop of this image in certain positions. I can't find any information or documentation on writing text onto an image, or even positioning text absolutely on the page. Is this something that should be done with writeHTML() instead? Ideally this pdf will be printed later - is it possible to 'outline' the text for printing purposes in TCPDF? Any help would be much appreciated, I am feeling a bit lost here.
edit: I am completely open to switching to another library if it would be a better solution.
Altough solution is already given in comment here's what u need to know:
Image() - read about inserting an image into PDF document.
SetX(), SetY(), SetXY(), GetX(), GetY() - read about setting/getting pointers. Keep in mind that PDF generation is pretty similar to printing process. If you generate some content, move pointer back over that content, and generate something new, it will appear on top of content u've 'printed' before.
Cell(), MultiCell(), Write() etc.
Oh, and if u want to be precise with generating PDFs try to avoid converting HTML to PDF. Use pointers instead. It's much more precise, works better with page breaks and u don't need to worry about CSS compatibility.
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.
I'm developing an app where the user adds items to a list. That list is stored in an array and passed to PHP with JSON.
The objective is to then create a PDF with all the values extracted from the user. The PDF is quite complicated. It includes images depending on what the user selects and the text varies depending on the images and the input data.
The first idea was to generate the pdf in php with one of those pdf libraries, but that's going to be a real hassle.
Then I thought of creating an html & css (much easier) and the convert it to PDF. But since the html & css are quite complex I don't think those pdf converters will work with this.
Then I thought I could convert the html to jpg and then to pdf.
It'll be much simpler if I could just use html but the output needs to be pdf.
What do you suggest?
Here's a post that discusses creating PDF files with PHP and the PDFLib extension.
Generate PDFs with PHP it's on sitepoint.
Or if you want to go from HTML to the PDF it looks like TCPDF might work.
You can try using FPDF
Then I thought of creating an html & css (much easier) and the convert it to PDF. But since the html & css are quite complex I don't think those pdf converters will work with this.
wkhtmltopdf to the rescue! If you are on a VPS or dedicated machine, it's probably the best (open source) HTML-to-PDF engine out there. It leverages Webkit, the rendering engine used by Google Chrome and Apple Safari, amongst others.
Otherwise, your only other options are going to involve drawing every aspect of the PDF or image yourself, "by hand" in your code.
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.