Skip to content

Commit a612d05

Browse files
committed
[DOC] Downloadable PDF Developer Guides
Signed-off-by: Arya Soni <[email protected]>
1 parent 38ed6ec commit a612d05

File tree

5 files changed

+696
-0
lines changed

5 files changed

+696
-0
lines changed

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ gem 'typhoeus'
4747
gem 'activesupport', '~> 7'
4848
gem 'mustache', '~> 1'
4949

50+
# PDF Generator
51+
gem 'grover', '~> 1.3'
52+
5053
group :development, :test do
5154
gem 'rspec'
5255
gem 'rubocop', '~> 1.44', require: false

_config.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,36 @@ plugins:
329329
- jekyll-redirect-from
330330
- jekyll-sitemap
331331
- jekyll-spec-insert
332+
- pdf_generator_loader
332333

333334
# This format has to conform to RFC822
334335
last-modified-at:
335336
date-format: '%a, %d %b %Y %H:%M:%S %z'
336337

338+
# PDF Generator Configuration
339+
pdf_generator:
340+
enabled: true
341+
# Generate PDFs for entire collections
342+
collections:
343+
- getting-started
344+
- install-and-configure
345+
- api-reference
346+
- query-dsl
347+
- aggregations
348+
- mappings
349+
- analyzers
350+
# Generate PDFs for specific guides (more granular control)
351+
guides:
352+
- name: "Getting Started Guide"
353+
collection: getting-started
354+
filename: "getting-started-guide.pdf"
355+
- name: "Installation Guide"
356+
collection: install-and-configure
357+
filename: "installation-guide.pdf"
358+
- name: "API Reference"
359+
collection: api-reference
360+
filename: "api-reference.pdf"
361+
337362
# Exclude from processing.
338363
# The following items will not be processed, by default. Create a custom list
339364
# to override the default setting.

_pdf_generator/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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

Comments
 (0)