【问题标题】:PDFKit Paths with fill, stroke and opacity具有填充、描边和不透明度的 PDFKit 路径
【发布时间】:2017-11-16 11:31:59
【问题描述】:

我一直在使用带有 NodeJS 的 PDFKit 为我们正在开发的应用程序生成 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();

我不明白为什么不对描边和填充应用不透明度。我已经尝试过只使用 opacity 函数并移动两组不透明度,但什么也没发生。

【问题讨论】:

    标签: node.js pdfkit node-pdfkit


    【解决方案1】:

    调试库后发现2014年的这个问题

    Opacity #259

    原来我们需要在设置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();
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多