Uploaded image for project: 'FOP'
  1. FOP
  2. FOP-3041

SVG image doesn't render properly in pdf using apache fop-1.1 and java

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Critical
    • Resolution: Unresolved
    • 1.1
    • None
    • image/svg
    • None

    Description

      I am trying to transcode an image test.svg in to a specified pdf with below code, but it fails to render properly.

      // Some comments here
      public class SvgToPdfUsingFop {
      	public static void main(String[] args) throws IOException {
      		File svg = new File("C:\\test.svg");
      		File pdf = new File("C:\\test_result.pdf");
      		Transcoder transcoder = new PDFTranscoder();
      		InputStream inputStream = new FileInputStream(svg);
      		try (FileOutputStream outputStream = new FileOutputStream(pdf);
      				BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);) {
      			TranscoderInput transcoderInput = new TranscoderInput(inputStream);
      			transcoderInput.setURI(svg.toURI().toString());
      			try {
      				TranscoderOutput transcoderOutput = new TranscoderOutput(bufferedOutputStream);
      				transcoder.transcode(transcoderInput, transcoderOutput);
      			} catch (Exception e) {
      				System.out.println(e);
      			}
      		} finally {
      			inputStream.close();
      		}
      	}
      }
      
      //Dependency
      <dependency>
                   <groupId>org.apache.xmlgraphics</groupId>
                   <artifactId>fop</artifactId>
                   <version>1.1</version>
              </dependency>
              <dependency>
                     <groupId>org.apache.avalon.framework</groupId>
                     <artifactId>avalon-framework-api</artifactId>
                     <version>4.3.1</version>
              </dependency>
              <dependency>
                     <groupId>org.apache.avalon.framework</groupId>
                     <artifactId>avalon-framework-impl</artifactId>
                     <version>4.3.1</version>
              </dependency>
      

      Screenshot of current output:

      Screenshot of Expected output:

      Could you please suggest me how I can achieve the expected result?

      Attachments

        1. current_output.png
          32 kB
          Srikant Das
        2. Expected_output.png
          23 kB
          Srikant Das
        3. out1.pdf
          12 kB
          J Frank
        4. output_without_mask.pdf
          27 kB
          Jan Tošovský
        5. test_jt.fo
          0.8 kB
          Jan Tošovský
        6. test_jt.svg
          7 kB
          Jan Tošovský
        7. test_svg.fo
          0.9 kB
          J Frank
        8. test.fo
          0.8 kB
          J Frank
        9. test.png
          3 kB
          J Frank
        10. test.svg
          7 kB
          Srikant Das
        11. test1.pdf
          10 kB
          J Frank

        Activity

          People

            Unassigned Unassigned
            srikdas Srikant Das
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: