File tree Expand file tree Collapse file tree 12 files changed +77
-15
lines changed
Expand file tree Collapse file tree 12 files changed +77
-15
lines changed Original file line number Diff line number Diff line change @@ -2,5 +2,10 @@ title: "Custom Location Example"
22description : " This page uses custom directory structure"
33template :
44 # If you just wrote this directly it would be relative to the templates directory
5- # We want it to be relative to the config file:
5+ # We want it to be relative to the config file, so use path :
66 path : " ../other_templates/custom_page.svg.j2"
7+ detailed_description :
8+ " This example demonstrates custom file locations in pdfbaker. The template file is in
9+ a custom directory (other_templates/), the page configuration file is in another
10+ custom directory (other_pages/), and the document configuration uses a path-based page
11+ reference with custom location."
Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" UTF-8" standalone =" no" ?>
22<svg width =" 210mm" height =" 297mm" viewBox =" 0 0 210 297" version =" 1.1" >
3- <text x =" 105" y =" 50" text-anchor =" middle" font-size =" 20" >{{ title }}</text >
4- <text x =" 105" y =" 80" text-anchor =" middle" font-size =" 14" >{{ description }}</text >
3+ <!-- Background -->
4+ <rect width =" 210" height =" 297" fill =" #ffffff" />
5+
6+ <!-- Light blue header background -->
7+ <rect x =" 0" y =" 0" width =" 210" height =" 70" fill =" #e0f0ff" />
8+
9+ <!-- Title with smaller font -->
10+ <text x =" 105" y =" 40" text-anchor =" middle" font-family =" Arial" font-size =" 14" font-weight =" bold" >{{ title }}</text >
11+
12+ <!-- Description with smaller font -->
13+ <text x =" 105" y =" 60" text-anchor =" middle" font-family =" Arial" font-size =" 8" >{{ description }}</text >
14+
15+ <!-- Detailed description using wordwrap filter -->
16+ {% for line in detailed_description | wordwrap (45) %}
17+ <text x =" 20" y =" {{ 100 + loop.index0 * 15 }}" font-family =" Arial" font-size =" 8" >{{ line }}</text >
18+ {% endfor %}
519</svg >
Original file line number Diff line number Diff line change 11title : " Standard Location Example"
22subtitle : " This page uses conventional directory structure"
33template : " standard_page.svg.j2"
4+ description :
5+ " This example demonstrates how pdfbaker organizes files with standard locations.
6+ Templates are in the standard templates/ directory, page configuration files are in
7+ the standard pages/ directory, and the document uses simple page references."
Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" UTF-8" standalone =" no" ?>
22<svg width =" 210mm" height =" 297mm" viewBox =" 0 0 210 297" version =" 1.1" >
3- <text x =" 105" y =" 50" text-anchor =" middle" font-size =" 20" >{{ title }}</text >
4- <text x =" 105" y =" 80" text-anchor =" middle" font-size =" 14" >{{ subtitle }}</text >
3+ <!-- Background -->
4+ <rect width =" 210" height =" 297" fill =" #ffffff" />
5+
6+ <!-- Gray header background -->
7+ <rect x =" 0" y =" 0" width =" 210" height =" 70" fill =" #f0f0f0" />
8+
9+ <!-- Title with smaller font -->
10+ <text x =" 105" y =" 40" text-anchor =" middle" font-family =" Arial" font-size =" 14" font-weight =" bold" >{{ title }}</text >
11+
12+ <!-- Subtitle with smaller font -->
13+ <text x =" 105" y =" 60" text-anchor =" middle" font-family =" Arial" font-size =" 8" >{{ subtitle }}</text >
14+
15+ <!-- Description text using wordwrap filter -->
16+ {% for line in description | wordwrap (45) %}
17+ <text x =" 20" y =" {{ 100 + loop.index0 * 15 }}" font-family =" Arial" font-size =" 8" >{{ line }}</text >
18+ {% endfor %}
519</svg >
Original file line number Diff line number Diff line change 77
88from pdfbaker .document import PDFBakerDocument
99from pdfbaker .errors import PDFBakerError
10+ from pdfbaker .processing import wordwrap
1011
1112
1213def process_document (document : PDFBakerDocument ) -> None :
@@ -23,10 +24,15 @@ def process_document(document: PDFBakerDocument) -> None:
2324 f"data:image/png;base64,{ base64 .b64encode (img_data ).decode ('utf-8' )} "
2425 )
2526
26- # Update config with XKCD info
27+ # Get the alt text and split it into lines using the wordwrap function
28+ # Note: This is for demonstration. Could use the wordwrap filter in template.
29+ wrapped_alt_text = wordwrap (data ["alt" ], max_chars = 60 )
30+
31+ # Update config/template context with XKCD info
2732 document .config ["xkcd" ] = {
2833 "title" : data ["title" ],
2934 "alt_text" : data ["alt" ],
35+ "alt_text_lines" : wrapped_alt_text ,
3036 "fetched_at" : datetime .now ().strftime ("%Y-%m-%d %H:%M:%S" ),
3137 "image_data" : image_data ,
3238 }
Original file line number Diff line number Diff line change 1515 <!-- XKCD Image -->
1616 <image x =" 20" y =" 120" width =" 170" height =" 120" xlink:href =" {{ xkcd.image_data }}" />
1717
18- <!-- Alt Text -->
19- <text x =" 105" y =" 260" font-family =" Arial" font-size =" 6" fill =" #666" text-anchor =" middle" >Alt text: {{ xkcd.alt_text }}</text >
18+ <!-- Centered Alt Text (Pre-wrapped in Python) -->
19+ {% for line in xkcd .alt_text_lines %}
20+ <text x =" 105" y =" {{ 260 + loop.index0 * 8 }}" font-family =" Arial" font-size =" 5" fill =" #666" text-anchor =" middle" >{{ line }}</text >
21+ {% endfor %}
2022</svg >
Original file line number Diff line number Diff line change @@ -2,5 +2,5 @@ documents:
22 - minimal
33 - regular
44 - variants
5- - " ./custom_locations/your_directory"
5+ - ./custom_locations/your_directory
66 - custom_processing
Original file line number Diff line number Diff line change @@ -4,4 +4,4 @@ content: |-
44 This is a minimal example of pdfbaker usage.
55 - Single page document
66 - One custom variable (text_color)
7- - Basic SVG template using variable for text color
7+ - Basic SVG template uses variable for styling
Original file line number Diff line number Diff line change 66 - benefits
77style :
88 highlight_color : " #30987c"
9+ header_title : " pdfbaker Example"
Original file line number Diff line number Diff line change @@ -10,5 +10,10 @@ items:
1010 desc : " Same template used by multiple pages"
1111 - title : " Consistent Styling"
1212 desc : " Shared styles across pages"
13+ - title : " Wrapping Long Text"
14+ desc :
15+ " SVG doesn't have text wrapping containers, but pdfbaker lets you store long text
16+ in config and use the wordwrap filter to split it into lines. Adjust max_chars to
17+ fit narrower spaces."
1318images :
1419 - name : pythonnz.png
You can’t perform that action at this time.
0 commit comments