Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.0.28, 3.0.0 PDFBox
-
None
Description
I've noticed saving documents incrementally does not trigger fonts to be subsetted.
The function PDDocument.save() contains the following code:
// subset designated fonts for (PDFont font : fontsToSubset) { font.subset(); } fontsToSubset.clear();
However, this code to subset fonts does not seem te be included in the PDDocument.saveIncremental(...) and PDDocument.saveIncrementalForExternalSigning(...) functions. When loading a font and indicating it should be subset, the font will be used in the appearance stream as if subsetted, but it won't be in the end, resulting in a corrupt file.
Solution
I propose to also call subset when signing incrementally.
I use this for files to which I add multiple signatures. In between signatures, text fields are filled in using PDFBox. Since the fields are not user-editable, fonts can be subsetted since the value cannot be changed afterwards.
Reproduce
I have attached 2 files to reproduce this issue. In both files you can change saveIncremental() by save() or manually call font.subset() and the output will be valid.
Note: both files are minimal reproducible files just designed to trigger this issue, that's why the implementations don't make sense (especially the first file).