简体   繁体   English

从一个svg文件创建多页pdf

[英]Create multi-page pdf from one svg file

Is there a way to create a multi-page pdf from just one svg file? 有没有一种方法可以仅从一个svg文件创建多页pdf? I am currently loading an svg file that I have broken up into two panels. 我目前正在加载一个已分解成两个面板的svg文件。 I then hide one panel so the user can only see one. 然后,我隐藏一个面板,以便用户只能看到一个面板。 Then by means of tabs listed as Panel 1 and Panel 2 which the user can click to see one panel at a time with css display. 然后,通过面板1和面板2中列出的选项卡,用户可以单击并使用css显示屏一次查看一个面板。 The user is able to add text to the panels. 用户能够向面板添加文本。 The user then can print to a pdf. 然后,用户可以打印为pdf。 The svg is sent via form data to a script that calls some java classes such as Batik to create the pdf. svg通过表单数据发送到脚本,该脚本调用一些Java类(例如Batik)来创建pdf。 All the above works fine except creating a multi-page pdf. 除了创建多页pdf以外,上述所有方法都可以正常工作。 I am not sure how to accomplish this. 我不确定如何做到这一点。 I am very new to this. 我对此很陌生。

SVG File: SVG文件:

<svg id="svgroot" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" version="1.1" height="100%" width="100%" viewBox="0 0 1638 1029.6" baseProfile="full" xmlns:space="preserve">    
<svg id="panel_1" width="1600" height="1024" overflow="visible">
    <g id="menupanel_1" style="display:inline">                 

        <image enable-background="new" width="1600" height="1024" xlink:href="images/Panel1.jpg" transform="matrix(1.0239 0 0 1.0021 -4.882813e-004 0)"></image>

        <a xlink:href="#" id="sec_" class="a-map" alt="Salads &amp; Soups"><rect x="8" y="259" fill-opacity="0" width="305.001" height="348"/></a>
        <a xlink:href="#" id="sec_" class="a-map" alt="Desserts"><rect x="333" y="486" fill-opacity="0" width="297" height="169"/></a>
        <a xlink:href="#" id="sec_" class="a-map" alt="Sandwiches"><rect x="6" y="673" fill-opacity="0" width="306.001" height="247"/></a>              
        <a xlink:href="#" id="imgsec_1" class="a-map" alt="Menu Panel Images">
            <rect  x="333.667" y="202.333" fill-opacity="0" width="294.911" height="273.911"/>
            <image id="image_1" enable-background="new" style="display:none" width="285" height="262" xlink:href="images/image1.png" transform="matrix(1.0057 0 0 1.0082 337.4297 207.7466)"></image>                               
            <image id="image_2" enable-background="new" style="display:none" width="285" height="262" xlink:href="images/image2.png" transform="matrix(1.0057 0 0 1.0082 337.4297 207.7466)"></image>
        </a>
        <g>
            <g><rect x="271.244" y="299.911" fill="#FFFFFF" width="34" height="12"/></g>
            <text id="price1" transform="matrix(0.9964 0 0 1 274 309.5898)" fill="#231F20" font-family="TradeGothicLTStd-Light" font-size="11">00.00</text>
        </g>
        <g>
            <g><rect x="271.244" y="343.244" fill="#FFFFFF" width="34" height="12"/></g>
            <text id="price2" transform="matrix(0.9964 0 0 1 274 352.9233)" fill="#231F20" font-family="TradeGothicLTStd-Light" font-size="11">00.00</text>
        </g>
        <g>
            <g><rect x="270.91" y="410.577" fill="#FFFFFF" width="34" height="12"/></g>
            <text id="price3" transform="matrix(0.9964 0 0 1 274 420.2563)" fill="#231F20" font-family="TradeGothicLTStd-Light" font-size="11">00.00</text>
        </g>
    </g>
</svg>

<svg id="panel_2" width="1638" height="1029.6" overflow="visible">
    <g id="menupanel_2" style="display:none">

        <image enable-background="new" width="1638" height="988" xlink:href="images/Panel2.jpg" transform="matrix(1 0 0 1.0421 0 0.002)"></image>

        <a xlink:href="#" id="sec_" class="a-map" alt="White Wine"><rect x="27" y="404" fill-opacity="0" width="302" height="246"/></a>
        <a xlink:href="#" id="sec_" class="a-map" alt="Red Wine"><rect x="28" y="658" fill-opacity="0" width="300" height="342"/></a>
        <a xlink:href="#" id="sec_" class="a-map" alt="Appetizers"><rect x="661" y="419" fill-opacity="0" width="312" height="563"/></a>
        <a xlink:href="#" id="sec_" class="a-map" alt="Burgers"><rect x="986" y="718" fill-opacity="0" width="628" height="253"/></a>
        <a xlink:href="#" id="sec_" class="a-map" alt="Mains"><rect x="985.5" y="17.3" fill-opacity="0" width="627" height="693"/></a>
        <a xlink:href="#" id="sec_" class="a-map" alt="Beers"><rect x="27.5" y="19.3" fill-opacity="0" width="303" height="343"/></a>
    </g>            
</svg>

Script: 脚本:

<cfscript>
svgformdata = form.data;
fname = form.filename;

transcoder = createObject("java", "org.apache.fop.svg.PDFTranscoder").init();

// load text into a reader and create the source input
svgText = '#svgformdata#';

reader = createObject("java", "java.io.StringReader").init(svgText);
input = createObject("java", "org.apache.batik.transcoder.TranscoderInput").init(reader);

// create a unique file name
outPath = ExpandPath("./pdf/" & fname);

fos = createObject("java", "java.io.FileOutputStream").init(outPath); 
output = createObject("java", "org.apache.batik.transcoder.TranscoderOutput").init(fos);

transcoder.transcode(input, output);

fos.close();
</cfscript>

I recall a proposal for multipage SVG getting dropped from version SVG 1.2 and I don't think SVG 2.0 will have it either. 我记得有一个关于将多页SVG从SVG 1.2版本中删除的建议,我也不认为SVG 2.0也可以。

However, you can use XPath or some other method to use the SVG you have to create two SVG files where each contains just one panel. 但是,您可以使用XPath或其他方法来使用SVG,您必须创建两个SVG文件,每个文件仅包含一个面板。 Then create your multipage PDF. 然后创建您的多页PDF。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM