Skip to content

Remove truly empty pages from Calc PDF exports - #414

Merged
KnifeLemon merged 5 commits into
KnifeLemon:mainfrom
Perricheno:fix/libreoffice-empty-sheet-pages
Oct 23, 2026
Merged

KnifeLemon merged 5 commits into
KnifeLemon:mainfrom
Perricheno:fix/libreoffice-empty-sheet-pages

Conversation

@Perricheno

@Perricheno Perricheno commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

LibreOffice Calc can preserve stale Excel print tiles as completely empty PDF pages. This removes only pages with no painting operator at all after a Calc-to-PDF conversion.

The check is deliberately conservative: text, borders, charts, images, annotations, and even white paint keep the page. Unreadable pages and wholly blank documents are left unchanged. PDF/A output is left byte-for-byte as LibreOffice wrote it because re-saving it would invalidate the relationship between its Info dictionary and archival XMP metadata.

Tested with focused unit tests and a locally supplied seven-sheet 1-5 курс.xlsx workbook through the real LibreOffice converter. The workbook contains personal/academic data, was not uploaded, and has no public issue or discussion.

@KnifeLemon KnifeLemon added the bug Something isn't working label Oct 22, 2026
@KnifeLemon KnifeLemon self-assigned this Oct 22, 2026

@KnifeLemon KnifeLemon left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Perricheno, this is a careful, conservative fix: only pages with no painting operator go, annotations and unreadable pages keep a page, a wholly blank document is left alone, and the file is replaced only after the cleaned copy was saved. CI is green.

Two things before we merge:

  1. PDF/A. When the preset asks for PDF/A, LibreOffice writes a PDF/A file, and re-saving it with PDFsharp breaks that: PDFsharp writes its own Producer and a new ModDate into the Info dictionary (I checked: after PdfBlankPages.Remove both change), while the XMP metadata LibreOffice wrote stays as it was. PDF/A validators flag that mismatch. Please skip the clean-up when step.Preset.Document.PdfA is on, with a test.
  2. The comment in LibreOfficeConverter says "empty trailing PDF pages", but PdfBlankPages.Remove drops empty pages anywhere in the document. Removing them anywhere is fine for Calc's leftover print tiles (with "down, then over" page order they can sit between real pages), so please just make the comment say what the code does.

Also, where did the 1-5 курс.xlsx report come from? If there is an issue or a discussion, please link it so the reporter hears about the fix.

@Perricheno

Copy link
Copy Markdown
Contributor Author

Thanks — addressed in 29072d5.

  1. PDF/A Calc output now bypasses PdfBlankPages completely. The new test uses a PDF containing a page that ordinary cleanup would remove, then verifies that with Document.PdfA = true the result is 0 removed, both pages remain, and the file is byte-for-byte unchanged.
  2. The LibreOffice comment now says that empty pages may occur anywhere in the output, not only at the end.
  3. 1-5 курс.xlsx came from my local Downloads folder during hands-on testing. There is no public issue/discussion or separate reporter to notify, and I did not upload it because it contains personal/academic data. I clarified that in the PR description.

Focused PdfBlankPagesTests: 3/3 pass locally. The broader LibreOffice selection run had 68 pass and 2 environment-dependent skips; the known local SVG→LibreOffice integration case still fails with “source file could not be loaded”, unrelated to this change. CI is the authoritative full-matrix run.

@KnifeLemon KnifeLemon left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Perricheno, PDF/A output is left untouched now and the test proves it byte for byte, and the comment matches what the code does. Good to go once CI is green.

@KnifeLemon
KnifeLemon merged commit 23aa5b0 into KnifeLemon:main Oct 23, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants