我想在 PDFBox 中用透明线绘制线条和多边形。这是我如何绘制蓝线的一些示例代码,但我不知道如何更改颜色的 alpha 值。
PDDocument document = new PDDocument();
PDPage page = new PDPage();
document.addPage(page);
PDPageContentStream contentStream = new PDPageContentStream(document, page);
contentStream.setStrokingColor(66, 177, 230);
contentStream.drawLine(100, 100, 200, 200);
最佳答案
从 PDFBox 2.0 开始,appendRawCommands
已弃用。
float alpha = 0.5f;
PDExtendedGraphicsState graphicsState = new PDExtendedGraphicsState();
graphicsState.setStrokingAlphaConstant(alpha);
stream.setGraphicsStateParameters(graphicsState);
// draw line here
关于java - 用PDFBox画透明线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4540593/