• Font size
  • Line height
  • Font
  • PagesFunction

    [email protected]

    Signature

    export type PagesFunction = (pathname: string) => PagesEntry | PagesEntry[]

    Defines the pages generated by astro-pdf using a callback, rather than listing all the pages in PagesMap.

    Description

    The callback will be called with each of the pathnames of the pages generated by Astro, and should return the options of the PDF file(s) to generate. If the return value is falsy, then no PDF files will be generated for that page. See PagesEntry for more details.

    The pathnames are normalised to have a leading slash. Whether the pathnames have a trailing slash will depend on build.format in your Astro config.

    Using PagesFunction alone will only allow generated PDF files from pages which are within your Astro site. For more flexibility, instead use the fallback option in PagesMap to define a PagesFunction in addition to the other locations, which can include other websites.

    Example

    {    pages: (pathname) => {        if (pathname === '/specific/page') {            return {                path: 'specific-page.pdf',                ensurePath: true,                throwOnFail: true            }        }        if (pathname.startsWith('/documents/')) {            return `/generated/${pathname.substring(11)}.pdf`        }    }}