2016-10-13 42 views
0

是否有一種方法可以從一個svg文件創建一個多頁PDF?我目前正在加載一個svg文件,我已經分解成兩個面板。然後,我隱藏一個面板,以便用戶只能看到一個面板。然後通過列爲面板1和麪板2的選項卡,用戶可以點擊一次以CSS方式顯示一個面板。用戶可以向面板添加文本。用戶然後可以打印到PDF。 svg通過表單數據發送到一個腳本,該腳本調用一些Java類(如Batik)來創建pdf。除了創建一個多頁的PDF格式,以上所有的工作都很好。我不知道如何做到這一點。我對此很新。從一個svg文件創建多頁PDF

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> 

腳本:

<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> 

回答

0

我記得的多頁SVG的建議得到從版本1.2 SVG下降,我不認爲SVG 2.0將有它也是。

但是,您可以使用XPath或其他方法來使用SVG,您必須創建兩個SVG文件,其中每個SVG文件只包含一個面板。然後創建您的多頁PDF。