SVG to PDF on a shared linux server

て烟熏妆下的殇ゞ 提交于 2019-11-30 02:05:25

I stumbled across TCPDF today which would have been perfect for this, had I known about it at the time. It's just a collection of pure PHP classes, no external dependencies for most things.

It can build PDF's from scratch and you can include pretty much anything you want in there, including SVG (amongst many, many other things), as shown in these examples:

http://www.tcpdf.org/examples.php

Main project page is here:

http://www.tcpdf.org/

Sourceforge page is here:

http://sourceforge.net/projects/tcpdf/

You can use Apache FOP's free Batik SVG toolkit which has a transcoder api to transform SVG to PDF.

download link

You will need to write a tiny bit of java. There are code examples here – note you will need to set the transcoder to org.apache.fop.svg.PDFTranscoder instead of Java.

You should be able to do this without installing anything on your machine – just drag the jars on there and run a script. I quote:

All other libraries needed by Batik are included in the distribution. As a consequence the Batik archive is quite big, but after you have downloaded it, you will not need anything else.

have you looked at imagemagick? I suspect you also need ghostscript to complete the loop, which might make installation difficulty and performance a problem.

I'd suggest giving princexml a try, they provide various addons (including one for PHP) and can output PDF from SVG/HTML/XML.

i have used TCPDF (http://www.tcpdf.org/) in many projects and it work in almost every use case.

Here is the example of SVG: https://tcpdf.org/examples/example_058/

and following is the code which can help you:

$pdf->ImageSVG($file='images/testsvg.svg', $x=15, $y=30, $w='', $h='', $link='http://www.tcpdf.org', $align='', $palign='', $border=1, $fitonpage=false);

$pdf->ImageSVG($file='images/tux.svg', $x=30, $y=100, $w='', $h=100, $link='', $align='', $palign='', $border=0, $fitonpage=false);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!