|
| 1 | +# PDF Generator for OpenSearch Documentation |
| 2 | + |
| 3 | +This plugin generates PDF versions of documentation collections during the Jekyll build process. |
| 4 | + |
| 5 | +## File Structure |
| 6 | + |
| 7 | +All PDF generator code is contained in the `_pdf_generator/` directory: |
| 8 | +- `pdf_generator.rb` - Main plugin implementation |
| 9 | +- `README.md` - This documentation file |
| 10 | + |
| 11 | +A minimal loader file exists in `_plugins/pdf_generator_loader.rb` to ensure Jekyll loads the plugin (Jekyll requires plugins to be in `_plugins` or be gems). |
| 12 | + |
| 13 | +## Overview |
| 14 | + |
| 15 | +The PDF generator creates downloadable PDF files for documentation collections and guides. PDFs are generated automatically during the Jekyll build and are saved to the `pdfs/` directory in the site destination. |
| 16 | + |
| 17 | +## Configuration |
| 18 | + |
| 19 | +PDF generation is configured in `_config.yml` under the `pdf_generator` section: |
| 20 | + |
| 21 | +```yaml |
| 22 | +pdf_generator: |
| 23 | + enabled: true |
| 24 | + # Generate PDFs for entire collections |
| 25 | + collections: |
| 26 | + - getting-started |
| 27 | + - install-and-configure |
| 28 | + - api-reference |
| 29 | + # Generate PDFs for specific guides (more granular control) |
| 30 | + guides: |
| 31 | + - name: "Getting Started Guide" |
| 32 | + collection: getting-started |
| 33 | + filename: "getting-started-guide.pdf" |
| 34 | + - name: "Installation Guide" |
| 35 | + collection: install-and-configure |
| 36 | + filename: "installation-guide.pdf" |
| 37 | +``` |
| 38 | +
|
| 39 | +### Configuration Options |
| 40 | +
|
| 41 | +- `enabled`: Set to `true` to enable PDF generation, `false` to disable |
| 42 | +- `collections`: Array of collection names to generate PDFs for (PDF filename will be `{collection-name}.pdf`) |
| 43 | +- `guides`: Array of guide configurations with: |
| 44 | + - `name`: Display name for the guide |
| 45 | + - `collection`: Collection name to generate PDF from |
| 46 | + - `filename`: Output PDF filename (optional, defaults to `{name}.pdf`) |
| 47 | + - `start_page`: Optional URL or path to start from (for partial guides) |
| 48 | + |
| 49 | +## How It Works |
| 50 | + |
| 51 | +1. During Jekyll build, the PDF generator plugin identifies configured collections/guides |
| 52 | +2. After all pages are rendered, the plugin collects the rendered HTML content |
| 53 | +3. HTML is cleaned and formatted for PDF output |
| 54 | +4. PDFs are generated using Grover (Puppeteer-based PDF generation) |
| 55 | +5. PDFs are saved to `_site/pdfs/` directory |
| 56 | + |
| 57 | +## Dependencies |
| 58 | + |
| 59 | +- `grover` gem: Ruby wrapper for Puppeteer (requires Node.js and Chrome/Chromium) |
| 60 | +- `puppeteer`: Node.js package (installed automatically by grover) |
| 61 | + |
| 62 | +## Accessing Generated PDFs |
| 63 | + |
| 64 | +Generated PDFs are available at: |
| 65 | +- Local build: `http://localhost:4000/pdfs/{filename}.pdf` |
| 66 | +- Production: `https://docs.opensearch.org/pdfs/{filename}.pdf` |
| 67 | + |
| 68 | +## Troubleshooting |
| 69 | + |
| 70 | +### PDF Generation Fails |
| 71 | + |
| 72 | +1. Ensure `grover` gem is installed: `bundle install` |
| 73 | +2. Ensure Node.js is installed (required for Puppeteer) |
| 74 | +3. Check Jekyll build logs for error messages |
| 75 | +4. Verify collection names in configuration match actual collection names |
| 76 | + |
| 77 | +### PDF Content Issues |
| 78 | + |
| 79 | +- The plugin automatically extracts main content and removes navigation elements |
| 80 | +- If content is missing, check that documents have `title` and are not excluded with `nav_exclude: true` |
| 81 | +- Documents are sorted by `nav_order` if available |
| 82 | + |
| 83 | +## Customization |
| 84 | + |
| 85 | +PDF styling can be customized by modifying the `pdf_styles` method in `pdf_generator.rb`. |
| 86 | + |
| 87 | +PDF options (page size, margins, headers/footers) can be customized in the `pdf_options` method. |
| 88 | + |
0 commit comments