Repository navigation
Description
Description
Proposal
Add PDF form elements, i.e. elements which when exported create form fields a user can interact with.
The following form elements are currently supported by pdf-writer 0.10.0:
- text
- fixed input size (comb)
- redacted (password)
- file selection
- choice
- list box (scrollable, single line)
- combo box (dropdown)
- custom input
- multi select
- buttons
- radio buttons
- push buttons
- check boxes
API
First, I want to propose the API for the elements themselves, ignoring name conflicts for now:
Text elements (PDF 1.7, Section 12.7.4.3)
#let text(
// whether this field is multiline or not
multiline: bool = false,
// whether this field is a password (redacted) field or not
passsword: bool = false,
// whether the field should scroll (horizontally) to accomodate large inputs
scroll: bool = true,
// whether the input should be separated into the given number of "characters" (like a bank number input field)
comb: int | none = none,
// default body
default: str | none = none,
) = ...Choice elements (PDF 1.7, Section 12.7.4.4)
#let choice(
// whether this field is a drop down or a list box
dropdown: bool = true,
// whether this field accepts custom choices
edit: false,
// whether more than one choice can be selected
multiselect: bool = false,
// the choices which are selected by default
default: array<str> | none = none,
// the choices the user is presented with
..choices: array<str>,
) = ...Push button elements (PDF 1.7, Section 12.7.4.2.2)
I am unsure whether these should be added in the first iteration of this feature, as they don't retain any value and require the viewer to support built-in actions (which they rarely do) or JS actions (which is yet rarer than support for the built-in options).
Check box elements (PDF 1.7, Section 12.7.4.2.3)
#let checkbox(
// the checkbox appearance when it is checked
on: content | auto = auto,
// the checkbox appearance when it is not checked
off: content | auto = auto,
// whether the checkbox is on or off by default
default: bool = false,
// positional + optional, the text to display with the checkbox
value: str | none,
) = ...Checkboxes display their text to the right of their box, I don't think this is configurable, but I could be wrong. Rendering it ourselves means we can support RTL layout, but lose interactivity for the displayed text, I believe.
The checkbox should create a block element which takes the size of the larger appearance.
Radio button elements (PDF 1.7, Section 12.7.4.2.4)
#let radio(
// the radio button appearance when it is checked
on: content | auto = auto,
// the radio button appearance when it is not checked
off: content | auto = auto,
// whether the radio button is on or off by default
default: bool = false,
// positional, the key to associate the radio button to
key: str,
// positional + optional, the text to display with the radio button
value: str | none,
) = ...Radio buttons are tricky, my current design simply provides a key and should error when there is more than one set to enabled by default. Having more than one button enabled is valid for some cases, but these rely on a feature that most PDF viewers get wrong (RadiosInUnison).
I'm not sure if we have the infrastructure in place to throw an error when multiple elements use the same key and default: true, if not we may need export-errors first.
Name conflicts
There are some name conflicts to address, combined with the fact that we will either need a more restrictive interface to accommodate HTML forms in the future, or have these be PDF specific (which I think makes more sense, see additional notes be low), the PDF form fields should be placed in a module for PDF specific features and elements. See #4174 for a possible API related to this.
Assuming we chose implementing "low level" access for PDF forms here first and implementing a high level interface encompassing both PDF and HTML in the future, moving them into a pdf or pdf.form scope seems sensible to me. Users could still access them in a simpler fashion by importing from the scope if need be. We'd then have:
pdf.form.textpdf.form.choicepdf.form.checkboxpdf.form.radio
Implementation Details
Because of how forms work in PDF and how we want to display forms ideally, we should strive to not use appearance streams in PDF at all and instead render form annotation fields on top of Typst native elements such as rect and block for styling. This has the benefit that they can be exported to all non-interactive export targets with the consistent styling and minimal effort. This also means that we lose functionality (e.g. switching appearances depending on hover) if we don't reimplement PDF viewer behavior for other export targets.
At least this is my initial thought, some appearance streams are simply FormXObjects, which are basically whatever content you throw at them, so maybe we can still support the hover and input appearance changes anyway.
Additional Notes
Some of the features have been deliberately left out, as they are deemed too arcane for now. This issue should serve as a place to discuss whether they should be added.
Whether two named parameters can be used together and how will follow the spec (Section 12.7.4), if there are conflicting values for the given fields an error with a hint will be thrown.
Because Typst is working towards HTML support, eventually HTML forms will have to be supported too, these will necessarily have a different API and feature set, so this RFC does not attempt to create a unified API. #4174 may be used as a basis for a more restrictive common API between different export targets supporting similar features.
Use Case
Would be cool.
Activity
tingerrr commentedon Jun 10, 2024
At this moment, these fields would be
100%sized, so putting a container around them would be required for both styling (consistent across export targets) and sizing by putting explicit constraints on those.I'm unsure whether this is a good idea, but otherwise we may need to duplicate loads of options from
blockand such on those elements.Enter-tainer commentedon Jun 11, 2024
What would they look like in png and svg?
Enivex commentedon Jun 11, 2024
Presumably the same, but without the actual ability to interact with the form.
tingerrr commentedon Jun 11, 2024
Yeah, basically that, the assumption is that, if we don't use PDF specific styling, but instead use Typst content where ever possible they'd look the same everywhere and the PDF export only really differs in adding the interactive part of the form.
reknih commentedon Jun 11, 2024
I have a few questions and remarks:
#show checkbox: set rect(...)to quickly customize or do I always have to implement the show rule?widthandheighton every control be nicer than having to wrap it in a block?#show checkbox.active: (it) => {}or does it work like headers and footers in a page set rule?radio.grouporradiogroupfunctionwrzian commentedon Jun 11, 2024
I know naming is subjective, but having
textas the name feels confusing even if it is scoped due to how fundamental the current text function is to Typst. I'd argue for something liketextboxinstead.tingerrr commentedon Jun 11, 2024
It would be a simple block level element, not really reusing anything other than
blockat most.Well maybe, but then we'd likely also need to add other possibly redundant appearance options.
Perhaps we always use a block element with an
autodefault size and allow configuration throughshow-set. See below regarding appearance.At this moment not at all, this dies into how I want to avoid using appearance streams.
Let's entertain the thought of exposing this to users, we'd expose either fields or sub elements to distinguish how an element is displayed, it's not important how this works, the problems I am concerned about exist in both cases.
If we want an API that allows a user to reuse primitive elements like above, we quickly run into the problem of how to translate this into appearance streams correctly and catching all the invalid edge cases like differing sizes of a text box block.
A hover action would only switch things like stroke type, color and the like.
If we instead faithfully expose appearance streams, we need to ensure that we correctly render something in non-PDF targets that will look like forms, which to me sounds like implementing parts of a PDF reader. This could quickly get out of hand, and I'm unsure how much of the whole PDF annotation transformation matrix shtick is required to correctly size and transform such appearances.
We definitely want to faithfully display forms on PNG and SVG, simply because they are used as preview export targets. My key takeaway is that I want to reuse rendering of primitive elements where possible. Using appearance streams like those (or in general) makes this more brittle in its implementation and more restrictive in its user-facing API.
I left this out as sendable forms are a feature which basically only Acrobat implements and, at least from my subjective experience, no one really uses. This is also one of the reasons I'm unsure about push buttons, their only use cases are some a few arcane custom actions and JS actions.
The keys in forms are also hierarchical, which is not easily done in Typst without having the user spell out the full path for the keys. We could add this in post and reserve a
keyfield for them. It should be noted that hierarchical keys are also rarely used, so maybe this is not a big issue.I considered this in earlier designs, but I'm not aware of any mechanism at this moment that supports allows forcing one element to only be created inside another. Consider
#figure.caption, which can be created outside afigure, but arguably shouldn't. I'm unsure if this is due to this limitation, if it exists, or if it's simply an oversight.It should also be noted that such a group would not allow one to easily place connected radio buttons in completely different places, which PDF allows. This feature is rather arcane, though, and I've not seen it used much in forms I collected. I'm fine with not allowing this and going for a super/sub element design. This also avoids having a spurious key field which could later conflict with sendable forms.
See above regarding hover/normal etc.
Sure, this makes sense to me.
Enivex commentedon Jun 11, 2024
How about
freeform?stanlrt commentedon Nov 2, 2025
whardier commentedon Nov 2, 2025
I am curious how font handling would happen.. as several fonts may be required for full embedding.
Enivex commentedon Nov 2, 2025
euberdeveloper commentedon Feb 10, 2026
dayala1 commentedon Mar 5, 2026
This would be fundamental for adoption of Typst in many institutions that need forms for people to easily fill for many bureocratic processes (e.g. universities). Until it is added, people will just keep using Word.
PavanSamyak commentedon Jun 4, 2026
I'm new to typst can anyone help me to get ineractive checkbox on to my pdfs please
cady-b commentedon Jun 4, 2026
@PavanSamyak Please direct support requests to the Forum or Discord; the issue tracker is not quite the place for such discussions.
TLDR; Forms are not yet implemented, so there is no way you can currently construct interactive checkboxes within your documents. There is an effort behind changing that in the future (but no ETA, no promises): https://bsky.app/profile/typst.app/post/3mmrma5rjss2u
You can otherwise use third-party solutions to create interactive overlays over any plain PDF. I assume Adobe & Co. have offerings here, but can't make general recommendations; https://github.com/carpe-diem/typst-fillable has been shared with the community, but I haven't looked over the code so run at your own risk.