我想将PDF转换为SVG,请建议一些库/可执行文件,将能够有效地做到这一点。我已经写了我自己的java程序使用apache PDFBox和Batik库 –
PDDocument document = PDDocument.load( pdfFile );
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document.
String svgNS = "/2000/svg";
Document svgDocument = domImpl.createDocument(svgNS, "svg", null);
SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(svgDocument);
ctx.setEmbeddedFontsOn(true);
// Ask the test to render into the SVG Graphics2D implementation.
for(int i = 0 ; i < document.getNumberOfPages() ; i++){
String svgFName = svgDir+"page"+i+".svg";
(new File(svgFName)).createNewFile();
// Create an instance of the SVG Generator.
SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx,false);
Printable page = document.getPrintable(i);
page.print(svgGenerator, document.getPageFormat(i), i);
svgGenerator.stream(svgFName);
}
这个解决方案工作伟大,但所产生的svg文件的大小巨大(许多倍大于pdf)。我已经弄清楚问题是在文本编辑器中查看svg的位置。即使字符的字体属性相同,也会将原始文档中的每个字符包含在其自己的块中。例如,词hello将显示为6个不同的文本块。有没有办法修复上面的代码?或者建议另一个解决方案,将更有效地工作。