1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > java pdf转svg_将pdf转换为svg

java pdf转svg_将pdf转换为svg

时间:2022-02-24 14:14:52

相关推荐

java pdf转svg_将pdf转换为svg

我想将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个不同的文本块。有没有办法修复上面的代码?或者建议另一个解决方案,将更有效地工作。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。