gatsby-plugin-pdf

0.0.1 • Public • Published

gatsby-plugin-pdf

by Lundegaard

🖨 ⚙ 🔌

Gatsby plugin that is able generate PDFs out of your gatsby web pages

With the plugin you are able to generate PDFs out of your gatsby web pages. PDFs are created during build time and so you are able to store them into a folder from which you can serve them later on the web.

Github MIT License Downloads Version

Installation

Setup your gatsby project and add gatsby-plugin-pdf as your dependency

yarn add gatsby-plugin-pdf
npm install gatsby-plugin-pdf

Usage

In your gatsby project add a plugin definition into your gatsby-plugin.js config.

Example 1: Exporting pages /page1, /page2 and a root index.html denoted by single '/' in the config below.

module.exports = {
    ...
    plugins: [
        ...
        {
            resolve: 'gatsby-plugin-pdf',
            options: {
                paths: ['/', '/page1', '/page2'],
                outputPath: '/public/exports',
            },
        },
    ],
};
 

Example 2: Exporting all pages with additional inline style.

module.exports = {
    ...
    plugins: [
        ...
        {
            resolve: 'gatsby-plugin-pdf',
            options: {
                allPages: true,
                styleTagOptions: {
                    content: 'header{display:none;} footer{display:none;} .cookie-bar{display:none;}'
                }
            },
        },
    ],
};
 

Configuration options

  • allPages <[boolean]> When true all pages will be converted to PDF files. Defaults to false. Either allPages or paths property must be specified.
  • styleTagOptions <[Object]> Optional configuration. See addStyleTag puppeteer options: https://github.com/puppeteer/puppeteer/blob/v5.5.0/docs/api.md#pageaddstyletagoptions.
    • url <[string]> URL of the <link> tag.
    • path <[string]> Path to the CSS file to be injected into frame. If path is a relative path, then it is resolved relative to current working directory.
    • content <[string]> Raw CSS content to be injected into frame.
  • filePrefix <[string]> Optional prefix for exported PDF file.
  • outputPath <[string]> Optional path where to store generated PDFs. Relative to current project dir. Defaults to /public/exports.
  • paths <[Array]<[string]>> Array of page paths to convert to PDF. Path have to start with a leading /. You can pass nested paths like '/path/subpath'. For the root path use just single '/'. Either allPages or paths property must be specified.
  • pdfOptions <[Object]> Optional configuration. See pdf puppeteer options: https://github.com/puppeteer/puppeteer/blob/v5.5.0/docs/api.md#pagepdfoptions.

Contribution

We are open to any ideas and suggestions! Feel free to make PR!

See contribution guide for guidelines.

See our related projects

  • @redux-tools - Modular Redux is possible!
  • react-union - Intergrate React apps into various CMSs seamlessly.
  • validarium - Validations done right.
  • apium - Redux middleware for event-driven HTTP requests with async/await support.

© 2020 Lundegaard a.s.

Package Sidebar

Install

npm i gatsby-plugin-pdf

Weekly Downloads

24

Version

0.0.1

License

MIT

Unpacked Size

20.8 kB

Total Files

12

Last publish

Collaborators

  • kohout.jakub