Repository navigation
Description
Summary
html2pdf4doc.js 0.4.1 sometimes places a page break after content that does not fit on the page. To keep the break on the page grid, the JS sets a negative margin-bottom on the first html2pdf4doc-print-running element of the next html2pdf4doc-page. In print, Chrome moves the overflowing content to an extra physical page before the break-after: page. As a result, the PDF has more pages than html2pdf4doc counted, and the strict mode fails:
RuntimeError: An error occurred with the printed page. Page count mismatch: PDF pages = 7, html2pdf4doc pages = 6.
After the extra page, the content is one page behind the page frames. The last PDF page has no header and no footer.
Environment
- html2pdf4doc 0.1.1 (html2pdf4doc.js 0.4.1)
- StrictDoc
main(d84869956) - Google Chrome 151.0.7922.71 on Linux
Steps to reproduce
The script below creates a StrictDoc project with two documents:
repro.sdoc: 11 short requirements, then the requirement "Many relations" with 16 Parent relationstargets.sdoc: the 16 parent requirements. The long titles make each relation link wrap over 3 lines.
make_repro.py:
from pathlib import Path
Path("strictdoc_config.py").write_text("""from strictdoc.api import ProjectConfig
def create_config() -> ProjectConfig:
return ProjectConfig(
project_title="Repro",
project_features=["HTML2PDF"],
html2pdf_strict=True,
)
""")
repro = ["[DOCUMENT]\nTITLE: Repro\n"]
for i in range(11):
repro.append(f"[REQUIREMENT]\nUID: REQ-{i}\nTITLE: Filler {i}\nSTATEMENT: The system shall do thing number {i}.\n")
relations = "".join(f"- TYPE: Parent\n VALUE: TGT-{j}\n" for j in range(16))
repro.append(f"[REQUIREMENT]\nUID: REQ-LONG\nTITLE: Many relations\nSTATEMENT: The system shall have many parents.\nRELATIONS:\n{relations}")
Path("repro.sdoc").write_text("\n".join(repro))
targets = ["[DOCUMENT]\nTITLE: Targets\n"]
for j in range(16):
targets.append(f"[REQUIREMENT]\nUID: TGT-{j}\nTITLE: Target {j} with a deliberately long title_that_contains_very_long_unbreakable_words_like_file_paths/test_{j}.itest so that it wraps\nSTATEMENT: Target {j}.\n")
Path("targets.sdoc").write_text("\n".join(targets))Run:
mkdir repro && cd repro
python ../make_repro.py
strictdoc export . --formats html2pdf
Expected: the export of repro.sdoc succeeds with 6 pages.
Actual: the export fails with PDF pages = 7, html2pdf4doc pages = 6. The bug depends on the exact position of the list. With 10 or 12 filler requirements, the export succeeds.
Analysis
In repro.sdoc-PDF.html, html2pdf4doc keeps the whole RELATIONS (Parent) list of "12. Many relations" on page 5. The list does not fit on page 5:
- The page body of page 5 ends at y=5726 (screen layout).
- The last list item (TGT-15) ends at y=5757, 31 px past the page body.
- html2pdf4doc inserts
<html2pdf4doc-page page="6">after the list. The firsthtml2pdf4doc-print-runningof this page marker hasstyle="margin-bottom: -70px;".
In the PDF, the list prints over the footer area of page 5. Page 6 shows only the page frame. The STATEMENT field of "12. Many relations" prints on page 7, which has no frame.
The same bug in the StrictDoc documentation
The same bug breaks the PDF export of the StrictDoc documentation with html2pdf_strict=True. The document docs/strictdoc_21_l2_high_level_requirements.sdoc gives PDF pages = 128, html2pdf4doc pages = 126. In this document, html2pdf4doc splits long lists inside the grid of a requirement node, but cuts the lists too late:
| Page marker | margin-bottom |
Field before the break | Extra PDF page |
|---|---|---|---|
| 70 | -105px | RELATIONS (File) list | yes |
| 102 | -269px | RELATIONS (File) list | yes |
| 103 | -117px | STATEMENT | no |
Example, page 102: the page body ends at y=114973. The last li that fits ends at y=114967. But html2pdf4doc cuts the list four items later, after the li that ends at y=115195. In the PDF, Chrome cuts the last link of page 69 in the middle of a text line and prints the rest of the line on an extra page.
Page 103 does not add a PDF page, by chance. The extra page for page 102 lets the next page start with 269 px of free space, which absorbs the 117 px overflow.
Suggestion
A negative margin-bottom on html2pdf4doc-print-running marks every split that overflows the page. html2pdf4doc.js could log a console error in this case. The error would then show the bug even without the page count check of the Python driver.
Activity