Skip to content

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.

Set on the element in HTML, or changed at runtime with setAttribute.

Spec Attributes 1

AttributeDescription and allowed valuesDefault
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

AttributeDescription and allowed valuesDefault
output

opendownload

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

AttributeDescription and allowed valuesDefault
pdf-title
Title on the cover page.
API Reference
include-info

truefalse

false leaves out the cover page with the API's title, version, description and contact.
true
include-toc

truefalse

false leaves out the table of contents.
true
include-security

truefalse

false leaves out the security schemes.
true
include-api-details

truefalse

false leaves out the operations: their parameters, request bodies and responses.
true
include-example

truefalse

true adds the request and response examples.
false
include-api-list

truefalse

true adds a closing list of every operation.
false
pdf-sort-tags

truefalse

false keeps the tags in the spec's order instead of sorting them by name.
true

PDF Look Attributes 3

AttributeDescription and allowed valuesDefault
pdf-schema-style

objecttable

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

AttributeDescription and allowed valuesDefault
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

truefalse

true hides the spec URL field, leaving only the button.
false
const pdf = document.querySelector('rapi-pdf');
await pdf.generatePdf(); // open or download, as the output attribute says
await pdf.generatePdf(specObject); // a spec object or spec text instead of spec-url
const blob = await pdf.getPdfBlob(); // the PDF itself, nothing opened or downloaded
MethodDescription
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.
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));
EventDescription
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.