gpt4 book ai didi

java - 使用pdfbox将透明图像插入pdf

转载 作者:行者123 更新时间:2023-11-30 06:48:43 26 4
gpt4 key购买 nike

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

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

我试图让图像看起来透明,就像它在文档(google docs、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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com