External SVG to PDF rendering

Discussion forum for contributors and developers who are using the QCAD version 3 ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

External SVG to PDF rendering

Postby hungerburg » Mon Oct 03, 2011 12:32 pm

One may export SVG with preserve geometry ticked, and then render SVG to PDF etc. Best results with apache FOP and below stylesheet:

Code: Select all
fop -xsl fo.xsl -xml Skizze.svg -pdf Skizze.pdf

Code: Select all
fop -xsl fo.xsl -xml Skizze.svg -png Skizze.png -dpi 150


Width and height are taken from the SVG.

Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="xs" version="1.0">
   <xsl:output method="xml"/>
   <xsl:param name="width" select="/*/@width"/>
   <xsl:param name="height" select="/*/@height"/>
   <xsl:template match="/*">
      <fo:root font-family="Helvetica" font-size="12pt">
         <!-- Stammseite -->
         <fo:layout-master-set>
            <fo:simple-page-master master-name="skizze" page-width="{$width}" page-height="{$height}" margin="0mm">
               <fo:region-body margin="0mm"/>
            </fo:simple-page-master>
         </fo:layout-master-set>
         <!-- Skizze -->
         <fo:page-sequence master-reference="skizze">
            <fo:flow flow-name="xsl-region-body">
               <fo:block-container top="0cm" left="0cm" position="fixed">
                  <fo:block>
                     <fo:instream-foreign-object xmlns="http://www.w3.org/2000/svg">
                        <xsl:copy-of select="."/>
                     </fo:instream-foreign-object>
                  </fo:block>
               </fo:block-container>
            </fo:flow>
         </fo:page-sequence>
      </fo:root>
   </xsl:template>
</xsl:stylesheet>
User avatar
hungerburg
Senior Member
 
Posts: 117
Joined: Fri May 28, 2010 7:35 pm

Return to QCAD 3 Developers and Contributors

Who is online

Users browsing this forum: No registered users and 1 guest