feat: EPDF_RemoveOptionalContentGroups — hidden optional-content layer removal (follow-up to #673)#28
Open
Phauks wants to merge 2 commits into
Open
feat: EPDF_RemoveOptionalContentGroups — hidden optional-content layer removal (follow-up to #673)#28Phauks wants to merge 2 commits into
Phauks wants to merge 2 commits into
Conversation
Add three EmbedPDF extension functions for redaction-defensibility scrubbing of non-content hidden vectors, mirroring the existing EPDF_SetMetaText style: - EPDF_RemoveXMPMetadata: drop the catalog /Metadata XMP stream (survives an Info-dict clear — the embedpdf#1 sanitization miss). - EPDF_RemoveEmbeddedThumbnails: drop every page /Thumb. - EPDF_RemoveAllJavaScript: drop /Names /JavaScript, JS /OpenAction, and /AA. Declared in public/fpdf_doc.h (auto-exported by the WASM build's generator), implemented in fpdfsdk/fpdf_doc.cpp via GetMutableRoot()/RemoveFor.
…t layers Per-page, drop page objects not visible under the default (View) OC config (CPDF_OCContext::CheckPageObjectVisible resolves OCG/OCMD/VE), regenerate the content, then remove the catalog /OCProperties. Excises hidden-layer content rather than just deleting /OCProperties (which would reveal it). Declared in public/fpdf_doc.h, implemented in fpdfsdk/fpdf_editpage.cpp (reuses FPDF_LoadPage for content parsing + CPDF_PageContentGenerator for regen).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to embedpdf/embed-pdf-viewer#673 — adds the fourth, harder sanitization vector: removing content hidden behind OFF optional-content groups (layers).
Stacked on #27 (the XMP/JS/thumbnails exports). This branch includes #27's commit; the OCG-specific commit is
8b8a678. Please land #27 first — I'll rebase this onto the merged base so it shows only the OCG change.EPDF_RemoveOptionalContentGroups(doc)Hidden layers can't be sanitized by just deleting
/OCProperties— that would make the hidden content visible. This excises the content instead: for each page it drops the page objects that are not visible under the default (View) configuration (usingCPDF_OCContext::CheckPageObjectVisible, which resolves OCGs, OCMDs, and/VEvisibility expressions), regenerates the page content, then removes the catalog/OCProperties. Implemented infpdfsdk/fpdf_editpage.cpp(reusesFPDF_LoadPagefor content parsing andCPDF_PageContentGeneratorfor regeneration), declared inpublic/fpdf_doc.h.The TypeScript
optionalContentGroupsflag onsanitizeDocumentand a test (test-remove-ocg.mjs: hidden-layer text removed via text extraction,/OCPropertiesgone, visible content preserved) are in the companion monorepo PR.Known scope / follow-ups (noted for review): this covers page-level content marked by hidden OCGs. Content inside form XObjects with their own
/OC, annotation/OC, and deeply nested cases may need additional handling or a rasterize-flatten fallback — happy to extend based on your preference.