PDFlib - 设置描边和填充不透明度(透明度)



在PDFlib中提供填充和描边颜色时是否可以设置alpha通道的值?

$p->setlinewidth(20);
$p->setcolor('fill', 'rgb', 1, 0, 0, null);
$p->setcolor('stroke', 'rgb', 0, 1, 0, null);
$p->rect(0, 0, 100, 100);
$p->fill_stroke();

是否可以使矩形的红色填充和粗绿色边框半透明?

是否可以使矩形的红色填充和粗绿色边框半透明?

当然,请使用 GState 来完成此任务。您可以在 PDFlib 说明书中找到完整的示例代码:透明图形


/* Save the current graphics state. The save/restore of the current
* state is not necessarily required, but it will help you get back to
* a graphics state without any transparency.
*/
$gstate = $p->create_gstate("opacityfill=.5 opacitystroke=.5");
$p->save();
$p->set_gstate($gstate);
$p->setlinewidth(20);
$p->setcolor('fill', 'rgb', 1, 0, 0, null);
$p->setcolor('stroke', 'rgb', 0, 1, 0, null);
$p->rect(0, 0, 100, 100);
$p->fill_stroke();
$p->restore();

对于功能强大的路径生成,可以使用 Path 对象。请参阅 PDFlib 9.2 文档以及 PDFlib Cookbook 中的示例 - path 对象。

page.drawText(WATERMARK.LABEL, {
x: 180,
y: 400,
size: 30,
font: helveticaFont,
color: rgb(220 / 255, 220 / 255, 220 / 255),
rotate: degrees(-315),
opacity: 0.6
})
// add opacity field only 

最新更新