• Font size
  • Line height
  • Font
  • PageOptions

    [email protected]

    Signature

    export interface PageOptions

    Specifies options for generating each PDF.

    Description

    All options are optional when specifying pages in a PagesMap or PagesFunction. See PagesEntry for more details.

    baseOptions can be used to specify options to apply to all pages, otherwise the default options will be used for options which are not specified.

    Members

    path

    Signature:
    path: string | ((url: URL, page: Page) => string | Promise<string>)

    Specify the location where the PDF will be generated.

    Default: '[pathname].pdf'

    This is treated like a href within the site, so absolute paths will be resolved relative to the root of the site. For example, /path/to/file.pdf and path/to/file.pdf are equivalent. If path contains certain special characters like %, you will need to encode those characters using encodeURI or encodeURIComponent.

    If the path contains [pathname], it will be substituted for the pathname of the page generated e.g. /path/to/page will be substituted into [pathname].pdf to get /path/to/page.pdf. If there are any redirects, the pathname will be the final location that is used to generate the PDF.

    path can also be a function which receives the final URL of the page and the Puppeteer Page. The function can return the path where the PDF will be generated as a string, or a Promise which will resolve to the path. The url parameter is equivalent to getting new URL(page.url()).

    If there is already a file with the same name, a counter suffix will be added to prevent overwriting the file. For example: example.pdf then example-1.pdf then example-2.pdf. This can be disabled with the ensurePath option.

    screen

    Signature:
    screen: boolean

    Use the CSS screen media type instead of the default print.

    Default: false

    This is set before callback is run.

    waitUntil

    Signature:
    waitUntil: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[]

    Used when Puppeteer is loading the page in Page.goto.

    Default: 'networkidle2'

    pdf

    Signature:
    pdf: PDFOptions | ((page: Page) => PDFOptions | Promise<PDFOptions>)

    Options to be passed to Puppeteer to specify how the PDF should be generated.

    Default: {}

    If you pass a callback, it will be called with the Puppeteer Page once it is loaded. You can use this to define dynamic page dimensions.

    ensurePath

    Signature:
    ensurePath?: boolean

    Set to true to ensure that the output path of the file is the same as the path option.

    Default: false

    This will prevent astro-pdf from adding the counter suffix if there is a file with the same name, and will instead cause the processing of that page to fail.

    viewport

    Signature:
    viewport?: Viewport

    Set the viewport for Puppeteer.

    This may be useful to set deviceScaleFactor. Read this Puppeteer issue for more info.

    Signature:
    navTimeout?: number

    Set the default navigation timeout (in milliseconds) for Puppeteer.

    This timeout applies when the page and all its contents are being loaded. A separate timeout is used when generating the PDF after the page is loaded. This can be set using the pdf option.

    The default used by Puppeteer is 30 seconds. This can be set to 0 to have no timeout.

    maxRetries

    Signature:
    maxRetries?: number

    The maximum number of times to retry loading and processing a page if there is an error.

    Default: 0

    throwOnFail

    Signature:
    throwOnFail?: boolean

    Set to throw errors encountered when loading and processing the page.

    Default: false

    This will cause the build of your site to fail when astro-pdf fails to generate the PDF for the page if Options.throwErrors is set to true (which is the default).

    By default, errors for failed pages will be logged and the Astro build will still successfully complete.

    isolated

    Signature:
    isolated?: boolean

    If set to true, a new BrowserContext will be created every time the page is loaded.

    Default: false

    This is like opening the page in a new incognito window, and isolated pages will not share any cookies or cache with the other pages.

    Otherwise, all other pages (with isolated: false) will be opened in the same browser context.

    preCallback

    Signature:
    preCallback?: (page: Page) => void | Promise<void>

    Receives a Puppeteer Page before any navigation is done.

    Parameters

    This can be used, for example, to set the user agent, or HTTP headers for the request.

    Note that the contents of the page will not be available as this is run before the page is loaded. If you need to access or modify the page contents, use the callback option

    callback

    Signature:
    callback?: (page: Page) => void | Promise<void>

    Receives a Puppeteer Page after the page has loaded.

    Parameters

    This callback is run before the PDF is generated.

    This can be used to modify the loaded page before generated the PDF, for example to remove certain elements, or eagerly load all images.