2025 Year of Code: November - PDF

Hi everyone and welcome to month #11, the final month of the 2025 Year of Code! This is the thread to share your November project, which has the theme of PDF. I hope this broad topic leads to tons of fun and creative Xojo projects!

Xojo’s @Gabriel_Ludosanu is starting things off with a fun and practical project: a PDF Postcard Generator. His desktop app allows you to easily design personalized holiday postcards. It’s a fantastic way to see Xojo’s capabilities in handling graphics, file operations, and PDF creation, all within a simple, intuitive interface. What will you do for this final Year of Code Challenge?

More information about this is in the November Year of Code blog post

You can download it from the Github.

Remember: To be entered in the drawings for this month’s prize and the grand prize at the end, you need to share your code, preferably on GitHub. Refer to this blog post if you need help with getting your project on GitHub.

It’s the final month of our Year of Code project and we can’t wait to see your creations!

1 Like

Sudoku Solver & Generator

For the Septgamer Challenge I have created a Sudoku App.
Meanwhile I have added quite some features, one of which is being able to print the Sudoku Puzzle or export it as PDF. And the repository now contains both a Desktop- and a WebApp.

This project shows some of Xojo’s x-platform strengths:

  • The Logic Class SudokuTool is used in both Desktop- and WebApp and available for all Build Platforms macOS/Windows/Linux
  • An instance of this Class represents the current state of the Sudoku Puzzle, and it’s Method .DrawInto(g As Graphics) is used for both Printing and creating a PDF using Xojo’s PDFDocument - for both Desktop- and WebApp, and all Build Targets

While it’s fun and super easy to be able to have a single code base for both Printing and PDF, and for both Desktop- and WebApp, this project has also shown to me that PDFDocument doesn’t seem to be quite production ready (in my humble opinion). Especially when used in a WebApp (running on a headless Linux machine) there are many issues regarding Text, Fonts, Positioning.
Just try yourself and compare the available Desktop- and WebApp. Look at the open source project and contribute to fix the issues - it’s also a good project for Xojo to see what should be improved regarding PDFDocument to make this feature even better.


Sudoku Solver & Generator

Create, generate, or solve Sudoku puzzles

  • Source Code: GitHub: jo-tools/sudoku
    • Download built Binaries → click on Releases on the right-hand side
  • Web Application: https://sudoku.azure.jo-tools.ch
    • Note: WebApp is running on a terribly limited VM, so don’t expect a great performance. It’s also not guaranteed to be online 24/7 or forever - but it should be available for a little while.
    • Fun Fact: Did you notice that you can use the arrow keys to navigate within the Sudoku Grid?
      Find out yourself by looking at the code how that’s been implemented. You’ll see two working approaches in the Commit History: the first “easy one” by me, and the now-current one has been contributed by @Ricardo_Cruz - thanks again :heart:!

ScreenShot

10 Likes

CodeCleaner

I have written a desktop application that reads the files in a folder and generates a summary of unused methods, classes, and properties. It generates s flowchart as a .pdf in a number of formats, but of most use is the complexity mtrix summary in the PDF generated after the code analysis.

:chart_increasing: What the Numbers Mean

Complexity of 5 = Easy to understand, test, and maintain
Complexity of 15 = Getting tricky, consider refactoring
Complexity of 25+ = Hard to maintain, should refactor

There is also a summary of relationships

I used this application to refactor its own code.

The application code can be downloaded from https://github.com/supcumps/CodeCleaner

I have found this application useful, especially when adding methods and refactoring with redundant code lying around. It also helps identify methods that can be refactored. I hope others also find it of benefit.

Phil

10 Likes

Thank you Philip.

Text files probably because the xojo_binary_project are not selectable.

Also, the three images are referenced as .png, and are .xojo_image (or so) in the downloaded zip.

That said, I am still curious to read what my project default(s) it have to correct it/them.

PDF Template Engine and Editor

This project is an approach to separate the design of a PDF file from code instead of writing it completely in XOJO code. it consists of classes to render a PDF document from a text based template file (.ptf). The template defines what to be rendered into the PDF document at what position. Also a visual editor is included to create and edit PDF template files (.ptf).

I’ve started this project a couple of month ago because I needed to dynamically create Invoice documents. I found it hard to design a PDF document in code, because it required me to run the whole project each time I change anything to the document layout. Also I had to redeploy the whole project again after if I fixed a small typo or added a static text to the document. With this project I now can position all elements like static text, images or simple lines on a raster-based page and save the definition of all this elements to a simple text file (the .ptf template file). The template-file will then be used by my invoice app to generate the PDF invoice documents.

This project contains not a fully featured app and framework but it is useable for simple purposes and may be enhanced in the future as need. Currently one can design single page DIN A4 PDF templates using the visual editor and generate PDF documents using the TemplateEngine classes.

Project on github: GitHub - stefanwatermann/XojoPdfTemplateEngine: Classes to render PDF files from a text based template file and a visual editor to design PDF template files.

This is how the visual editor looks like:

And this is how to render the PDF from code and inject parameters that will replace the variables starting with %:

Private Function CreateCustomerInvoice(params as dictionary) As PDFDocument
  Using PdfTemplate
  
  Var pdfSvc As New PdfService
  pdfSvc.Load(Self.PdfTemplateFolder.Child("customerinvoice.ptf"))
  
  Var helper As New PdfHelper
  helper.CreateA4PdfDoc
  helper.DrawElements(pdfSvc.CanvasElements, params)
  
  Return helper.PdfDoc
End Function

There are two projects in the repository, the first one is the visual editor (Desktop App) and the second one is an example Web-App to demonstrate how to use a template file to render a PDF document using the TemplateEngine classes. A sample template file can be found in the Web-App project (customerinvoice.pft).

11 Likes

PDF Manual Generator

Even in 2025 my users want a manual for printing. Because I use a website as manual I made a little project to create a PDF out of the website for each new version.

macOS only and needs MBS plugins!!!

What You Typically Change

1. Default URLs: Modify the `Open` event:

Sub Open()
me.AddRow("https://your-site.com/page1.html")
me.AddRow("https://your-site.com/page2.html")
End Sub

2. PDF title: Change kPDFName.

3. Company metadata: Edit globals.Company.

Limitations

1. A4 Only

Output PDF size is fixed at:

- Width: 595 points

- Height: 842 points

To use a different paper format (e.g., Letter), update:

- kPageWidth

- kPageHeight

2. Website Must Have a Print CSS

The tool prints the webpage as a browser would.

The website must provide a print stylesheet that hides:

- Menus

- Navigation bars

- Headers/footers

- Cookie banners

- Other interface elements

Without a good print CSS, those elements will appear in the PDF.

https://www.mothsoftware.com/downloads/pdfmanualgenerator.zip

3 Likes

I have added parameter complexity analysis to the application I wrote to analyse code in .xojo_code format

Parameter Count Thresholds:

Parameters Status Action
0-3 :white_check_mark: Excellent Ideal range
4-5 :yellow_circle: Acceptable Monitor closely
6-7 :orange_circle: Warning Should refactor
8+ :red_circle: Critical Must refactor

I accidentally tried your app on an xml project with 670 external items and the code had some hang for StringOpsClassic.

Sorry, I haven’t had time to take into account every kind of application. Feel free to extend it however you like.

I complained about the hang and not me being stupid.

@Beatrix: You just do not read the above. (Or do not realize Philip was talking about .xojo_code format

Hi Beatrix, I have always appreciated your comments and would like to know more about the problem you found. Most likely my application can be improved as I often miss areas that cause issues.
Phil

I have now added a section that generates refactoring suggestions.

1. Deep Nesting Detection

  • Method: AnalyzeDeepNesting and CalculateNestingDepth
  • Metric: Counts the maximum nesting level in a method
  • Thresholds:
    • HIGH priority: ≥ 6 levels of nesting
    • MEDIUM priority: 4-5 levels of nesting
  • Examples from your code:
    • DetectFileOperations: 11 levels (HIGH)
    • DetectTypeConversions: 11 levels (HIGH)
    • DetectDatabaseOperations: 10 levels (HIGH)
    • GetMethodMetrics: 4 levels (MEDIUM)

2. Too Many Parameters

  • Method: AnalyzeManyParameters
  • Metric: Counts parameters in method signature
  • Special detection: Identifies ByRef parameters (which suggest the method is doing too much)
  • Thresholds:
    • HIGH priority: > 5 parameters (especially with ByRef)
    • MEDIUM priority: 6 parameters
  • Examples:
    • HandleEndTag: 7 parameters, 6 ByRef (HIGH - critical!)
    • RenderSingleSuggestion: 6 parameters (MEDIUM)

3. High Cyclomatic Complexity

  • Method: AnalyzeHighComplexity with CalculateCyclomaticComplexity
  • Metric: Counts decision points in code:
    • Each If, ElseIf, For, While, Do, Case, And, Or adds +1
    • Base complexity = 1
  • Threshold: Methods with high complexity scores
  • Purpose: Identifies methods that are hard to test and understand

4. Long Methods

  • Method: AnalyzeLongMethod
  • Metric: Counts non-empty lines of code
  • Purpose: Identifies methods that do too much and should be split

5. Missing Error Handling

  • Method: AnalyzeMissingErrorHandling and DetectTryCatchBlocks
  • Detects:
    • Database operations without Try/Catch
    • File operations without error handling
    • Network operations without error handling
    • Type conversions that could fail
  • Priority: Based on risk level of the operation

Analysis Process Flow

  1. Scan project files → Parse all .xojo_code files
  2. Extract code elements → Identify all methods, classes, modules
  3. For each method, run multiple analyzers:
   AnalyzeRefactoringOpportunities(method)
   ├── AnalyzeDeepNesting()
   ├── AnalyzeHighComplexity()
   ├── AnalyzeLongMethod()
   ├── AnalyzeManyParameters()
   └── AnalyzeMissingErrorHandling()
  1. Store suggestions in method.RefactoringSuggestions[]
  2. Deduplicate when displaying or generating reports

Suggestion Structure

Each RefactoringSuggestion contains:

  • Element: Reference to the CodeElement (method)
  • Priority: HIGH | MEDIUM | LOW
  • Category: “Deep Nesting” | “Too Many Parameters” | etc.
  • Title: Short description (e.g., “Deep Nesting (11 levels)”)
  • Description: Explanation of the issue
  • Suggestions[]: Array of actionable recommendations with examples

Key Thresholds Used

Metric Threshold Priority
Nesting Depth ≥ 6 levels HIGH
Nesting Depth 4-5 levels MEDIUM
Parameters > 5 params HIGH (if ByRef present)
Parameters 6 params MEDIUM
ByRef params ≥ 5 ByRef CRITICAL

2 Likes

I have now added an overall score that helps compare versions of code as it is being developed.

5 Likes

I have now added a ‘code smell’ detection, which analyses code and suggests way to imporove it

If anyone has other suggestions for improvement, I am open to having a go.

2 Likes

Just in case it helps, There is now a ‘Hotspot’ display and PDF report that indicates areas that need attention and suggets an intial approach,

1 Like

Made with xojo, no plugin …

Archive.zip (953.6 KB)

This is my entry for november contest:

:bullseye: Xojo FPDF - Pure Xojo PDF Generation with Full Unicode Support

Why Another PDF Library?

If you’ve ever tried to generate PDFs in Xojo with extensive Unicode text (Chinese, Arabic, Hebrew, Mathematical symbols, etc.), you know the challenges. While Xojo’s built-in PDFDocument class works across platforms, it has significant limitations:

:cross_mark: ANSI Encoding Only - No true Unicode support, special characters and CJK languages don’t work properly
:cross_mark: No Font Subsetting - Embeds entire 20MB font files instead of just the glyphs you use (massive file sizes)
:cross_mark: Closed Source - Can’t inspect internals, fix bugs, or extend functionality yourself
:cross_mark: Limited Extensibility - Harder to customize for advanced PDF features

Xojo FPDF changes everything. :rocket:


:glowing_star: What Makes Xojo FPDF Special?

:white_check_mark: Full Unicode Support

// Japanese, Arabic, Hebrew, Mathematical symbols - ALL WORKING!
pdf.AddUTF8Font("Arial", "", "/path/to/ArialUnicode.ttf")
pdf.SetFont("Arial", "", 14)
pdf.Cell(0, 10, "Hello World! 你好世界! مرحبا بالعالم! שלום עולם!")

:white_check_mark: Automatic Font Subsetting

Massive file size savings! Our TrueType font subsetter embeds only the glyphs you actually use:

  • :chart_decreasing: 98% size reduction - 20MB Arial Unicode → 400KB subset
  • :bullseye: Sparse glyph IDs - Preserves original character encoding
  • :high_voltage: Automatic - Happens transparently during font embedding
  • :package: Smaller PDFs - Perfect for web delivery and email

Xojo’s PDFDocument embeds entire font files, bloating your PDFs unnecessarily.

:white_check_mark: 100% Open Source & Pure Xojo

  • No black boxes - Read and modify every line of code
  • No declares - Works everywhere (Desktop, Web, iOS, Console)
  • Community-driven - Contribute features, fix bugs, adapt to your needs
  • Based on proven libraries: go-pdf/fpdf and original PHP FPDF

:white_check_mark: Cross-Platform by Design

One codebase, four platforms:

  • :desktop_computer: Desktop (Mac/Windows/Linux)
  • :globe_with_meridians: Web (Server-side generation)
  • :mobile_phone: iOS (Native mobile PDFs)
  • :gear: Console (Automated workflows)

90%+ shared code across all platforms!


:package: Current Feature Set (v0.3.0)

Core Features

  • :white_check_mark: UTF-8/Unicode - TrueType font support with full Unicode
  • :white_check_mark: Multiple Page Formats - A3, A4, A5, Letter, Legal, Custom sizes
  • :white_check_mark: Text Methods - Cell, MultiCell, Write, Text with alignment
  • :white_check_mark: Graphics Primitives - Line, Rect, Circle, Ellipse, Arc, Bezier curves, Arrows, Polygons
  • :white_check_mark: Image Support - JPEG, PNG (RGB/Grayscale/CMYK), programmatic graphics
  • :white_check_mark: Colors - RGB for text, fill, and draw operations
  • :white_check_mark: Compression - FlateDecode/zlib (27-60% file size reduction, Desktop/Web/Console)
  • :white_check_mark: Links & Bookmarks - Internal links, external URLs, hierarchical outlines
  • :white_check_mark: Header/Footer Callbacks - Automatic page headers and footers
  • :white_check_mark: Metadata - Title, Author, Subject, Keywords, Creator, Language
  • :white_check_mark: PDF/A Compliance - ICC color profiles for archival documents

Advanced Features

  • :white_check_mark: Document Encryption - RC4-40 encryption with password protection (free version)
  • :white_check_mark: PDF Permissions - Print, copy, modify restrictions (free version with RC4-40)
  • :white_check_mark: Custom Page Formats - Define any page dimensions
  • :white_check_mark: Printf-Style Formatting - Cellf(), Writef() with %s/%d/%f
  • :white_check_mark: Font Metrics - GetFontDesc() for precise typography
  • :white_check_mark: Error Accumulation - Go-style error handling (Ok/Err/GetError)

:bullseye: 19 Working Examples

Every feature has a working example that generates a real PDF:

  1. Simple Shapes - Lines, rectangles, circles, Bezier curves, arrows
  2. Text Layouts - Cell, MultiCell, Write with alignment
  3. Multiple Pages - Multi-page documents with various shapes
  4. Line Widths - Different line styles, caps, joins
  5. UTF-8 & TrueType Fonts - Chinese, Arabic, Hebrew, Mathematical symbols
  6. Text Measurement - Precise alignment with GetStringWidth()
  7. Document Metadata - Title, Author, Subject, Keywords
  8. Error Handling - Ok(), Err(), GetError() patterns
  9. Image Support - JPEG, PNG files, programmatically drawn graphics
  10. Header/Footer Callbacks - Automatic headers with page count
  11. Links and Bookmarks - TOC, clickable links, PDF outline
  12. Custom Page Formats - Mixed page sizes in one document
  13. PDF/A Compliance - ICC color profiles for archival
  14. Document Encryption - RC4-40 password protection and permissions (free version)
  15. Watermark Header - Semi-transparent background watermarks
  16. Formatting Features - Printf-style formatters, font metrics
  17. Utility Methods - Version info, unit conversions, page size helpers
  18. Plugin Architecture - Premium feature separation
  19. Table Generation - Professional tables with pagination

All examples generate PDFs you can inspect in pdf_examples/ folder!


:gem_stone: Premium Modules - Coming Soon

Premium modules are ready! We’re finalizing the distribution and licensing system:

:locked_with_key: Encryption Premium (Ready)

Free version includes RC4-40 encryption + permissions. Premium adds:

  • :white_check_mark: AES-256 - Strongest PDF encryption available (Revisions 5-6)
  • :white_check_mark: AES-128 - Modern encryption without Acrobat warnings (Revision 4) - RECOMMENDED
  • :white_check_mark: RC4-128 - Enhanced legacy support (Revision 3)
  • :locked: All encryption levels work with full permission control (print, copy, modify restrictions)

:bar_chart: Table Premium (Ready)

  • :white_check_mark: SimpleTable - Quick equal-width columns
  • :white_check_mark: ImprovedTable - Custom widths, auto number alignment
  • :white_check_mark: FancyTable - Styled headers, alternating rows
  • :white_check_mark: Multi-Page Tables - Auto page breaks with header repetition
  • :white_check_mark: Database Integration - Direct RowSet support from SQLite/PostgreSQL/etc

:clamp: Compression Premium (Ready)

Free version uses system zlib with Declares (Desktop/Web/Console only, iOS blocked)

Premium is 100% pure Xojo code - no declares, works everywhere:

  • :white_check_mark: Pure Xojo Zlib - Complete DEFLATE/INFLATE implementation in Xojo
  • :white_check_mark: iOS Support - Works on iOS where system zlib is blocked by sandboxing
  • :white_check_mark: 60% Smaller PDFs - FlateDecode compression on all platforms
  • :white_check_mark: No Dependencies - No system libraries, no declares, fully portable

:crystal_ball: PDF/A Premium (Planned)

  • Advanced archival features
  • Automatic compliance validation
  • Long-term preservation support

:receipt: E-Invoice Premium (Planned)

  • Factur-X / ZUGFeRD - Hybrid PDF/XML invoices (French/German/EU standard)
  • XML Invoice Embedding - Attach structured XML data to PDF invoices
  • Standards Compliance - EN 16931, PEPPOL, UBL 2.1, CII D16B formats
  • Validation - Automatic invoice structure validation
  • Digital Signatures - Sign embedded invoice data
  • Metadata Extraction - Parse and extract invoice data from hybrid PDFs
  • Multi-Country Support - Adapt to regional e-invoicing requirements

Premium modules are code-complete and fully tested (Encryption, Table, Zlib ready now). E-Invoice and PDF/A modules are in planning phase. We’re currently setting up the distribution and licensing system. Expected availability: soon.

:light_bulb: Important: Premium modules are delivered as full, unencrypted source code - no black boxes, no compiled libraries. After payment, you receive the complete Xojo source code to inspect, modify, and integrate into your projects. Same transparency as the free version!

:money_bag: Flexible Pricing: Purchase Modules Separately - You don’t need to buy all premium modules! Each module (Encryption, Table, Zlib, PDF/A, E-Invoice) can be purchased individually based on your specific needs. Only pay for the features you’ll actually use!

Interested in early access? Contact us through this forum thread to discuss beta testing or early licensing.


:rocket: Quick Start

// Create document
Dim pdf As New VNSPDFDocument(VNSPDFModule.ePageOrientation.Portrait, _
                              VNSPDFModule.ePageUnit.Millimeters, _
                              VNSPDFModule.ePageFormat.A4)

// Add page
pdf.AddPage()

// Set font (core font)
pdf.SetFont("Helvetica", "", 16)

// Output text
pdf.Cell(0, 10, "Hello from Xojo FPDF!")

// Or use Unicode with TrueType font
pdf.AddUTF8Font("Arial", "", "/System/Library/Fonts/Supplemental/Arial Unicode.ttf")
pdf.SetFont("Arial", "", 14)
pdf.Cell(0, 10, "你好世界! مرحبا بالعالم!")

// Save PDF
If pdf.Ok() Then
  Dim f As FolderItem = SpecialFolder.Desktop.Child("output.pdf")
  Call pdf.SaveToFile(f)
Else
  MsgBox "Error: " + pdf.GetError()
End If

:books: Architecture Highlights

Smart Code Sharing

  • All PDF logic in shared PDF_Library/ folder
  • Platform-specific only for file I/O and UI
  • Conditional compilation for platform differences
  • Module-based organization (VNSPDFModule, VNSPDFExamplesModule)

Clean API Design

  • Consistent naming - All classes prefixed with VNS
  • Go-style error handling - Ok/Err pattern
  • Delegate callbacks - Header/Footer functions
  • Printf formatting - Cellf(), Writef() for convenience
  • Method chaining - Fluent API where appropriate

Reference Implementations

Based on proven libraries with millions of downloads:

  • go-pdf/fpdf (Go) - Primary reference
  • PHP FPDF (PHP) - Original library (2000)

:construction: Known Limitations & Roadmap

We’re transparent about what doesn’t work yet and our plans to fix it:

Web Platform Limitations

  • :cross_mark: WebChart Embedding - WebChart has protected constructor, cannot be converted to Picture
    • :clipboard: Planned: Server-side chart rendering using pure Xojo graphics
  • :cross_mark: Color Emoji Support - Server-side Graphics API cannot access system emoji fonts
    • :clipboard: Planned: Direct font file parsing (SBIX, COLR/CPAL, CBDT/CBLC formats)

iOS Platform Notes

  • :white_check_mark: String Functions - All cross-platform differences handled with conditional compilation
  • :white_check_mark: File I/O - SpecialFolder.Documents instead of Desktop
  • :white_check_mark: Image Handling - JPEG encoding for Picture objects (iOS RGBA→RGB conversion)
  • :warning: Compression (Free) - System zlib uses Declares, blocked by iOS sandboxing
    • :white_check_mark: Solution: Premium Pure Xojo Zlib (no declares) works perfectly on iOS!

Desktop/Console

  • :white_check_mark: No known limitations - All features fully working

Bottom Line: Desktop and Console are 100% feature-complete. Web and iOS have minor limitations with workarounds available or in development.


:trophy: November Contest Entry

This project demonstrates:

  • :white_check_mark: Innovation - First open-source Unicode PDF library for Xojo
  • :white_check_mark: Quality - 19 working examples, cross-platform, well-documented
  • :white_check_mark: Practicality - Solves real pain points (Unicode, closed source)
  • :white_check_mark: Completeness - Full feature set from fonts to encryption
  • :white_check_mark: Community Value - Open source, extensible, educational

Get it here : Xojo FPDF - Pure Xojo PDF Generation with Full Unicode Support - verynicesw

15 Likes

Wow. If this is as comprehensive as described and produces good output, you should sell it to Xojo. You’ve reinvented their wheel and dramatically improved it.

3 Likes

Looks impressive. The only thing I can’t see listed is the ability to output Graphs from DesktopCharts (or WebCharts etc) as can be done with the built in PDFDocument class (yes without the UTF8 support).