我通过以下方式将图像加载到pdf:

PDImageXObject image= PDImageXObject.createFromFile(<image_path>, doc);
contentStream.drawImage(image, 15, pdfData.getPageHeight() - 80,
image.getWidth(), image.getHeight());


我正在尝试使图像看起来透明,就像在文档的标题(Google文档,Word等)中一样
是否有捷径可寻?

最佳答案

使用扩展的图形状态:

stream.saveGraphicsState();
PDExtendedGraphicsState pdExtGfxState = new PDExtendedGraphicsState();
pdExtGfxState.getCOSObject().setItem(COSName.BM, COSName.MULTIPLY); // pdExtGfxState.setBlendMode(BlendMode.MULTIPLY) doesn't work yet, maybe in later version
pdExtGfxState.setNonStrokingAlphaConstant(0.5f);
contentStream.setGraphicsStateParameters(pdExtGfxState);
// do your stuff
stream.restoreGraphicsState();

关于java - 使用pdfbox将透明图像插入pdf,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43964930/

10-08 22:28