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

PDFlib - setting stroke and fill opacity (transparency)

在 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();

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

Is it possible to make rectangle's red fill and thick green border to be semi-transparent?

没问题,请使用 GState 完成此任务。您可以在 PDFlib 说明书中找到完整的示例代码:Transparent Graphics


    /* 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 objects.

中的示例