The fact that typst easily compiles in the browser brought me the idea that it could be cool to let people fill out forms and generate PDFs from them on a webpage.
The idea is to not need any PDF-Forms support (I had often some problems with them not saving correctly, being cut off, not being printed even though they are shown in the pdf and so on…) but just generating a PDF.
Typst reflection capabilities allows to declare the inputs that are needed in the document and generate a form from this.
I created a small proof-of-concept for this here: Typst Forms
You can see how the arguments are declared and used in the document. If you add more, those will automatically be added to the form where you can fill them. The preview is done by an SVG (and I find it mind-blowing that it is updated basically as fast as I type).
Thanks @quachpas who helped me with getting the argument declaration nice and clean.
9 Likes
Wow, this is really impressive!
Typst is so versatile. Great idea to use it this way.
How have you personally planned to use this?
1 Like
Thanks :-)
I am part of a club where different people organize different events, but we want to keep a uniform appearance for any documents that need to be generated. We have tex-templates for that, but not everyone is proficient with that and it’s just more complicated than necessary. I’m thinking about replacing that with a solution based on this proof-of-concept.
3 Likes
That’s really nice! you populate the form by querying the document, right? Is that some existing form builder (that can take a JSON-like schema) or is it your own? I wonder how easy it would be to extend this to tabular data…
Everything I’ve done here is a bit hacky^^ The typst query returns json containing an object that is basically the same as the declared args (an entry for each arg and as value the declare default). I have some vanilla js that just loops over those entries and creates a label and input tag for each of them: scripts/index.js · trunk · Nicholas Schwab / typst-forms · GitLab
I’m not quite sure what you mean with tabular data in this context, but I think it is relatively easy to adapt for most uses.
Making this bases on json schema would of course be an option, but then you’d have to generate the json schema. I tend to think this will be nicer to use when keeping the declaration very simple.
So there isn’t much data to put into the json schema (the only thing I could think of right now would be the type of the default value). So at least for me, the json schema seems to be too complex to be worth it, here.
But there are surely use cases where it would make sense. Though then I’d think about starting with the json schema and import that into the typst document (maybe using a rust lib wrapped into a wasm plugin) and generate the forms from it.
I think this very much depends on what one wants to do with it.