From 27fd2bcb8d910293d36bab1092758bffafa7df96 Mon Sep 17 00:00:00 2001 From: mlam19 Date: Sat, 6 Dec 2025 15:35:52 -0500 Subject: [PATCH] Enable input controls in PDF reports (#10969) * Enable input controls in PDF reports Modify options passed to WeasyPrint. * Changelog update for issue #10969. * Add usage notes for PDF forms to report docs (#10969). --- CHANGELOG.md | 1 + docs/docs/report/weasyprint.md | 3 +++ src/backend/InvenTree/report/models.py | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 862860c1af..af5b9c2437 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Adds "Category" columns to BOM and Build Item tables and APIs in [#10722](https://github.com/inventree/InvenTree/pull/10772) - Adds generic "Parameter" and "ParameterTemplate" models (and associated API endpoints) in [#10699](https://github.com/inventree/InvenTree/pull/10699) - Adds parameter support for multiple new model types in [#10699](https://github.com/inventree/InvenTree/pull/10699) +- Allows report generator to produce PDF input controls in [#10969](https://github.com/inventree/InvenTree/pull/10969) - UI overhaul of parameter management in [#10699](https://github.com/inventree/InvenTree/pull/10699) ### Changed diff --git a/docs/docs/report/weasyprint.md b/docs/docs/report/weasyprint.md index e2aaaccad5..faeabfc143 100644 --- a/docs/docs/report/weasyprint.md +++ b/docs/docs/report/weasyprint.md @@ -13,6 +13,9 @@ We use the powerful [WeasyPrint](https://weasyprint.org/) PDF generation engine Templates are rendered using standard HTML / CSS - if you are familiar with web page layout, you're ready to go! +HTML form elements (`input`, `select`, `textarea`, `button`) are converted into PDF form controls. Use CSS to limit which elements are converted; refer to the +[WeasyPrint docs](https://doc.courtbouillon.org/weasyprint/stable/common_use_cases.html#include-pdf-forms) for further information. + ### Template Language Uploaded report template files are passed through the [django template rendering framework]({% include "django.html" %}/topics/templates/), and as such accept the same variable template strings as any other django template file. Different variables are passed to the report template (based on the context of the report) and can be used to customize the contents of the generated PDF. diff --git a/src/backend/InvenTree/report/models.py b/src/backend/InvenTree/report/models.py index f2bedd9e67..677500ea3b 100644 --- a/src/backend/InvenTree/report/models.py +++ b/src/backend/InvenTree/report/models.py @@ -272,7 +272,7 @@ class ReportTemplateBase(MetadataMixin, InvenTree.models.InvenTreeModel): bytes: PDF data """ html = self.render_as_string(instance, request, context, **kwargs) - pdf = HTML(string=html).write_pdf() + pdf = HTML(string=html).write_pdf(pdf_forms=True) return pdf