0

I am getting the an exception when I try to convert some PDF to JPEG, with the message "content not allowed in prolog". I am performing a two-step opertaion converting SVG to PDF and then PDF to image.

I am facing this issue when I try to do the direct process which Batik is meant for.

Here is my code.

File pdfFile= new File("path to pdffile");
InputStream in = new java.io.FileInputStream(pdfFile);
JPEGTranscoder transcoder = new JPEGTranscoder();
transcoder.addTranscodingHint(JPEGTranscoder.KEY_XML_PARSER_CLASSNAME,
        "org.apache.crimson.parser.XMLReaderImpl");
transcoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,
        new Float(1.0));
TranscoderInput input = new TranscoderInput(in);
OutputStream ostream = new FileOutputStream("path to jp file here!");
TranscoderOutput output = new TranscoderOutput(ostream);
transcoder.transcode(input, output);
ostream.close();
Raedwald
  • 40,290
  • 35
  • 127
  • 207
varunrao321
  • 835
  • 2
  • 10
  • 17

2 Answers2

0

Batik transcoders expect to be given SVG data as input, not pdf documents.

Robert Longson
  • 102,136
  • 21
  • 218
  • 211
  • Thanks for your reply Robert, I am using a Kala SVG, decomperssing it and then converting it to image, but the quality has diminished, I am using the code sample code explained on the site. Help of any sort is appreciated!! – varunrao321 Nov 19 '12 at 07:07
0

I can't find anything that suggests you can convert PDF to JPEG with Batik. Btw, Batik is an XML graphics library, not a general transcoder library. Converting from PDF to JPEG is not what it's for, it's for displaying and/or transcoding SVG input to some image output.

Now, that being said, is there any reason you can't go straight from SVG to JPEG? Or use Batik to do the transcoding from SVG to PDF, then use another library besides Batik to transcode PDF to JPEG? What are your concerns involving this approach?

Brian
  • 16,069
  • 5
  • 38
  • 64
  • Thanks for your reply Brian. I am using a Kala SVG, decomperssing it and then converting it to image, but the quality has diminished. I am using the code sample code explained on the site. Help of any sort is appreciated!! – varunrao321 Nov 19 '12 at 07:08