在共享的Linux服务器上将SVG转换为PDF [英] SVG to PDF on a shared linux server

查看:95
本文介绍了在共享的Linux服务器上将SVG转换为PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,该网站使用SVG进行交互式客户端thingamabob.我想提供下载完成输出的PDF的选项.我可以将最终的SVG输出传递回服务器,在这里我要转换为PDF,然后将其返回给客户端进行下载.

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 SVG output back to the server, where I want to convert to PDF, then return it to the client for download.

这将需要在无头共享linux服务器上工作,在该服务器上安装或编译是一个巨大的痛苦,甚至是不可能的.该网站是PHP,因此理想的解决方案是PHP,或使用易于安装在共享Web服务器上的软件.可以使用Python,perl和ruby,以及在Linux机器上可能期望的常规功能.涉及cairo,脚本inkscape或比"FTP it up"更复杂的安装的解决方案可能已经淘汰.自然,花大量的钱也花光了.由于这是一台共享服务器,因此内存和/或CPU饥饿的解决方案也已淘汰,因为它们往往会被杀死.这或多或少排除了蜡染.

This would need to work on a headless shared linux server, where installation or compilation is either an enormous pain, or impossible. The website is PHP, so the ideal solution would be PHP, or use software that's easily installed on a shared webserver. Python, perl and ruby are available, along with the usual things you might expect on a linux box. Solutions that involve cairo, scripting inkscape, or installation more complex than 'FTP it up' are probably out. Spending large amounts of money are also out, naturally. As this is a shared server, memory and/or CPU hungry solutions are also out, as they will tend to get killed; this more or less rules out Batik.

到目前为止,我最近的是

The nearest that I've got so far is this XSL transform which I can drive from PHP and then squirt the resulting postscript through ps2pdf (which is already installed). The only problem with this is that it doesn't support SVG paths - if it did, it would be perfect.

关于StackOverflow,有一堆或相关的问题,我已经阅读了全部,但都假设您可以安装东西,花钱或两者兼而有之.

There are a bunch or related questions on StackOverflow, all of which I've read through, but they all assume that you can either install stuff, spend money, or both.

有人对此有现成的解决方案吗?还是我应该花一些停机时间尝试为该XSL转换添加路径支持?

Does anyone have an off-the-shelf solution to this, or should I just spend some downtime trying to add paths support to that XSL transform?

谢谢, 邓克

推荐答案

我今天偶然发现TCPDF,如果当时我知道的话,这本来是完美的.它只是纯PHP类的集合,在大多数情况下没有外部依赖项.

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.

它可以从头开始构建PDF,并且您可以在其中包含几乎所有想要的内容,包括SVG(以及许多其他内容),如以下示例所示:

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

主项目页面在这里:

http://www.tcpdf.org/

Sourceforge页面在这里:

Sourceforge page is here:

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

这篇关于在共享的Linux服务器上将SVG转换为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆