dompdf positioning errors - php

This may have been asked multiple times, but is there a good HTML-to-PDF creator for PHP?
I'm currently using dompdf, and there is a whole list of unsupported things (such as postion:absolute inside a position:relative container, and float:right) which make my PDF render incorrectly.
dompdf forces me to make tables in order to align stuff the way I want. I made an HTML page using floats and relative+absolute positioning, but dompdf ignores this and overlaps all my text and positions them wrong.
It also randomly put a blank 2nd page even though I have both page-break-before and page-break-after set to avoid.
So, can anyone tell me a good PHP PDF creator, or tell me a workaround for dompdf's lack of floats or relative+absolute positioning (I hate tables)?
P.S. I am using dompdf 0.6.0beta1

I just decided to re-write my HTML using tables, so dompdf will render it the way I want. mPDF looked nice, I may switch to that in the future.

Related

Using TCPDF to write text onto an image

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.

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.

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 it possible to dynamically merge one PDF with another using dompdf?

I am trying to take the raw data from a previously made PDF, and append it to a new PDF using DOMPDF. Is this possible?
Thanks for any help,Metropolis
Are you talking about overlaying one PDF on top of another or appending the pages of one document to another? DOMPDF doesn't currently support either type of functionality because it is focused on HTML to PDF conversion. Due to this focus by the project you're not likely to see any work put in to support the handling of existing PDFs anytime soon.
This doesn't help for your current project, but you might post a feature request to add support for a library that is capable of performing a merge (I think FPDI may work). DOMPDF relies on third-party PDF rendering engines for creation of the actual PDF. A modified version of the CPDF library is included with DOMPDF, but there's no reason other rendering engines couldn't be supported.
if it helps someone else,
what I did, I concatenated the HTML string in a loop and then made a pdf file after the loop.
And ofcourse using page-break-after: always; which creates a new page.

How do I replace outbound link URLs in a PDF document, using PHP

I have a PDF document with some external links.
I'd like to parse the document, replace the destination of the links then close (and serve) the PDF document, all using PHP
I know I can do this with PDFLib but I don't want to incur this cost.
I could re-write the document with FPDF or DomPDF, but some of these PDFs are quite complex so this would be a major time investment.
Surely there must be a way to do this directly to PDF docs, using native PHP?
TIA
I don't think there is a text/hyperlink changer class for PHP. The closest products, like pdftk, only does higher-level stuff like merging, splitting and applying watermarks.
Changing a pdf is much more difficult than generating it, so you need to use a pdf editor like Nitro PDF (untested), or why not Acrobat/Illustrator/InDesign.
If you must use PHP, regenerating the PDF:s with one of the free classes seems to be your best choice. I like FPDF very much, it gets my recommendation. If you decide to use it, check out FPDI as well, it can use existing PDF files as a template, maybe it will help you. Good luck!

Categories