PDFをSVGに変換したいのですが、これを効率的に実行できるライブラリ/実行可能ファイルを提案してください。私はapachePDFBoxとBatikライブラリを使用して独自のJavaプログラムを作成しました-
PDDocument document = PDDocument.load( pdfFile );
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document.
String svgNS = "http://www.w3.org/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つの異なるテキストブロックとして表示されます。上記のコードを修正する方法はありますか?または、より効率的に機能する別のソリューションを提案してください。