Apache Batik - 例外:“prolog中不允许的内容”将PDF转换为JPEG

时间:2012-11-07 15:44:42

标签: java svg transcoding batik

当我尝试将某些PDF转换为JPEG时,我收到一个例外,其中包含“prolog中不允许的内容”消息。我正在执行两步操作,将SVG转换为PDF,然后将PDF转换为图像。

当我尝试进行Batik的直接处理时,我正面临这个问题。

这是我的代码。

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();

2 个答案:

答案 0 :(得分:0)

Batik transcoders期望获得SVG数据作为输入,而不是pdf文档。

答案 1 :(得分:0)

我找不到任何暗示您可以使用Batik将PDF转换为JPEG的内容。顺便说一句,Batik是一个XML图形库,不是一般的代码转换库。从PDF转换为JPEG不是它的用途,而是用于将SVG输入显示和/或转码为某些图像输出。

现在,有人说,你有什么理由不能直接从SVG转到JPEG吗?或者使用Batik从SVG转换为PDF,然后使用除Batik之外的其他库将PDF转换为JPEG?您对此方法有何疑虑?

相关问题