1 回答
TA贡献1993条经验 获得超5个赞
我真的不知道为什么这个库会发生这种情况,因为没有答案,我已将 SVGSalamendar 更改为 Batik 库,如果有人需要,这是它的工作代码
Maven 依赖项
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-svggen</artifactId>
<version>1.11</version>
</dependency>
<!-- https://mvnrepository.com/artifact/batik/batik-transcoder -->
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-transcoder</artifactId>
<version>1.11</version>
</dependency>
<!-- https://mvnrepository.com/artifact/batik/batik-rasterizer -->
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-rasterizer</artifactId>
<version>1.11</version>
</dependency>
Java 代码反映与上面相同的结果:
private static Image createSVGImage(PdfWriter pdfWriter, String imageEntry) throws BadElementException, IOException {
Image image = null;
final BufferedImage[] imagePointer = new BufferedImage[1];
PdfContentByte pdfCB = new PdfContentByte(pdfWriter);
try {
TranscoderInput input = new TranscoderInput(new FileInputStream(imageEntry));
ImageTranscoder t = new ImageTranscoder() {
@Override
public BufferedImage createImage(int w, int h) {
return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
}
@Override
public void writeImage(BufferedImage img, TranscoderOutput output) throws TranscoderException {
// TODO Auto-generated method stub
imagePointer[0] = img;
}
};
t.addTranscodingHint(ImageTranscoder.KEY_FORCE_TRANSPARENT_WHITE,
Boolean.FALSE);
t.addTranscodingHint(ImageTranscoder.KEY_BACKGROUND_COLOR, Color.white);
t.transcode(input, null);
}
catch (TranscoderException ex) {
// Requires Java 6
ex.printStackTrace();
throw new IOException("Couldn't convert ");
}
image = Image.getInstance(pdfCB, imagePointer[0], 1);
return image;
}
添加回答
举报