Using TCPDF to write text onto an image - 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.

Related

Generate PDF from HTML PHP

I want to generate PDF from a PHP file that includes HTML controls like textbox, and textarea. I attached CSS in the same. I tried FPDF, DOMPDF and TCPDF, but still I don't get exactly what I want. How do I pass HTML controls with PHP variables and CSS to these libraries?
mpdf is another option that you could try.
EDIT :
Found another solution for it, TCPDF is a FLOSS PHP class for generating PDF documents. Looks more dominating library.
"PRINCEXML" is a good library (not completely free now).
Others:
If your meaning is to create a PDF file from PHP, pdflib will help you (as some other suggested).
Else, if you want to convert an HTML page in PDF via PHP, you'll find
a little trouble outta here.. For three years I have been trying to do it as best as I
can.
So, the options I know are:
HTML2PS: same of DOMPDF, but this one convert first in .ps
(Ghostscript), then, in whatever format you need (PDF, JPEG, PNG). For
me it is a little better than dompdf, but I have the same speed problem.. Oh,
it has better compatibility with CSS.
Those two are PHP classes, but if you can install some software on the
server, and access it through passthru() or system(), have a look at
these too:
wkhtmltopdf: based on webkit (safari's wrapper), is really fast and
powerful... It seem like it is the best one (atm) for converting HTML pages to PDF on the fly, taking only two seconds for a three pages XHTML document
with CSS 2. It is a recent project. Anyway, the Google Code page is often
updated.
htmldoc: this one is a tank, it really never stops orcrashes... The project
seems to have died in 2007, but anyway if you don't need CSS compatibility
this can be nice for you.
** Thumbs Up For Strae.
If I understand your needs correctly I don't think any PHP-PDF class would do that.
Mostly you could insert only text and images to a PDF file, so if you would want something that looks like an HTML element you would need to insert it as an image.
Usually just putting HTML doesn't mean all your elements would stay intact in the PDF . (Different world, after all)
http://www.fpdf.org/ is the site having a great HTML-to-PDF class which work well. I am using it, but you have to first study its functionality and then start.

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.
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

There in PDF not change the style which i have added in HTML?

In my site, I am using the TCPDF to generate the pdf from HTML ,and i also using the image in header but i can't show the style which i added in html.
Ljubljana,'.date("d.m.Y").'
'.JText::_('BUYER_NAME').':
'.$my->name.'
'.JText::_('BOOKING_CODE').':
'.$ticketNo.'
This table in PDF not margin from top with its given 35px.
plz help.......
If you refer to the original documentation and examples of TCPDF when checking for this question, you'll probably find yourself without any valid solution.
This is because TCPDF hasn't a full CSS complementation, but just for basic formatting. With getHtmlDomArray() you'll probably be able to access this CSS partial use, such as font-family and others. So, if you want to use full CSS with TCPDF, you are using a wrong tool and I'd advise to try other one that would make the same output, as many as they are.
Anyway, be sure to check new versions of that implementation, in case you really want to keep using it, as they might add more implementations on the future.

Is there a way to output html div to an image using php?

I have a div on my page which I want to output to a jpeg file. Is this possible using PHP?
I know there's the GD library for creating images in PHP but I'm not sure if it can do what I want. Because I also want to put a barcode on the image (I used a jQuery plugin to do this on the html page) .
Is this possible (if it's possible can you give me an idea how to implement it) or is there a better approach to this? Thanks!
As far as I know the functionality you want is not supported by GD. You might want to search for a library that does that. The problem is that the browser renders the HTML and CSS, but GD would need to know how to parse and render HTML and CSS (and Javascript) in order to turn HTML into an image. It might be a better idea, depending on what you really want to do, to create an image in GD and stick it in the HTML DIV, and then you won't have to do any conversion.
If there is a way to export a section of HTML to an image in a browser, then you could use PHP to control a server-side browser and export it that way. It would be a lot more work, but it's definitely possible.
It can't be done the way you want it. Instead you can draw the image based on the data you have.
You say it's bar code... so I guess this would be a good start.

Programmatic Way To Link Text Within A PDF

I am looking for some way to code a function (I'm open to any language or library at this point) to take an already existing PDF file as input and return a modified PDF file that links certain words to different URLs. I know PHP and ColdFusion both have good tools for dealing with PDF's, but I haven't been able to find anything that works.
I've been doing this by going through Acrobat and linking the text by hand and was wondering if there was any way to automate the procedure.
Thanks!
With ColdFusion you can extract the text with DDX (see Extracting text from a PDF document on the page), modify it using search/replace and generate new document.
If I understand what you're trying to do, you should be able to use CFPDF (http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_p-q_02.html#2922772) to read the pdf file into a ColdFusion variable, replace whatever content you want in that variable, then save the content back to pdf.

Categories