• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need Java program to convert SVG to PDF format

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I need to convert some SVG (scalable vector graphics) files to PDF format. I tried using Apache Batik toolkit to do the conversion and it didnt work. Does someone know about any other toolkit or a java program that can convert SVG files to PDF.

I am primarily looking for a java program and not an application because I need to run this java program in server.

Please let me know if you have any idea.
Thanks in advance!
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello "mkumar"-

Welcome to JavaRanch.

On your way in you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.

As to your question, what does "it didnt work" mean? What exactly did you try, and what happened?
 
Mansa Kumar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By "it didnt work" I meant that I had a java program using apache batik for converting SVG to PDF and that didnt work.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, that's how I understood it, but that doesn't answer the question "What exactly did you try, and what happened?" TellTheDetails
 
Mansa Kumar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My client used Verydoc to convert an EMF (enhanced metafiles) to SVG and I had to convert that SVG file to a PDF. I am getting an exception while converting the given SVG to PDF using the apache batik supported program.

The error message is:
java.io.IOException: The prefix "xlink" for attribute "xlink:href" associated with an element type "image" is not bound.
at org.apache.batik.dom.util.SAXDocumentFactory.createDocument(Unknown Source)
at org.apache.batik.dom.util.SAXDocumentFactory.createDocument(Unknown Source)
at org.apache.batik.dom.svg.SAXSVGDocumentFactory.createDocument(Unknown Source)
at org.apache.batik.dom.svg.SAXSVGDocumentFactory.createDocument(Unknown Source)
at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown Source)
at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)

and the Java source code is:
//Create transcoder
Transcoder transcoder = new PDFTranscoder();
//Transcoder transcoder = new org.apache.fop.render.ps.PSTranscoder();

//Setup input
File svgFile = new File(svg);
File pdfFile = new File(pdf);

InputStream in = new java.io.FileInputStream(svgFile);
try {
TranscoderInput input = new TranscoderInput(in);

//Setup output
OutputStream out = new java.io.FileOutputStream(pdfFile);
out = new java.io.BufferedOutputStream(out);
try {
TranscoderOutput output = new TranscoderOutput(out);
//Do the transformation
transcoder.transcode(input, output);
} finally {
out.close();
}
} finally {
in.close();
}

Because of this, I am looking for another java program which can successfully convert this SVG file to PDF (If not PDF then JPEG/TIFF in the worst case.).

Thanks a ton.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does it work if you alter the SVG so that it declares the proper XLink URI namespace? Its proper value should be "http://www.w3.org/1999/xlink". If that works, maybe you can get the SVG-emitting process to write that out, or -alternatively- add an intermediate step that adds that namespace declaration to the SVG file.
 
Mansa Kumar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for the idea. The generated SVG was in fact missing the namespace binding along with couple of mismatched end tags. I added xmlns:xlink="http://www.w3.org/1999/xlink" in the svg tag and added the missing end tags and it worked fine.

My client uses Verydoc to create SVG files and Verydoc generated SVG file was not well formed XML and because of this I have to look for another java program that might convert these to PDF overlooking well formedness (like the way IE does, btw IE renders these SVG files well).

Any idea about non-batik program?
Thanks again.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I doubt that there is any serious software that will handle malformed XML. IE makes a best effort to display something, just like it does with crappy HTML, but you shouldn't expect that.

It's inexcusable for a commercial software to generate malformed XML; have their developers fix that - it's a major bug.
 
Mansa Kumar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks again Ulf
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic