Is there a workaround for having transparent gradients in PDF exports?

The cover page of my doctoral school’s LaTeX template has a mask with a transparent gradient making the blue lines progressively fade away:

I was able to reproduce this template in typst, and the SVG preview works well, but when I export it to PDF the mask becomes all white (there is no gradient anymore).

This is a known issue for more than a year now (Transparent Gradient does not export to PDF correctly · Issue #2546 · typst/typst · GitHub), so is there a workaround that does not involve compiling the cover page with LaTeX and concatenating it with the rest of my thesis in typst? Exporting my thesis to SVG is not an option, as the text is not selectable anymore.

For the sake of having a minimal example, the following code reproduces the bug:

#import "@preview/cetz:0.2.2": canvas, draw

#canvas(length: 5pt, {
  import draw: *

  // blue rectangle
  draw.rect(
    (0, 0), (4, 4), stroke: 0pt, fill: blue
  )

  // fading white mask
  draw.rect(
    (-.1, -.1), (3, 4.1), stroke: 0pt, fill: gradient.linear(dir: ltr,
      white, white.transparentize(100%)
    )
  )
})

SVG output:
image

PDF output:
image

1 Like

You could try to recreate just the background of your thesis cover with the transparent gradient, export that as SVG and then use it as a background with #set page(background: ...).

I wonder if that actually helps or if svg2pdf suffers from the same issue. @LaurenzV would know more. But PNG should work either way.

It works with the provided example at least.