Sematre / typst-letter-pro

DIN 5008 letter template for Typst
https://typst.app/universe/package/letter-pro/
MIT License
67 stars 2 forks source link

Add option to include the stamp directly as a svg #6

Open VincentWo opened 2 months ago

VincentWo commented 2 months ago

Hi there, I really love this template! I would like to have the possibility to directly include a stamp using the library without having to use external tools (especially since I am using typst in my browser and don't want to do the workflow of downloading the document, looking up the syntax, looking up the download place of the stamp, opening it again, print it...

I achieved this in a rather hacky way by putting place(top + left, image("stamp.svg")) into the background property at this line Would you be open to such an addition? (Obviously in a less hardcoded way)

Sematre commented 2 months ago

I would love to have this option built-in. Unfortunately, I haven't found a good solution for this yet.

Deutsche Post only distributes stamps in the form of PDFs and as far as I can tell, the only sane way to process stamps from them is to use the DIN A4 Normalpapier (Einlegeblatt) format. That means the best solution would be for Typst to have a built-in function to overlay PDFs, just like you can do in LaTeX:

\usepackage{pdfoverlay}
\pdfoverlaySetPDF{TestPrint.pdf}

But since this is not possible (yet?), my idea is to have users be able to declare the stamp like this:

#show: letter-simple.with(
  // [...]
  stamp: image("TestPrint.svg"),
  // [...]
)

For that to work, you would first need to convert the PDF from Deutsche Post to an SVG. The best solution that I could find was the Inkscape CLI:

$ inkscape TestPrint.pdf -o TestPrint.svg

Now you're able to include the picture in Typst, just like you suggested. This is the resulting address box. Letter_with_stamp

For comparison, here's the resulting address box using qpdf. Letter_with_stamp_using_qpdf

Not a bad result, considering this is what the SVG version would look like in earlier Typst versions when I started this project. Screenshot from 2024-04-22 01-33-05

Despite the result, I'm still kind of not satisfied with the SVG version. I'm open for any suggestions on this topic. I'm also attaching my benchmark stamp from Deutsche Post.