Skip to content

Commit d5e3c77

Browse files
committed
Updating documentation scripts to convert md to pdf
1 parent a9cd0d7 commit d5e3c77

File tree

18 files changed

+315
-649
lines changed

18 files changed

+315
-649
lines changed

gh_pages/assets/pdf-template/template.tex

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,24 @@
22
\documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$babel-lang$,$endif$$if(papersize)$$papersize$paper,$endif$$for(classoption)$$classoption$$sep$,$endfor$]{$documentclass$}
33

44
% Packages
5-
\usepackage{lmodern}
65
\usepackage{amssymb,amsmath}
76
\usepackage{ifxetex,ifluatex}
8-
\usepackage{fixltx2e}
9-
\usepackage[T1]{fontenc}
10-
\usepackage[utf8]{inputenc}
7+
8+
% Font setup for XeLaTeX/LuaLaTeX vs pdfLaTeX
9+
\ifxetex
10+
\usepackage{fontspec}
11+
\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
12+
\else
13+
\ifluatex
14+
\usepackage{fontspec}
15+
\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
16+
\else
17+
\usepackage{lmodern}
18+
\usepackage[T1]{fontenc}
19+
\usepackage[utf8]{inputenc}
20+
\fi
21+
\fi
22+
1123
\usepackage{microtype}
1224
\usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry}
1325
\usepackage{hyperref}
70.5 KB
Binary file not shown.
10.9 KB
Binary file not shown.

gh_pages/assets/pdf/hmi-usage.pdf

23 KB
Binary file not shown.

gh_pages/assets/pdf/plc-usage.pdf

19.5 KB
Binary file not shown.
22.3 KB
Binary file not shown.

tcpkg/README.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,43 @@ tcpkg/
2020
│ ├── BUILD_INSTRUCTIONS.md
2121
│ └── QUICK_REFERENCE.txt
2222
├── Build.ps1 # Convenience wrapper (run from here)
23-
└── Build.bat # Convenience wrapper (double-click)
23+
├── Build.bat # Convenience wrapper (double-click)
24+
└── convert_to_pdf.py # Generate documentation PDFs (Python)
2425
```
2526

2627
## Quick Start
2728

28-
### Option 1: PowerShell (Recommended)
29+
### Build TwinCAT Packages
30+
31+
#### Option 1: PowerShell (Recommended)
2932
```powershell
3033
.\Build.ps1 -CleanBuild
3134
```
3235

33-
### Option 2: Batch File
36+
#### Option 2: Batch File
3437
Double-click `Build.bat`
3538

36-
### Option 3: From Scripts Directory
39+
#### Option 3: From Scripts Directory
3740
```powershell
3841
cd scripts
3942
.\Build-TcPackages.ps1 -CleanBuild
4043
```
4144

45+
### Generate Documentation PDFs
46+
47+
To generate PDF documentation from the markdown files:
48+
49+
```bash
50+
python convert_to_pdf.py
51+
```
52+
53+
This script:
54+
- Automatically installs required Python packages (markdown, weasyprint)
55+
- Converts all markdown files from `gh_pages\_docs\` to PDFs
56+
- Outputs individual PDFs to `packages\EventvideoPlayback.Documentation\bin\`
57+
- Creates a combined `complete-documentation.pdf` with all documentation
58+
- No external dependencies needed (no LaTeX or pandoc required!)
59+
4260
## Adding New Packages
4361

4462
To add a new package to the build:
@@ -75,10 +93,17 @@ For complete documentation, see:
7593

7694
## Requirements
7795

96+
### For Building TwinCAT Packages
7897
- TwinCAT tcpkg tool (installed with TwinCAT XAE)
7998
- PowerShell 5.1 or higher
8099
- Windows 10/11
81100

101+
### For PDF Generation (Optional)
102+
- Python 3.6+
103+
- Python packages (automatically installed by script):
104+
- `markdown` - Markdown parser
105+
- `xhtml2pdf` - HTML to PDF converter (pure Python, no external dependencies)
106+
82107
## Support
83108

84109
For issues or questions, review the documentation in the `scripts/` directory or check the console output for specific error messages.

tcpkg/convert_to_pdf.py

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
#!/usr/bin/env python3
2+
"""Convert markdown documentation to PDF using Python libraries"""
3+
4+
import sys
5+
import os
6+
from pathlib import Path
7+
8+
# Force UTF-8 encoding for console output on Windows
9+
if sys.platform == 'win32':
10+
sys.stdout.reconfigure(encoding='utf-8')
11+
sys.stderr.reconfigure(encoding='utf-8')
12+
13+
def check_dependencies():
14+
"""Check if required packages are installed"""
15+
try:
16+
import markdown
17+
except ImportError:
18+
print("Installing required package: markdown...")
19+
import subprocess
20+
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'markdown'])
21+
import markdown
22+
23+
try:
24+
import xhtml2pdf
25+
except ImportError:
26+
print("Installing required package: xhtml2pdf...")
27+
import subprocess
28+
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'xhtml2pdf'])
29+
import xhtml2pdf
30+
31+
return True
32+
33+
def markdown_to_html(md_content, title="Documentation"):
34+
"""Convert markdown to HTML with styling"""
35+
import markdown
36+
37+
# Convert markdown to HTML
38+
md = markdown.Markdown(extensions=[
39+
'extra',
40+
'codehilite',
41+
'toc',
42+
'tables',
43+
'fenced_code'
44+
])
45+
html_content = md.convert(md_content)
46+
47+
# Create full HTML document with CSS
48+
html = f"""
49+
<!DOCTYPE html>
50+
<html>
51+
<head>
52+
<meta charset="utf-8">
53+
<title>{title}</title>
54+
<style>
55+
@page {{
56+
size: letter;
57+
margin: 1in;
58+
}}
59+
body {{
60+
font-family: Arial, sans-serif;
61+
line-height: 1.6;
62+
color: #333;
63+
max-width: 100%;
64+
}}
65+
h1, h2, h3, h4, h5, h6 {{
66+
color: #d32f2f;
67+
margin-top: 1.5em;
68+
margin-bottom: 0.5em;
69+
}}
70+
h1 {{
71+
font-size: 2em;
72+
border-bottom: 2px solid #d32f2f;
73+
padding-bottom: 0.3em;
74+
}}
75+
h2 {{
76+
font-size: 1.5em;
77+
}}
78+
code {{
79+
background-color: #f5f5f5;
80+
padding: 2px 4px;
81+
border-radius: 3px;
82+
font-family: 'Courier New', monospace;
83+
font-size: 0.9em;
84+
}}
85+
pre {{
86+
background-color: #f5f5f5;
87+
padding: 10px;
88+
border-left: 3px solid #d32f2f;
89+
overflow-x: auto;
90+
border-radius: 3px;
91+
}}
92+
pre code {{
93+
background-color: transparent;
94+
padding: 0;
95+
}}
96+
table {{
97+
border-collapse: collapse;
98+
width: 100%;
99+
margin: 1em 0;
100+
}}
101+
th, td {{
102+
border: 1px solid #ddd;
103+
padding: 8px;
104+
text-align: left;
105+
}}
106+
th {{
107+
background-color: #d32f2f;
108+
color: white;
109+
}}
110+
tr:nth-child(even) {{
111+
background-color: #f9f9f9;
112+
}}
113+
a {{
114+
color: #d32f2f;
115+
text-decoration: none;
116+
}}
117+
a:hover {{
118+
text-decoration: underline;
119+
}}
120+
blockquote {{
121+
border-left: 4px solid #d32f2f;
122+
padding-left: 1em;
123+
margin-left: 0;
124+
color: #666;
125+
}}
126+
.toc {{
127+
background-color: #f9f9f9;
128+
border: 1px solid #ddd;
129+
padding: 1em;
130+
margin-bottom: 2em;
131+
}}
132+
</style>
133+
</head>
134+
<body>
135+
{html_content}
136+
</body>
137+
</html>
138+
"""
139+
return html
140+
141+
def convert_md_to_pdf(md_file, output_file):
142+
"""Convert a single markdown file to PDF"""
143+
from xhtml2pdf import pisa
144+
145+
# Read markdown file
146+
with open(md_file, 'r', encoding='utf-8') as f:
147+
md_content = f.read()
148+
149+
# Get title from filename
150+
title = md_file.stem.replace('-', ' ').replace('_', ' ').title()
151+
title = f"Event Video Playback - {title}"
152+
153+
# Convert to HTML
154+
html = markdown_to_html(md_content, title)
155+
156+
# Convert HTML to PDF
157+
with open(output_file, 'wb') as pdf_file:
158+
pisa_status = pisa.CreatePDF(html, dest=pdf_file)
159+
160+
if pisa_status.err:
161+
raise Exception(f"PDF generation failed with {pisa_status.err} errors")
162+
163+
def main():
164+
"""Main function"""
165+
# Check dependencies
166+
print("Checking dependencies...")
167+
if not check_dependencies():
168+
return 1
169+
170+
print("✓ All dependencies installed\n")
171+
172+
# Set paths
173+
script_dir = Path(__file__).parent
174+
project_root = script_dir.parent
175+
docs_dir = project_root / 'gh_pages' / '_docs'
176+
output_dir = script_dir / 'packages' / 'EventvideoPlayback.Documentation' / 'bin'
177+
178+
# Verify input directory exists
179+
if not docs_dir.exists():
180+
print(f"✗ Documentation directory not found: {docs_dir}")
181+
return 1
182+
183+
# Create output directory
184+
output_dir.mkdir(parents=True, exist_ok=True)
185+
186+
# Get all markdown files
187+
md_files = sorted(docs_dir.glob('*.md'))
188+
189+
if not md_files:
190+
print(f"✗ No markdown files found in {docs_dir}")
191+
return 1
192+
193+
print(f"Found {len(md_files)} markdown files")
194+
print(f"Output directory: {output_dir}\n")
195+
196+
success = 0
197+
failed = 0
198+
199+
# Convert each file
200+
for md_file in md_files:
201+
pdf_name = md_file.stem + '.pdf'
202+
pdf_path = output_dir / pdf_name
203+
204+
print(f"Converting {md_file.name}...", end=' ')
205+
206+
try:
207+
convert_md_to_pdf(md_file, pdf_path)
208+
print("✓")
209+
success += 1
210+
except Exception as e:
211+
print(f"✗ {e}")
212+
failed += 1
213+
214+
# Create combined PDF
215+
print(f"\nCreating combined PDF...", end=' ')
216+
try:
217+
from xhtml2pdf import pisa
218+
219+
# Combine all markdown content
220+
combined_content = []
221+
for md_file in md_files:
222+
with open(md_file, 'r', encoding='utf-8') as f:
223+
content = f.read()
224+
# Add a page break between documents
225+
combined_content.append(content)
226+
combined_content.append("\n\n---\n\n")
227+
228+
# Convert to HTML
229+
html = markdown_to_html(''.join(combined_content), "Event Video Playback - Complete Documentation")
230+
231+
# Convert to PDF
232+
combined_path = output_dir / 'complete-documentation.pdf'
233+
with open(combined_path, 'wb') as pdf_file:
234+
pisa_status = pisa.CreatePDF(html, dest=pdf_file)
235+
236+
if pisa_status.err:
237+
raise Exception(f"PDF generation failed with {pisa_status.err} errors")
238+
239+
print("✓")
240+
success += 1
241+
except Exception as e:
242+
print(f"✗ {e}")
243+
failed += 1
244+
245+
# Summary
246+
print(f"\n{'='*40}")
247+
print(f"Success: {success}, Failed: {failed}")
248+
print(f"{'='*40}")
249+
250+
if failed == 0:
251+
print("\n✓ All PDFs generated successfully!")
252+
print(f"Output: {output_dir}")
253+
254+
return 0 if failed == 0 else 1
255+
256+
if __name__ == '__main__':
257+
sys.exit(main())

tcpkg/packages/EventVideoPlayback.XAE/EventVideoPlayback.XAE.Workload.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
33
<metadata>
44
<id>Beckhoff-USA-Community.EventVideoPlayback.XAE</id>
5-
<version>2.0.0</version>
5+
<version>2.0.1</version>
66
<title>Event Video Playback</title>
77
<authors>Beckhoff Automation LLC</authors>
88
<requireLicenseAcceptance>true</requireLicenseAcceptance>
@@ -21,7 +21,7 @@
2121
<dependencies>
2222
<dependency id="Beckhoff-USA-Community.XAE.HMI.EventVisionControl" version="1.1.3" />
2323
<dependency id="Beckhoff-USA-Community.XAE.PLC.Lib.EventVideoPlayback" version="1.1.1" />
24-
<dependency id="Beckhoff-USA-Community.XAE.Documentation.EventVideoPlayback" version="2.0.0" />
24+
<dependency id="Beckhoff-USA-Community.XAE.Documentation.EventVideoPlayback" version="2.0.1" />
2525
</dependencies>
2626
</metadata>
2727
<files>

tcpkg/packages/EventvideoPlayback.Documentation/EventVideoPlayback.Documentation.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
33
<metadata>
44
<id>Beckhoff-USA-Community.XAE.Documentation.EventVideoPlayback</id>
5-
<version>2.0.0</version>
5+
<version>2.0.1</version>
66
<title>Event Video Playback Documentation</title>
77
<authors>Beckhoff Automation LLC</authors>
88
<projectUrl>https://github.com/Beckhoff-USA-Community/EventVideoPlayback</projectUrl>
@@ -13,7 +13,7 @@
1313
<readme>docs/README.md</readme>
1414
<summary>Documentation and examples for EventVideoPlayback system</summary>
1515
<tags>Beckhoff TwinCAT</tags>
16-
<releaseNotes>Version 2.0.0 - Complete documentation for EventVideoPlayback 2.0 release</releaseNotes>
16+
<releaseNotes>Version 2.0.1 - Complete documentation for EventVideoPlayback 2.0 release</releaseNotes>
1717
<description>EventVideoPlayback Documentation Package - Comprehensive documentation for the EventVideoPlayback system including installation guides, usage instructions, system requirements, and service documentation.</description>
1818
</metadata>
1919
<files>

0 commit comments

Comments
 (0)