Skip to content

Optimize PDF generation with compression and complete metadata - #172

Merged
makr-code merged 8 commits into
mainfrom
copilot/fix-pdf-internal-links
Dec 29, 2025
Merged

makr-code merged 8 commits into
mainfrom
copilot/fix-pdf-internal-links

Conversation

Copilot AI commented Dec 29, 2025 •

Copy link
Copy Markdown
Contributor

User reported PDF lacks internal links and file size is 13MB for text content. Investigation revealed:

  1. PDF already contains 39+ bookmarks and internal hyperlinks - visibility issue with PDF viewer settings
  2. File bloat from ~4,000 embedded Material theme SVG icons (26 per page × 152 pages)

Changes

PDF Optimization Scripts

  • scripts/optimize_pdf.sh - Ghostscript-based compression (image resampling, font subsetting, duplicate removal)
  • scripts/build_compendium_pdf.sh - Automated build pipeline with verification
  • scripts/verify_pdf.py - Validates PDF structure (pages, bookmarks, links)

Size Reduction Infrastructure

  • styles_pdf_optimization.scss - CSS to hide decorative elements (icons, navigation, badges) during PDF generation
  • Updated mkdocs-compendium.yml configs with custom_template_path for future SCSS compilation

Documentation

  • docs/PDF_OPTIMIZATION_GUIDE.md - Technical details, mkdocs-with-pdf configuration, optimization strategies
  • docs/PDF_ANTWORT_DE.md - German user guide for opening bookmark panels in various PDF viewers
  • docs/PDF_BUILD_NOTES.md - Build process lessons learned, SCSS compilation requirements

Results

Generated new Kompendium with aggressive Ghostscript optimization and complete metadata:

  • Size: 13.8 MB → 12.92 MB (7% reduction)
  • Structure: 152 pages, 39+ bookmarks, internal links verified
  • Internal Compression: UseFlateCompression enabled for maximum compression
  • Complete Metadata: All PDF fields populated (Title, Author, Subject, Keywords, Creator, Producer, dates)
  • Portable file size calculation using wc -c instead of platform-specific stat

PDF Metadata Added:

  • Title: ThemisDB - Das vollstaendige Handbuch
  • Author: ThemisDB Team
  • Subject: Umfassendes Kompendium fuer ThemisDB v1.3.4
  • Keywords: ThemisDB, Multi-Model Database, Graph Database, Vector Search, Document Store, Time Series, AQL, NoSQL, Enterprise Database, Kompendium, Handbuch, Datenbank
  • Creator/Producer info with version details
  • Creation and modification timestamps

CSS optimization requires SCSS compilation for full effect (expected 60-80% reduction to 2-5 MB). Infrastructure is in place for future implementation.

# Build optimized PDF
./scripts/build_compendium_pdf.sh

# Or optimize existing PDF
./scripts/optimize_pdf.sh input.pdf output.pdf
Original prompt

This section details on the original issue you should resolve

<issue_title>@copilot warum hat das PDF keine internen Links? Warum ist das File 13MB groß wenn es nur text enthält?</issue_title>
<issue_description>@copilot warum hat das PDF keine internen Links? Warum ist das File 13MB groß wenn es nur text enthält?

Originally posted by @makr-code in #170 (comment)

warum hat das PDF keine internen Links? Warum ist das File 13MB groß wenn es nur text enthält?</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 5 commits December 29, 2025 09:47
- Add custom CSS to hide decorative elements in PDF
- Create Ghostscript optimization script
- Add automated build script with optimization
- Add comprehensive PDF optimization guide
- Update mkdocs config to use custom styles
- Expected 60-80% file size reduction (13MB -> 2-5MB)
- PDF already has internal links/bookmarks (verified)

Co-authored-by: makr-code <[email protected]>
- Add PDF_ANTWORT_DE.md explaining the issues in German
- Verify Ghostscript optimization works correctly
- Test shows 7% reduction on existing PDF
- Expect 60-80% reduction with CSS optimizations on new build
- All bookmarks and internal links preserved after optimization

Co-authored-by: makr-code <[email protected]>
- Fix leftover debugging code in build script
- Add error handling for cross-platform file size detection
- Extract PDF verification into separate Python script
- Fix missing import in documentation example
- Improve maintainability and error handling

Co-authored-by: makr-code <[email protected]>
- Rebuild ThemisDB Kompendium with current documentation
- Apply Ghostscript optimization (7% size reduction)
- Verify all bookmarks and links preserved
- Add build notes documenting lessons learned
- PDF size: 13.80 MB -> 12.93 MB
- All 152 pages, 39 bookmarks, internal links intact
- Note: CSS optimization needs SCSS compilation for full effect

Co-authored-by: makr-code <[email protected]>
- Clarify bookmark counting is top-level only (add + symbol)
- Use portable wc -c for file size calculation instead of stat
- Fix SVG selector to properly exclude Mermaid diagrams
- Add sync notes to duplicate style files
- Improve robustness across platforms

Co-authored-by: makr-code <[email protected]>
Copilot AI changed the title [WIP] Fix internal links and optimize PDF file size Optimize PDF generation and clarify bookmark visibility Dec 29, 2025
Copilot AI requested a review from makr-code December 29, 2025 10:08
@makr-code

Copy link
Copy Markdown
Owner

@copilot okay weiter

Copilot AI and others added 2 commits December 29, 2025 10:12
- Apply Ghostscript with UseFlateCompression and aggressive settings
- Replace main PDF with fully compressed version (12.92 MB)
- Remove duplicate optimized PDF file
- All 152 pages, 39+ bookmarks, internal links verified and working
- Internal compression maximized with ebook quality settings

Co-authored-by: makr-code <[email protected]>
- Add Title: ThemisDB - Das vollstaendige Handbuch
- Add Subject: Umfassendes Kompendium fuer ThemisDB v1.3.4
- Add Author: ThemisDB Team
- Add Keywords: ThemisDB, Multi-Model Database, Graph Database, Vector Search, Document Store, Time Series, AQL, NoSQL, Enterprise, Kompendium
- Add Creator: mkdocs tools version info
- Add Producer: Ghostscript with optimization info
- Add CreationDate and ModDate
- All metadata fields properly filled using pdfmarks
- Maintains 152 pages, 39+ bookmarks, internal links (12.92 MB)

Co-authored-by: makr-code <[email protected]>

Copilot AI commented Dec 29, 2025

Copy link
Copy Markdown
Contributor Author

@copilot okay weiter

✅ Erledigt! Das PDF wurde optimiert:

Änderungen (Commit 79ee3d4):

  • ✅ Komprimiertes PDF verwendet (12.92 MB)
  • ✅ Aggressive interne Komprimierung (UseFlateCompression)
  • ✅ Vollständige Metadaten hinzugefügt:
    • Title: ThemisDB - Das vollstaendige Handbuch
    • Author: ThemisDB Team
    • Keywords: ThemisDB, Multi-Model Database, Graph Database, Vector Search, etc.
    • Creator, Producer, Datum-Felder

Alle 152 Seiten, 39+ Lesezeichen und interne Links bleiben erhalten.

Copilot AI changed the title Optimize PDF generation and clarify bookmark visibility Optimize PDF generation with compression and complete metadata Dec 29, 2025
@makr-code
makr-code marked this pull request as ready for review December 29, 2025 10:17
@makr-code
makr-code merged commit 7171917 into main Dec 29, 2025
@makr-code makr-code modified the milestones: v1.0.2, v1.3.2 Mar 11, 2026
Copilot AI added a commit that referenced this pull request May 11, 2026
…HMAC/embedding stubs

- GGUFMetadata (stub #259): add HmacFn type alias + setHmacFn() static API;
  sign()/verify() delegate to injected fn when set, fall back to XOR stub;
  fail-closed on fn exception; source comments updated from #173 → #259

- FlareRetrieval (stub #260): add EmbeddingQueryFn type alias + setEmbeddingQueryFn()
  static API + buildQueryEmbedding() method; string buildQuery() path retained
  as documented fallback; fail-closed on fn exception

- TensorRAGPipeline (stub #261): add EmbeddingQueryFn + setEmbeddingQueryFn()
  static API; step() populates RAGDecision::flare_query_embedding when fn set
  and FLARE triggers; fail-closed on fn exception

- STUB_INVENTORY.md: 21 new entries (#259–#277, with #263 as a/b/c subtypes);
  header updated to 272 entries / 238 resolved / 34 active; source ID conflicts
  for AR-01 (#172→#265), AR-02 (#177→#266), mmap-bridge (#176→#270),
  fingerprint-graph (#174→#276) noted and source comments updated

- All three bridges follow the gpu_tensor.cpp pattern: static function-local
  mutex + static function-local std::function storage; thread-safe getter/setter

Co-authored-by: Copilot <[email protected]>

Co-authored-by: makr-code <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@copilot warum hat das PDF keine internen Links? Warum ist das File 13MB groß wenn es nur text enthält?

2 participants