Feature Request MVP: Add Typst as a PDF Generator Option in Print Format#450
Feature Request MVP: Add Typst as a PDF Generator Option in Print Format#450agatho-daemon wants to merge 23 commits into
Conversation
…bally, resolve all TS errors
…ering with style mapping
…code, image, table)
- Installed Vitest, configured tsconfig and vite.config.ts - Verified module resolution using @typst aliases - Fixed issues with sanitizeFontFamily test logic - Removed old references to #box from page tests - Confirmed successful UI testing with --ui flag
Hijack the default 'chrome' PDF generator in Print Designer to use Typst instead, by checking for the presence of the Typst engine directory. This avoids the need for modifying core Frappe validation or requiring a new pdf_generator literal. - Added `generate_typst_pdf` with sample Typst output - Modified `get_pdf` to route Chrome-based PDF generation to Typst if engine is present - Cleaned up all prior patching, JS overrides, and unnecessary hooks - Preserves fallback to Chromium-based rendering for other formats
This commit enhances the Print Designer by injecting "typst" (and "chrome") into the `pdf_generator` field options of the "Print Format" DocType. The addition is performed programmatically during installation using `make_property_setter`. Changes: - Introduced `add_pdf_generator_option()` to add custom generators - Created `set_pdf_generator_option(action, generators)` to handle addition/removal - Ensured the new generator is only added if not already present - Applied changes to the DocType definition without requiring manual intervention This ensures Typst can be selected via the UI as an alternative to Chrome for generating PDF outputs. Note: - Compatible with Frappe v15+ - Safe for repeated installs due to idempotent logic
Removed hijacking backend print_doc() to render using Typst CLI call.
Adds a sample Typst source file (invoice_sample.typ), its rendered output (invoice_sample.png), and a sample letterhead background (letterhead.png) to demonstrate the visual and layout capabilities of Typst PDF generation. This example serves as a visual supplement to the Typst MVP PR and provides a reference implementation of styled, positioned text and image-based layouts. Location: print_designer/pdf_generator/samples/
|
@agatho-daemon would love to discuss and understand before reviewing +14,272 change. if you are open to google meet call please let me know. if you prefer we can also do discussion via comments. Also, Thank you for your contribution. |
|
@maharshivpatel The other changes are samples, and the arch readme file As I have titled the request, this is only a minimal MVP and
Why I choose
Kindly note that this PR is not for submission. It is an MVP attempt to present the benefits of using So, please don't be tempted to accept the PR. We can discuss using both google meet and here depending on my proximity to a google meet enabled device. |
Description
This MVP serves as a proof-of-concept implementation of Typst as a PDF generator within Print Designer. It is intended to demonstrate the feasibility and potential advantages of supporting declarative typesetting engines alongside existing HTML-based renderers. Feedback and discussion are welcome.
This PR introduces a Minimum Viable Product (MVP) for integrating Typst
as a PDF rendering engine in Frappe's Print Designer. It serves as a proof of concept, demonstrating the feasibility and advantages of supporting declarative typesetting engines like Typst alongside existing HTML-based renderers. Feedback and discussion are welcome.
MVP Scope
"typst"to thepdf_generatorfield options in Print FormatstaticText,dynamicText, andimageblock stylesTypstDocumentBuilder,TypstEngine, and layout scaffoldingThis MVP is tightly coupled to the current Print Designer JSON schema, which brings the following constraints:
Changes Included
add_pdf_generator_option()andset_pdf_generator_option()ininstall.py"typst"(and"chrome") into thepdf_generatoroptions viamake_property_setterWhy Typst?
Frappe has historically relied on wkhtmltopdf, which is deprecated and being replaced by WeasyPrint. Meanwhile, Print Designer currently uses Chromium (chrome) to convert HTML to PDF—an approach that lacks the precision, consistency, and elegance of a typesetting system.
Typst offers a clean and modern alternative—a declarative, typesetting-first approach that prioritizes consistency and developer ergonomics.
🌟 Typst Benefits
For architectural context and diagrams, check:
typst-arch.mdThe current implementation of Typst rendering relies solely on the structure and semantics of the JSON output generated by Print Designer. While this provides a useful baseline for rendering, it introduces some rigidity and complexity when mapping document elements to Typst’s typesetting constructs.
This MVP was coded within the existing format to ensure compatibility without requiring upstream changes. However, improvements to the JSON schema or a shared interface specification between the builder and renderers (e.g., Typst, Chrome, WeasyPrint) could open the door for more flexible and expressive layouts in the future.
This is not a blocker for Typst integration, but rather a potential area for shared improvement.
Future
It is very imperative to note that the progress of implementation is tightly coupled to a structured JSON taking into account Typst markup structural precision for elements positioning on page.
How to Test
📎 Sample Output
A complete sample of a rendered sales invoice using Typst is included in this repository to demonstrate layout accuracy, styled label/value blocks, and use of a letterhead background image.
Included files:
print_designer/pdf_generator/samples/sales_invoice_sample.typprint_designer/pdf_generator/samples/sales_invoice_sample.pngprint_designer/pdf_generator/samples/letterhead.svgThese serve as a practical reference for how Typst can express precise business document layouts typically rendered in HTML/CSS.