Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Yet Another SVG to PDF Question

by Anonymous Monk
on Jan 29, 2012 at 21:12 UTC ( #950658=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I've been working for a long time on a web application that needs to generate PDF invoice reports from a database. The look of the reports is important, and they also include photos. Additionally, the reports are several pages long. The process that I've been using is to make an SVG into a template that can be substituted with HTML::Template, then have the users--who are all using Macs at this point--create the PDF by printing to PDF from the browser. This system works okay, but it isn't ideal for a few reasons:

1. SVGs don't support text wrap
2. I'd prefer to generate a PDF to deliver to the browser, rather than counting on the browser to handle the PDF generation
3. The command line tools I've found to generate PDFs from SVGs (rsvg, batik, etc) don't seem to use the font specified in the SVG, even if I include the SVG font in the image.

So, any ideas to clean up this workflow and generate multi page PDFs from SVGs?

Thanks in advance,


Replies are listed 'Best First'.
Re: Yet Another SVG to PDF Question
by Eliya (Vicar) on Jan 29, 2012 at 22:29 UTC

    In case there's no compelling reason to use SVG in the first place, you might want to use a LaTeX template instead, and then use the pdfTeX backend to render it to PDF.  As this is a professional typesetting package, it would also support automatic text wrapping, font embedding, etc.

Re: Yet Another SVG to PDF Question
by Corion (Pope) on Jan 30, 2012 at 08:09 UTC

    When I needed to create multi-page PDFs from SVG, I first created single-page PDFs from SVG by launching Inkscape via system() (see in App-imagestream, not yet on CPAN), and then combined the PDFs to a multi-page PDF using (I think) CAM::PDF (|].

    At least in Inkscape, PDF (1.1 I think) supports a wrapping textbox element. I had problems with that element rendering improperly under early Firefox versions (2.x), but as you want to deliver PDF anyway, this shouldn't be a problem.

    I suppose that if your tools are not rendering the fonts properly that there is something wonky with the font setup. Maybe these applications need to be told where the fonts are to be found, or the font names need to be mangled? I've only used Inkscape as my renderer (also see uniConvertor for a headless version).

Re: Yet Another SVG to PDF Question
by moritz (Cardinal) on Jan 30, 2012 at 11:00 UTC

    You can convert each SVG individually to PDF, and then use one of the various PDF manipulators (either from CPAN, or command line tools taht are packaged for all major Linux distributions).

    As for SVG -> PDF conversion, I found inkscape to be the most reliable. Unfortunately inkscape has a huge startup cost, even when used with GUI. But there is hope, svg2pdf uses inkscape's conversion engine in a separate executable, which works nicely for my needs.

Re: Yet Another SVG to PDF Question
by Anonymous Monk on Jan 29, 2012 at 22:08 UTC

    svg is xml, convert it to html?

    Yeah, I know, won't be easy

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://950658]
Approved by marto
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2017-05-28 04:19 GMT
Find Nodes?
    Voting Booth?