SVG to PDF on a shared linux server

前端 未结 5 1586
庸人自扰
庸人自扰 2020-12-28 09:10

I have a website which uses SVG for an interactive client side thingamabob. I would like to provide the option to download a PDF of the finished output. I can pass the final

相关标签:
5条回答
  • 2020-12-28 09:23

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

    0 讨论(0)
  • 2020-12-28 09:35

    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/

    0 讨论(0)
  • 2020-12-28 09:41

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

    0 讨论(0)
  • 2020-12-28 09:42

    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.

    0 讨论(0)
  • 2020-12-28 09:42

    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);
    
    0 讨论(0)
提交回复
热议问题