title: SVG to PDF using Apache FOP
body: <p>I have 3 SVG Files that I want to convert into a single PDF.
  I'm trying to do this with Apache FOP, but i am thus far unsuccessful.</p>
  <p>My idea was to simply write all 3 SVG files one after another into the resulting PDF, but that didn't work. My code for that looks like this:</p>
  <pre><code>public void convertSVG2PDF(File svg, File svg2, File svg3, File pdf) throws IOException,
          TranscoderException {
  
      // Create transcoder
      Transcoder transcoder = new PDFTranscoder();
      // Transcoder transcoder = new org.apache.fop.render.ps.PSTranscoder();
  
      // Setup input
      InputStream in = new java.io.FileInputStream(svg);
      InputStream in2 = new java.io.FileInputStream(svg2);
      InputStream in3 = new java.io.FileInputStream(svg3);
  
      try {
          TranscoderInput input = new TranscoderInput(in);
          TranscoderInput input2 = new TranscoderInput(in2);
          TranscoderInput input3 = new TranscoderInput(in3);
  
          // Setup output
          OutputStream out = new java.io.FileOutputStream(pdf);
          out = new java.io.BufferedOutputStream(out);
          try {
              TranscoderOutput output = new TranscoderOutput(out);
              TranscoderOutput output2 = new TranscoderOutput(out);
              TranscoderOutput output3 = new TranscoderOutput(out);
  
              // Do the transformation
              transcoder.transcode(input, output);
              transcoder.transcode(input2, output2);
              transcoder.transcode(input3, output3);
          } finally {
              out.close();
          }
      } finally {
          in.close();
      }
  }
  </code></pre>
  <p>And lastly my SVG images look like this, they are generated from a  javascript application.</p>
  <pre><code>&lt; svg height=&quot;70&quot; id=&quot;topBar&quot; version=&quot;1.1&quot; width=&quot;1060&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;
      &lt;g clip-path=&quot;url(#clip)&quot; height=&quot;560&quot; transform=&quot;translate(60,0)&quot; width=&quot;1060&quot;&gt;
        &lt;clipPath id=&quot;clip&quot;&gt;
          &lt;rect height=&quot;70&quot; width=&quot;1000&quot;/&gt;
    &lt;/clipPath&gt;
    &lt;rect fill=&quot;white&quot; fill-opacity=&quot;1&quot; height=&quot;70&quot; id=&quot;rect&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; width=&quot;1000&quot; x=&quot;0&quot; y=&quot;0&quot;/&gt;
    &lt;path d=&quot;M-35.63129521110456,34L-1.6312952111045584,68L32.36870478889544,34L-1.6312952111045584,1Z&quot; fill=&quot;white&quot; id=&quot;mileStones&quot; stroke=&quot;green&quot; stroke-width=&quot;2&quot;/&gt;
    &lt;path d=&quot;M269.4286615414018,34L303.4286615414018,68L337.4286615414018,34L303.4286615414018,1Z&quot; fill=&quot;white&quot; id=&quot;mileStones&quot; stroke=&quot;green&quot; stroke-width=&quot;2&quot;/&gt;
    &lt;path d=&quot;M674.5082762455497,34L708.5082762455497,68L742.5082762455497,34L708.5082762455497,1Z&quot; fill=&quot;white&quot; id=&quot;mileStones&quot; stroke=&quot;green&quot; stroke-width=&quot;2&quot;/&gt;
    &lt;text id=&quot;mileStoneText&quot; style=&quot;font-size: 15px;&quot; x=&quot;-16.631295211104558&quot; y=&quot;40&quot;&gt;MS1&lt;/text&gt;
    &lt;text id=&quot;mileStoneText&quot; style=&quot;font-size: 15px;&quot; x=&quot;288.4286615414018&quot; y=&quot;40&quot;&gt;MS2&lt;/text&gt;
    &lt;text id=&quot;mileStoneText&quot; style=&quot;font-size: 15px;&quot; x=&quot;693.5082762455497&quot; y=&quot;40&quot;&gt;MS3&lt;/text&gt;
  &lt;/g&gt;
  </code></pre>
    
  <p>My code thus far overwrites the pdf 2 times and the resulting PDF only contains the last SVG. I can also create 3 separate PDFs with the images inside. But i need all 3 on one page one beneath the other.</p>