我一直在使用 PDFKit 和 NodeJS 为我们正在开发的应用程序生成 PDF,但我无法设置路径的描边不透明度和填充不透明度。
这就是它在 PDF 中的显示方式:(忽略一些区域的浅灰色,这是水印)
两者的不透明度值均应为 0.6。这就是我尝试应用填充描边和不透明度的方式:
pdfDocument.path(pathString);
pdfDocument.lineCap('butt');
pdfDocument.lineJoin('miter');
pdfDocument.lineWidth(strokeWidth);
pdfDocument.fillOpacity(opacity);
pdfDocument.strokeOpacity(opacity);
pdfDocument.fillAndStroke(fillColor, strokeColor, fillRule);
pdfDocument.stroke();
我不明白为什么不对描边和填充应用不透明度。我已经尝试过仅使用不透明度函数并移动两组不透明度,但没有任何反应。
最佳答案
调试库后发现这个问题从 2014 年开始
事实证明,在设置 fillAndStroke
之前,我们需要先设置 fillColor
的不透明度和 StrokeColor
的不透明度。
pdfDocument.path(pathString);
pdfDocument.lineCap('butt');
pdfDocument.lineJoin('miter');
pdfDocument.lineWidth(strokeWidth);
// HERE IS THE TRICK.
pdfDocument.fillColor(fillColor, opacity);
pdfDocument.strokeColor(strokeColor, opacity);
pdfDocument.fillAndStroke(fillColor, strokeColor, fillRule);
pdfDocument.stroke();
关于node.js - 具有填充、描边和不透明度的 PDFKit 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47328584/