DeckTape

repository·master·Indexed 25 days ago

https://github.com/astefanutti/decktape

A high-quality PDF exporter for HTML presentation frameworks such as Reveal.js, Remark, and Bespoke.js. Using Puppeteer and headless Chrome, it provides a CLI to capture slide decks as PDFs or images, featuring automatic framework detection, custom viewport sizing, slide range selection, and support for Docker and NPM installation.

Tokens
3.2K
Snippets
6
Records
16
Agent score
82%

What's inside decktape

  1. Install DeckTape via NPM

    master

    You can install DeckTape globally to run it directly from your terminal, or install it locally within a project.

    Global installation:

    $ npm install -g decktape
    $ decktape

    Local installation:

    $ npm install decktape
    $ npm exec decktape
    $ npm install -g decktape
    $ decktape
  2. Run DeckTape via Docker

    master

    DeckTape can be executed using the ghcr.io/astefanutti/decktape container image. This is useful for environments where you don't want to install Node.js or Puppeteer locally.

    Convert an online presentation to a local PDF: Mount the current working directory to /slides inside the container so the output is written to your host filesystem.

    $ docker run --rm -t -v `pwd`:/slides ghcr.io/astefanutti/decktape https://revealjs.com/demo/ slides.pdf

    Convert a local HTML file: Mount both your current directory and the directory containing your slides.

    $ docker run --rm -t -v `pwd`:/slides -v ~:/home/user ghcr.io/astefanutti/decktape /home/user/slides.html slides.pdf

    Convert a presentation on localhost: Use --net=host to allow the container to access your host's network. Note that on macOS and Windows, you may need to use host.docker.internal instead of localhost.

    $ docker run --rm -t --net=host -v `pwd`:/slides ghcr.io/astefanutti/decktape http://localhost:8000 slides.pdf
  3. Use the DeckTape CLI to export PDFs

    master

    DeckTape is a command-line tool that uses a browser (via Puppeteer) to capture slide decks and export them as PDF files. It automatically detects compatible plugins for the provided URL.

    Basic Usage: decktape <url> <filename>

    Example:

    decktape https://impress.js.org/ my_slides.pdf
  4. Troubleshooting DeckTape issues

    master

    No usable sandbox!

    If you encounter sandbox errors (common on Arch Linux), pass the --no-sandbox flag to Chrome:

    $ decktape ... --chrome-arg=--no-sandbox

    Mixed Content Errors

    If the page is HTTPS but requests insecure resources, allow insecure content:

    $ decktape ... --chrome-arg=--allow-running-insecure-content

    CORS / CSS Access Errors

    If you see Failed to read the 'rules' property from 'CSSStyleSheet', you may need to disable web security to allow access to local/external stylesheets:

    $ decktape ... --chrome-arg=--disable-web-security

    Layout Inconsistencies

    If the layout looks wrong, try setting a specific viewport size using the -s option:

    $ decktape -s 1024x768 <url> <filename>

    Reveal.js specific note

    Do not append ?print-pdf to the URL or load print stylesheets when using DeckTape with Reveal.js, as DeckTape captures slides individually.

  5. Use the `generic` command for unsupported frameworks

    master

    The generic command works by emulating end-user interaction. It is useful for HTML presentation frameworks that do not expose an API or accessible state.

    It works by pressing a specified --key (defaulting to ['ArrowRight']) and continues as long as:

    1. Changes are detected in the DOM (via mutation events on the body).
    2. The number of exported slides has not reached --max-slides.

    Example: Using custom keys

    $ decktape generic --key=ArrowDown --key=ArrowRight <url> <filename>
    $ decktape generic --key=ArrowDown --key=ArrowRight
  6. Configure Playwright 'use' options

    master

    The use object in the Playwright configuration defines shared settings for all test projects. In this repository, it configures:

    • actionTimeout: Set to 0 (no limit), meaning actions like click() will not time out by default.
    • trace: Set to 'on-first-retry', which collects a Playwright trace only when a test fails and is being retried.
    • baseURL: Set to http://localhost:3010 (via the port constant), allowing tests to use relative paths in commands like await page.goto('/').
      use: {
        /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
        actionTimeout: 0,
        /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
        trace: 'on-first-retry',
        baseURL: `http://localhost:${port}`
      },
  7. Configure Playwright test settings

    master

    The playwright.config.ts file defines the execution environment for DeckTape's Playwright-based tests. Key configuration areas include:

    • Test Execution: Sets the testDir to ./test, a global timeout of 30 seconds, and enables fullyParallel execution.
    • Assertions: The expect.timeout is set to 5000ms, which is the maximum time expect() calls will wait for conditions to be met.
    • CI Environment: When running in a CI environment (process.env.CI is truthy), the configuration automatically enables forbidOnly, sets retries to 2, and limits workers to 1 to prevent parallelization issues.
    • Reporting: Uses the html reporter to generate test results.
    • Web Server: Automatically starts a local development server using node test/run-server.js ${port} before running tests, reusing the existing server if it is already running.
    const config: PlaywrightTestConfig = {
      testDir: './test',
      timeout: 30 * 1000,
      expect: {
        timeout: 5000
      },
      fullyParallel: true,
      forbidOnly: !!process.env.CI,
      retries: process.env.CI ? 2 : 0,
      workers: process.env.CI ? 1 : undefined,
      reporter: 'html',
      use: {
        actionTimeout: 0,
        trace: 'on-first-retry',
        baseURL: `http://localhost:${port}`
      },
      projects: [
        {
          name: 'firefox',
          use: devices['Desktop Firefox'],
        }
      ],
      webServer: {
        command: `node test/run-server.js ${port}`,
        port,
        reuseExistingServer: true,
      },
    };
  8. Reference: DeckTape CLI Options

    master

    General options available for most commands:

    OptionDescription
    -s, --size <size>Size of the viewport (e.g. 1280x720)
    -p, --pause <ms>Duration in ms before each slide is exported [1000]
    --load-pause <ms>Duration in ms between page load and export start [0]
    --url-load-timeout <ms>Timeout for initial URL load [60000]
    --page-load-timeout <ms>Timeout for slide deck page load [20000]
    --buffer-timeout <ms>Timeout waiting for slide buffering [30000]
    --screenshotsCapture each slide as an image [false]
    --screenshots-directory <dir>Screenshots output directory [screenshots]
    --screenshots-size <size>Screenshots resolution (can be repeated)
    --screenshots-format <format>Image format: jpg, png [png]
    --slides <range>Range of slides to export (e.g. 1-3,5,8)
    --headlessPuppeteer headless mode: new, true, false [new]
    --headersComma-separated <header>,<value> pairs
    --chrome-path <path>Path to Chromium/Chrome executable
    --chrome-arg <arg>Additional Chrome arguments (can be repeated)
    --pdf-author <arg>PDF author string
    --pdf-title <arg>PDF title string
    --pdf-subject <arg>PDF subject string
  9. Capture specific slide ranges with --slides

    master

    You can use the --slides flag to export only a subset of the presentation. The range follows a pattern of slide indexes and ranges separated by commas.

    Example formats:

    • 1-3: Slides 1, 2, and 3.
    • 5: Only slide 5.
    • 1-3,5,8: Slides 1, 2, 3, 5, and 8.

    CLI Command:

    decktape https://example.com slides.pdf --slides 1-3,5,8
  10. Capture slide screenshots with `--screenshots`

    master

    To capture each slide as an image instead of (or in addition to) a PDF, use the --screenshots flag. You can configure the resolution, format, and directory using the following options:

    • --screenshots-directory <dir>: Output directory (default: screenshots).
    • --screenshots-size <size>: Resolution (e.g., 1280x720). This can be repeated to capture multiple resolutions.
    • --screenshots-format <format>: Image format, either jpg or png (default: png).

    Example: Capturing multiple resolutions

    $ decktape --screenshots --screenshots-size=400x300 --screenshots-size=800x600 <url> <filename>
    $ decktape --screenshots --screenshots-size=400x300 --screenshots-size=800x600
  11. Export specific slide ranges with `--slides`

    master

    Use the --slides option to export only a subset of the presentation. You can provide individual slide indexes, ranges, or a combination of both.

    Examples:

    • Single slide: --slides 1
    • Series of slides: --slides 1,3,5
    • Range of slides: --slides 1-10
    • Combination: --slides 1,2,5-10