MCPcopy Create free account
hub / github.com/LibPDF-js/core / flattenAll

Method flattenAll

src/api/pdf.ts:3046–3074  ·  view source on GitHub ↗

* Flatten all interactive content in the document. * * This is a convenience method that flattens: * - Layers (OCGs) - prevents hidden content attacks * - Form fields - converts to static text/graphics * - Annotations - bakes appearances into page content * * Use this before sig

(options?: FlattenAllOptions)

Source from the content-addressed store, hash-verified

3044 * ```
3045 */
3046 flattenAll(options?: FlattenAllOptions): FlattenAllResult {
3047 // Flatten layers first (affects visibility of everything)
3048 const layerResult = this.flattenLayers();
3049
3050 // Flatten form fields
3051 const form = this.getForm();
3052 let formFields = 0;
3053
3054 if (form) {
3055 formFields = form.getFields().length;
3056 form.flatten(options?.form);
3057 }
3058
3059 // Flatten annotations last (may reference form widgets which are now gone)
3060 // By default, remove Link annotations since they contain actions that
3061 // Adobe considers "hidden behavior" which can cause signature validation warnings.
3062 const annotationOptions = {
3063 removeLinks: true,
3064 ...options?.annotations,
3065 };
3066
3067 const annotations = this.flattenAnnotations(annotationOptions);
3068
3069 return {
3070 layers: layerResult.layerCount,
3071 formFields,
3072 annotations,
3073 };
3074 }
3075
3076 // ─────────────────────────────────────────────────────────────────────────────
3077 // Text Extraction

Calls 5

flattenLayersMethod · 0.95
getFormMethod · 0.95
flattenAnnotationsMethod · 0.95
getFieldsMethod · 0.65
flattenMethod · 0.45

Tested by

no test coverage detected