For PDFs with form fields, _usedInForm on embedded fonts is set to true, which permanently blocks subsetting, causing flattened PDFs to embed full fonts. Since flattened PDFs don't have form fields anymore, I believe their embedded fonts should be subsettable.
I'm using this hacky work-around:
form.flatten()
for (const font of Object.values(embeddedFonts)) {
if (font && (font as unknown as { _usedInForm: boolean })._usedInForm) {
;(font as unknown as { _usedInForm: boolean })._usedInForm = false
}
}
But I'm guessing the cleaner solution is to clear the _usedInForm field in flatten() itself.
I'm happy to put together a PR if this is the right approach.
For PDFs with form fields,
_usedInFormon embedded fonts is set to true, which permanently blocks subsetting, causing flattened PDFs to embed full fonts. Since flattened PDFs don't have form fields anymore, I believe their embedded fonts should be subsettable.I'm using this hacky work-around:
But I'm guessing the cleaner solution is to clear the
_usedInFormfield inflatten()itself.I'm happy to put together a PR if this is the right approach.