我成功地使用Apache Batik将SVG文件转换为PDF.
以下代码用于生成PDF:
import org.apache.fop.svg.PDFTranscoder;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
...
File svgFile = new File("./target/test.svg");
...
PDFTranscoder transcoder = new PDFTranscoder();
try (FileInputStream fileInputStream = new FileInputStream(svgFile); FileOutputStream fileOutputStream = new FileOutputStream(new File("./target/test-batik.pdf"))) {
TranscoderInput transcoderInput = new TranscoderInput(fileInputStream);
TranscoderOutput transcoderOutput = new TranscoderOutput(fileOutputStream);
transcoder.transcode(transcoderInput, transcoderOutput);
}
Run Code Online (Sandbox Code Playgroud)
现在我想影响生成的PDF的页面大小,以便获得A4的页面大小.我怎么能这样做?
我尝试了一些关键的提示,但没有效果.