Options
[email protected]Signature
export interface Options
Specifies options for astro-pdf
.
Members
pages
Signature:
pages: PagesFunction | PagesMap
Specifies which pages in the site to convert to PDF and the options for each page.
This is the only required option.
maxConcurrent
Signature:
maxConcurrent?: null | number
Set the maximum number of pages to load and process at once.
By default, all pages will be loaded in parallel, which may result in a Puppeteer navigation timeout if there are too many pages.
If set to null
or undefined
, there will be no limit (which is the default behaviour).
install
Signature:
install?: boolean | Partial<InstallOptions>
Specifies whether to install a browser, or options to pass to Puppeteer install
.
By default, it will install the latest stable build of Chrome if install
is truthy and the browser to install is not specified.
If install
is false
or undefined
, but no browser is found, it will automatically install a browser.
launch
Signature:
launch?: LaunchOptions
Options to pass to Puppeteer launch
for launching the browser.
server
Signature:
server?: false | ((config: AstroConfig) => ServerOutput | Promise<ServerOutput>)
Function to launch a custom server which will be used to serve the built pages.
Returns: The URL of the server, and optionally a function to close the server. Note that only the origin of the URL will be used.
By default, astro preview
will be used.
However, if you are using an adapter, you will likely need to use a custom server as currently only the @astrojs/node
adapter supports astro preview
.
The server
function will be called with the projectβs Astro config.
This can also be set to false
to not run any server. If server
is set to false
or returns no URL, then only pages with a full URL specified for the location in PagesMap
will work.
baseOptions
Signature:
baseOptions?: Partial<PageOptions>
Default options to use for each page.
This will override the default options of PageOptions
.
throwErrors
Signature:
throwErrors?: boolean
Set to false
to prevent astro-pdf
from throwing any errors.
This will cause astro-pdf
to exit gracefully when it encounters errors, instead of the default behaviour of causing the whole Astro build to fail.
runBefore
Signature:
runBefore?: (dir: URL) => void | Promise<void>
Callback to run before astro-pdf
has started running anything, but after the Astro build has completed.
Parameters
-
dir
βThe file URL of the output directory
The function will be called with the file URL of the output directory.
runAfter
Signature:
runAfter?: (dir: URL, pathnames: string[]) => void | Promise<void>
Callback to run after astro-pdf
has finishing running and has generated all the PDFs.
Parameters
-
dir
βThe file URL of the output directory -
pathnames
βArray of the pathnames of PDF files generated
The function will be called with the file URL of the output directory, and a list of the pathnames of the generated PDFs.
The full file URL of each PDF can be resolved using the URL constructor:
const pdfUrl = new URL(pathnames[0], dir)
browserCallback
Signature:
browserCallback?: (browser: Browser) => void | Promise<void>
Receives the Puppeteer Browser
after it is launched.
Parameters
-
browser
βThe PuppeteerBrowser
used byastro-pdf
This can be used to configure the browser before any pages are processed.