html2pdf embed SVG files - php

I'm trying to use html2pdf to automatically create brochures that may need to go to print so need certain elements to be vector based. The class is hopelessly documented and I've got stuck trying to embed SVGs.
If I just try to embed the SVGs in the HTML to output like <embed src="img/test.svg" type="image/svg+xml" /> then I get an error saying the necessary methods to use this tag don't yet exist, likewise for <object> tags.
Digging further and the examples seem to show some sort of, I assume, proprietary <draw> tags that consist of all the required co-ords to draw the SVG. However I can't find any documentation anywhere to explain how to generate these?
Has anyone ever successfully embedded a SVG into a PDF using html2pdf?

Well I've partly figured this out, it seems the <draw> tag just contains the contents of an SVG file ("show SVG code" when saving as SVG from Illustrator) but it turns out html2pdf doesn't support bezier curves, which makes it pretty much useless for most things.

Related

SVG image get's messed up when I put it into html

I have been starting using SVG recently and I love it. There so clean, cool and easy to design.
Well I stumbled across a issue when I tried to one of my svg's into html (Works with every one of my svgs except this one). It works totally fine if I call it as a image (<img src="hill.svg"></img>) but when I try to use it
either with PHP(include 'hill.svg';) or just straight up passing it in on the index files, it messes up.
Here's an image. Messed up svg top left and the working on the full screen. Same file just that the working one is imbedded with "background-image"
It kinds of look like the background is turnt into one of those "missing- image-icons"
Any help would be highly appreciated.
Svg: https://pastebin.com/RsSAGv8M
There are some raster images linked in your SVG:
947B2F3D9DDD76B8.png (two times),
947B2F3D9DDD76B9.png,
947B2F3D9DDD76BF.png
They are probably not available on your webserver. If the SVG is linked as an <img>, they are never tried to retrieve, as for security reasons all images must be self-contained. But when the SVG is embeded in a HTML page, the request fails. and some browsers show a "missing image" icon.
Either delete the <image> tags in your SVG file (it seems you did not miss their content?), or embed them as data URLs. (I don't know Adobe illustrator good enough to know if there is a utility to do that.)

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.

Using Timthumb to Resize Images from CKEditor

I am using CKEditor to do basic text and image input into my website. I have noticed that it is quite sporadic in it's method of generating HTML for images when you add them. (Sometimes it might use height and width tags, other times it might use CSS).
I use Timthumb for on the fly image resizing on a number of other websites and find it very useful. I use a mod_rewrite rule in my .htaccess file to allow me to create domains like http://localhost/images/800x600/image.jpg and achieve resizing.
I would like to somehow incorporate this into CKEditor. I cannot find how to do this looking through the documentation so I have tried post-processing the data produced by CKEditor using Regex, however as mentioned before CKEditor seems to be too sporadic to be able to get this to work all the time.
Anyone else done this before? How did you achieve it?
I've done this in Grails. It's quite painful because of the random usage of html attributes and css. I ended up using an html parser, iterating over the images (dom nodes) and resizing those who has been resized. After that the html attributes and/or css styles has to be updated. It took quite some time to get it right as there are so many things that can go wrong.

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