We’ve been seeing a consistent issue starting about two weeks ago where PDFs generated by Anvil’s internal PDF generator crash macOS Preview on open.
Previously, everything worked fine. I can’t think of changing anything in the code that effects the PDF generation. The actual code used is straightforward.
pdf = PDFRenderer(
filename="Report.pdf",
page_size="A4",
# landscape=True,
scale=0.7,
margins={"top": 1.0, "bottom": 1.0, "left": 2.25, "right": 1.25},
).render_form("ComponentCalculate_Result", result_dict)
return pdf
A few key observations:
- The same files open without any issues in Adobe Acrobat Reader
- No problems have been reported by Windows users
- Multiple macOS users running up to date computers can reproduce the crash across different machines
- I have a PDF on hand that reproduces the error on an up to date MAC.
Given that several independent users are affected, this doesn’t appear to be an isolated environment issue.
From the crash report, the failure occurs in Apple’s PDF stack (CoreGraphics / PDFKit), specifically:
Thread 6 Crashed:: Dispatch queue: PDFKit.PDFDocument.formFillingQueue
0 CoreGraphics PageLayout::GetBoundsForRangeWithinLine
1 CoreGraphics PageLayout::GetBoundsForTextRange
2 CoreGraphics CGPDFTaggedNodeCreateCopyWithStringRange
3 CoreGraphics TaggedParser::InsertLinkAnnotationsIntoStructureTree
4 CoreGraphics CGPDFPageEnumerateAnnotations
5 CoreGraphics CGPDFPageCopyRootTaggedNode
6 CoreGraphics CGPDFPageInsertTableDescriptions
7 PDFKit +[PDFPageAnalyzerV2 addTablesFromVisionDocument…]
8 PDFKit +[PDFPageAnalyzerV2 analyzePage…]
9 PDFKit __31-[PDFView visiblePagesChanged:]_block_invoke
This suggests the crash is triggered during parsing of tagged PDF content / annotations / table structures.
At this point, I’m trying to determine:
whether our PDF output violates something in Apple’s PDF implementation
or whether this is a regression/bug in macOS Preview
I’m happy to share a sample PDF and/or more details about the APP privately if that helps.