API Reference
Everything <rapi-pdf> takes and offers, read from the element’s own source. How to use it is in the overview; the same options in Node are on In Node.
Nothing on this page matches.
Attributes
Section titled “Attributes”Set on the element in HTML, or changed at runtime with setAttribute.
Spec Attributes 1
| Attribute | Description and allowed values | Default |
|---|---|---|
spec-url | URL of the spec: OpenAPI 3.x or Swagger 2.0, JSON or YAML. It fills the input field, and the reader can change it there. generatePdf(spec) takes a spec object or text instead. | — |
Output Attributes 2
| Attribute | Description and allowed values | Default |
|---|---|---|
output |
open shows the PDF in a new tab; download saves it. If the browser blocks the new tab, the PDF is downloaded instead. | open |
file-name | Name of the downloaded file; .pdf is added when it is missing. | api-reference |
PDF Content Attributes 9
| Attribute | Description and allowed values | Default |
|---|---|---|
pdf-title | Title on the cover page. | API Reference |
pdf-footer-text | Text at the bottom of every page. | — |
include-info |
false leaves out the cover page with the API's title, version, description and contact. | true |
include-toc |
false leaves out the table of contents. | true |
include-security |
false leaves out the security schemes. | true |
include-api-details |
false leaves out the operations: their parameters, request bodies and responses. | true |
include-example |
true adds the request and response examples. | false |
include-api-list |
true adds a closing list of every operation. | false |
pdf-sort-tags |
false keeps the tags in the spec's order instead of sorting them by name. | true |
PDF Look Attributes 3
| Attribute | Description and allowed values | Default |
|---|---|---|
pdf-schema-style |
How schemas are drawn: as an indented object, or as a table. | object |
pdf-primary-color | Color of headings and operation titles. | #b44646 |
pdf-alternate-color | Color of section labels and table headers. | #005b96 |
Element Look Attributes 6
| Attribute | Description and allowed values | Default |
|---|---|---|
button-label | Text of the button. | GENERATE PDF |
button-bg | Background color of the button (and the input's border). | — |
button-color | Text color of the button. | — |
input-bg | Background color of the spec URL field. | — |
input-color | Text color of the spec URL field. | — |
hide-input |
true hides the spec URL field, leaving only the button. | false |
Methods
Section titled “Methods”const pdf = document.querySelector('rapi-pdf');
await pdf.generatePdf(); // open or download, as the output attribute saysawait pdf.generatePdf(specObject); // a spec object or spec text instead of spec-urlconst blob = await pdf.getPdfBlob(); // the PDF itself, nothing opened or downloaded| Method | Description |
|---|---|
generatePdf(spec?) | Makes the PDF and opens it in a new tab, or downloads it when output="download". Takes a
spec URL, spec text or a spec object; without one, the spec-url attribute. Resolves when
the PDF is open or the download has started. |
getPdfBlob(spec?) | Makes the PDF and resolves with it as a Blob, without opening or downloading anything: for
a page that shows or uploads the PDF itself, or where new tabs are not allowed. |
Events
Section titled “Events”const pdf = document.querySelector('rapi-pdf');
pdf.addEventListener('pdf-generated', (e) => console.log('Made a PDF:', e.detail.output));pdf.addEventListener('pdf-error', (e) => console.error(e.detail.error));| Event | Description |
|---|---|
pdf-generated | A PDF was made. e.detail.output is
"open", "download" or "blob". |
pdf-error | The PDF could not be made. e.detail.error is the Error. |