fix(export): prevent wide tables from being cut off in PDFs (#15021) - #18341
Florian DeLemarre (delemaf) wants to merge 1 commit into
Conversation
…in PDF generation
There was a problem hiding this comment.
🟡 Changes recommended
One or more issues must be addressed before approval.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
This PR fixes frontend PDF exports so wide tables wrap within page margins while preserving links, images, orientation, and font sizing.
Changes:
- Constrains table columns and cell images for HTML, Markdown, and Fintel exports.
- Handles merged headers using
colSpan. - Adds rendered-PDF regression tests with PDF.js and declares
pdfjs-distdirectly.
File summaries
| File | Description |
|---|---|
| opencti-platform/opencti-front/yarn.lock | Updated as part of this pull request. |
| opencti-platform/opencti-front/src/utils/htmlToPdf/utils/pdfTableWidth.ts | Updated as part of this pull request. |
| opencti-platform/opencti-front/src/utils/htmlToPdf/utils/pdfTableWidth.test.ts | Updated as part of this pull request. |
| opencti-platform/opencti-front/src/utils/htmlToPdf/htmlToPdf.ts | Updated as part of this pull request. |
| opencti-platform/opencti-front/package.json | Updated as part of this pull request. |
Review details
Suppressed comments (1)
opencti-platform/opencti-front/src/utils/htmlToPdf/utils/pdfTableWidth.test.ts:37
- The Markdown branch never sets
spanningHeader: true, and themarkdownstring does not include theheadingat all. Consequently, the new post-Markdown-conversion path is not tested with a merged header—thecolSpancase this change is intended to support—so a regression in the combined Markdown/merged-header flow could pass these tests. Include a Markdown export containing the equivalent raw HTML merged header.
const exportCases = ['table helper', 'HTML', 'Markdown', 'Fintel'].flatMap((exportType) => (
exportType === 'Markdown'
? [{ exportType, spanningHeader: false }]
: [{ exportType, spanningHeader: false }, { exportType, spanningHeader: true }]
- Files reviewed: 4/5 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| const firstRow = table.rows[0]; | ||
| if (firstRow) { | ||
| const columnCount = Array.from(firstRow.cells).reduce((total, cell) => total + cell.colSpan, 0); |
| cell.querySelectorAll('img').forEach((image) => { | ||
| if (image.closest('td, th') === cell) image.style.maxWidth = `${cellWidth}pt`; | ||
| }); |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #18341 +/- ##
==========================================
+ Coverage 36.57% 36.65% +0.08%
==========================================
Files 3467 3467
Lines 141069 141079 +10
Branches 38098 38099 +1
==========================================
+ Hits 51593 51719 +126
+ Misses 89476 89360 -116
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Proposed changes
Prevent tables containing long hashes or URLs from overflowing the printable page in built-in HTML/Markdown and Fintel PDF exports.
*) column widths with equal percentage widths. Flexible columns respect long tokens' minimum widths and can exceed the page; constrained widths allow those tokens to wrap.colSpanso merged headers do not cause rendering failures.Related issues
ExportReportPDFconnector uses WeasyPrint in the separateOpenCTI-Platform/connectorsrepository and requires its own fix. This PR deliberately does not auto-close the issue.How to test this PR
Automated checks, from
opencti-platform/opencti-front:Verification:
Checklist
Rendered-PDF regression tests are included; no new browser E2E tests or documentation changes are included.