The PDF designer element
<datum-pdf-designer> is the builder's PDF workspace on its own: the layout list, the page designer, template mode and the preview, without the form editor around them. Use it on a page where someone designs a form's PDF layouts and nothing else.
<link rel="stylesheet" href="datum-builder.css">
<script type="module" src="datum-builder.js"></script>
<datum-pdf-designer layout="contained" style="height: 720px"
src="/forms/intake.json"
values='{"fullName":"Ada Lovelace"}'></datum-pdf-designer>
<script type="module">
const designer = document.querySelector("datum-pdf-designer");
designer.addEventListener("datum-pdf-layout-change", (event) => {
save(event.detail.definition);
});
</script>It is defined by datum-builder., beside the builder, and it loads the same PDF files from the bundle folder. values gives the preview sample answers to draw.
What differs from the builder
- It shows the PDF workspace alone. There is no workspace switch, and the form's components, rules and journeys pass through untouched.
- Its bar does not carry New, Open and Download unless the page names them in
file-actions, such asfile-actions="download". - The PDF side is always on, whatever a
featureslist says.
Attributes
Every attribute and property of the builder element applies, including src, definition, save, pdf-theme and layout. One is its own:
| Attribute and property | What it does |
|---|---|
layout-idlayout | Which of the definition's PDF layouts is on the page. Takes layout id. Default the definition's default layout, else the first. |
Events
| Event | When |
|---|---|
datum-pdf-designer-ready | A layout is up and the methods can be called. detail. is that layout. |
datum-pdf-layout-change | A layout changed. detail. is the form with its layouts as they stand; detail also has layout, pdf (the layouts block) and reason. |
datum-pdf-layout-select | Another layout was put on the page. detail has layout and layout. |
The builder's own events, such as datum-builder-save and datum-error, fire here too.
Properties
| Property | What it is |
|---|---|
layout | Which layout is on the page, as the layout-id attribute. Setting it selects that layout once the designer is up. |
layouts | The layouts, in the definition's order. |
pdf | The layout on the page as designed so far. Assigning a layout replaces the one with that id, or adds it, and puts it on the page. |
ready | Whether the layout on the page is up. |
designer | The PDF designer behind the panels, when one is up. |
controller | The builder controller over the layout's tree. |
Methods
A page with its own layout list drives the designer from script.
The designer is loaded in a chunk of its own, so for a moment after the element connects its methods throw an error ("The PDF side is not set up yet"), and they keep throwing if pdf="off" is set or the chunk fails to load. Wait for datum-pdf-designer-ready before calling one. preview and render do not throw: they return a promise that rejects in the same cases.
| Method | Does |
|---|---|
select | Puts a layout on the page. |
new | Makes a layout and returns it. options is { name, from, select }: from is "form" (derived from the form), "blank" or "copy" of the layout on the page; select defaults to true. |
add | Adds a layout the page made or loaded. |
add | Adds an existing PDF as a template layout, ready for its fields to be mapped. source is { storage, name, type, size, data } for a file held in the layout as base64, or { storage, name, type, size, ref } for a file your own store holds (see Offering your own PDFs). |
replace | Swaps a layout for another under the same id. |
duplicate | Copies a layout and returns the copy. options may carry id, name and select. |
rename | Renames a layout. |
move | Moves a layout in the order they are tried in. |
set | Makes a layout the one drawn when no condition holds. |
remove | Removes a layout. |
open | Opens the designer's own Add menu, beside an element of the page's. |
preview | Draws the preview now. |
render | Draws the PDF and resolves with a result whose bytes are the file, with page, warnings, layout and file. |
Layouts, templates and what a PDF can carry are described in PDFs.