D2L Document Generation
D2L Document Generation#
Python-based system to generate professional, WCAG AAA-compliant PDFs and DOCX files from course content for Brightspace (D2L) upload.
Features#
- π Dual-path generation β PDFs via Typst (beautiful), DOCXs via Pandoc (editable)
- π― Flexible modes β Combined or individual files per content item
- β WCAG AAA compliant β Both formats meet accessibility standards
- π¨ Professional styling β MSU green branding template
- π Multiple content types β Readings, assignments, resources, docs
- π Batch processing β Generate all at once or by type
Quick Start#
Generate readings as PDF + DOCX#
cd /path/to/repo
source venv/bin/activate.fish
python scripts/generate-d2l-docs.py --type readings --format both
Output:
output/d2l/readings.pdfβ Beautiful, paginated (346 KB)output/d2l/readings.docxβ Editable in Word (21 KB)
Generate individual files#
python scripts/generate-d2l-docs.py --type assignments --individual --format both
Output:
output/d2l/assignment-01.pdf+.docxoutput/d2l/assignment-02.pdf+.docx- … (one pair per file)
Setup#
Prerequisites#
Virtual environment (one-time setup):
python3 -m venv venv source venv/bin/activate.fish pip install python-frontmatter markdown pyyaml pypandocTypst (for PDF generation):
brew install typstPandoc (for DOCX generation):
brew install pandoc
Verify Installation#
typst --version
pandoc --version
python --version
Usage#
Command Syntax#
python scripts/generate-d2l-docs.py [OPTIONS]
Options#
| Option | Values | Default | Description |
|---|---|---|---|
--type | readings, assignments, resources, docs, all | all | Content type |
--format | pdf, docx, both | pdf | Output format |
--individual | (flag) | combined | Separate files per item |
Common Examples#
Combined documents#
# All readings as one PDF
python scripts/generate-d2l-docs.py --type readings
# All content in both formats
python scripts/generate-d2l-docs.py --format both
# Assignments as combined PDF + DOCX
python scripts/generate-d2l-docs.py --type assignments --format both
Individual documents#
# Each reading separate
python scripts/generate-d2l-docs.py --type readings --individual
# Each resource in both formats
python scripts/generate-d2l-docs.py --type resources --individual --format both
# All content as individual files
python scripts/generate-d2l-docs.py --individual --format both
Specific types#
# Syllabus and docs only
python scripts/generate-d2l-docs.py --type docs --format both
# Resources only
python scripts/generate-d2l-docs.py --type resources --individual
Accessibility & Compliance#
PDF (Typst-generated)#
β WCAG AAA Compliant:
- Color contrast: 7:1+ minimum
- Body text: 17.4:1 β
- Headings: 10.75:1 β
- Footer: 8.06:1 β
- Proper heading hierarchy (h1 β h2 β h3)
- Readable fonts (11pt Roboto)
- Optimized spacing (0.7em leading)
DOCX (Pandoc-generated)#
β Native Accessibility:
- Semantic structure preserved
- Heading tags for screen readers
- Editable in Microsoft Word
- Supports annotations
- Cross-platform compatible
Output Structure#
Files are saved to: output/d2l/
Combined mode#
output/d2l/
βββ readings.pdf # All readings
βββ readings.docx
βββ assignments.pdf
βββ assignments.docx
βββ resources.pdf
βββ resources.docx
βββ docs.pdf
Individual mode#
output/d2l/
βββ week-01.pdf # One per item
βββ week-01.docx
βββ week-02.pdf
βββ week-02.docx
βββ assignment-01.pdf
βββ assignment-01.docx
βββ ...
Content Requirements#
Files need frontmatter:
---
title: "Week 1: Introduction"
weight: 1
---
# Main heading
Your markdown content...
titleβ Used as document headingweightβ Sort order (lower = earlier)- Content β Standard markdown
File Structure#
content/
βββ readings/ # Weekly readings
β βββ week-01.md
β βββ week-02.md
β βββ ...
βββ assignments/ # Assignments
β βββ assignment-01.md
β βββ ...
βββ resources/ # Additional resources
β βββ ...
βββ docs/ # Syllabus, guides, etc.
βββ ...
D2L Upload Guide#
PDF Method (Recommended)#
- In D2L, go to Content > Learning Materials
- Upload
readings.pdf,assignments.pdf, etc. - Students download and view in PDF reader
- β Maintains formatting
- β Accessible on all devices
- β Offline readable
DOCX Method (For Editing)#
- Upload
.docxfile to Brightspace - Students download and edit in Word
- β Can add annotations
- β Can customize formatting
- β Offline access
Hybrid Approach (Best)#
- Post PDF for reading
- Include DOCX link for students who prefer Word
- β Covers all accessibility needs
- β Covers all device preferences
File Naming#
Script uses Hugo filename as output name:
| Source | Output (Combined) | Output (Individual) |
|---|---|---|
content/readings/week-01.md | readings.pdf | week-01.pdf |
content/assignments/project-a.md | assignments.pdf | project-a.pdf |
Troubleshooting#
typst: command not found#
Install Typst:
brew install typst
typst --version
pandoc: command not found#
Install Pandoc:
brew install pandoc
pandoc --version
Empty output directory#
Check content exists:
ls -la content/readings/ ls -la content/assignments/Ensure files have
title:in frontmatterCheck script can find template:
ls -la templates/typst/clean/template.typ
DOCX looks plain#
This is intentional β minimal styling ensures cross-platform compatibility. You can:
- Use PDF version for rich formatting
- Edit DOCX in Word to add styles
- Create custom reference document
PDF font rendering issues#
# Clear cache
rm -rf output/d2l/*.typ
# Regenerate
python scripts/generate-d2l-docs.py --type readings --format pdf
Performance#
Approximate generation times:
| Task | Time |
|---|---|
| Single reading PDF | 2-3 seconds |
| Combined readings (12 files) | 3-5 seconds |
| Single DOCX | 1-2 seconds |
| Full regenerate (all types, both) | 30-60 seconds |
Automation#
Shell Script#
# Create scripts/regenerate-d2l.sh
cat > scripts/regenerate-d2l.sh << 'EOF'
#!/bin/bash
cd "$(dirname "$0")/.."
source venv/bin/activate.fish
python scripts/generate-d2l-docs.py --format both
echo "β
D2L documents regenerated"
EOF
chmod +x scripts/regenerate-d2l.sh
./scripts/regenerate-d2l.sh
CI/CD Pipeline#
Add to your GitHub Actions workflow:
- name: Generate D2L Documents
run: |
source venv/bin/activate
python scripts/generate-d2l-docs.py --format both
Advanced: Custom DOCX Template#
Create a reference document for custom styling:
# Generate default reference
pandoc -o output/d2l/reference.docx --print-default-data-file reference.docx
# Edit reference.docx with Word styles
# Save as output/d2l/reference.docx
# Script automatically uses it
Template Customization#
Edit templates/typst/clean/template.typ to customize PDFs:
- Font: Change from Roboto to any system font
- Colors: Modify MSU green or text colors
- Margins: Adjust page margins
- Heading sizes: Increase/decrease heading sizes
See Template Guide for details.
Maintenance#
Update Template#
# Edit template
nano templates/typst/clean/template.typ
# Regenerate documents
python scripts/generate-d2l-docs.py --format both
# Commit changes
git add templates/
git commit -m "Update PDF template styling"
Add New Content Type#
Edit scripts/generate-d2l-docs.py:
types_to_process = ['readings', 'assignments', 'resources', 'docs', 'new-type']
Then run script with --type new-type.
Key Features Explained#
Dual-Path Generation#
Why two different tools?
- Typst β Beautiful PDFs with professional typography
- Pandoc β Direct markdownβDOCX with native Word compatibility
This gives you:
- β Professional PDFs for distribution
- β Editable DOCXs for student work
Combined vs Individual#
Combined: All readings in one PDF
- β Single file to manage
- β Harder to organize updates
Individual: One PDF per reading
- β Easy to update one section
- β Student downloads only what needed
- β More files to manage
Use case: Combined for printing, individual for online.
Format Options#
PDF only:
- Fast generation
- Beautiful output
- Read-only
DOCX only:
- Fast generation
- Editable
- Native Word format
Both:
- Complete flexibility
- Students choose format
- Slightly longer generation
Related Documentation#
- See System Overview for architecture
- See Accessibility Features for compliance
- See Template Guide for PDF customization
Support#
Common Questions#
Q: Can I customize the PDF styling?
A: Yes! Edit templates/typst/clean/template.typ
Q: Can students edit the PDF?
A: No, use DOCX format for editing. Or use bothβlet students choose.
Q: How do I update one assignment?
A: Edit the markdown file, regenerate with --type assignments --individual
Q: Can I automate regeneration?
A: Yes, use the shell script or CI/CD pipeline approach
Q: How big are the files?
A: PDFs: 150-350 KB, DOCXs: 10-50 KB per document
Last Updated: May 2026
Status: Production ready
Accessibility: WCAG AAA compliant