1

Is it possible to set value of alpha channel when providing fill and stroke colors in PDFlib?

$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?

temuri
  • 2,767
  • 5
  • 41
  • 63

2 Answers2

1

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

sure, please use GState for this task. You find a complete sample code within the PDFlib cookbook: 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();

For a powerful path generation, you might use the Path object. See PDFlib 9.2 Documentation as well the samples within PDFlib Cookbook - path objects.

Rainer
  • 2,013
  • 1
  • 10
  • 7
0
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 
Shashwat Gupta
  • 5,071
  • 41
  • 33