Skip to content

Conversation

@galihlasahido
Copy link

Description

...
Add new features of

📄 PDF Manipulation Suite

  • Merge multiple PDFs with page selection
  • Split documents into chunks, extract odd/even pages
  • Stamp & Watermark with headers, footers, page numbers
  • PDF Encryption
  • PDF Compression
  • PDF to Image
  • Barcode/QR Code
  • PDF Bookmarks
  • PDF Form Filling
  • Page Rotation
  • PDF Crop/Resize
  • Metadata Editor
  • PDF Linearization

🌐 HTML to PDF Conversion

  • Headings, lists, tables, inline CSS → beautiful PDFs
  • Perfect for reports, invoices, and dynamic documents

🔐 Enhanced Digital Signatures

  • Multiple signatures per document
  • RFC 3161 timestamps
  • Long-Term Validation (LTV) support
    ...

Type of change:

  • Add multiple features
  • Documentation.
  • Example.
  • Testing.

galihlasahido and others added 30 commits January 1, 2026 23:36
Implement support for multiple digital signatures in PDF documents using
incremental updates. This addresses the limitation of openssl_pkcs7_sign()
which can only sign once.

New features:
- SignatureManager: Main class for managing multiple signatures
- CmsBuilder: Builds CMS/PKCS#7 SignedData structures using phpseclib
- PdfParser: Parses existing PDFs for incremental updates
- PhpseclibSigner: Implements SignatureInterface using phpseclib
- Support for signing existing empty signature fields
- Support for adding new signature fields and signing them
- Incremental PDF updates to preserve existing signatures

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add signer1, signer2, signer3 certificates for testing multiple signatures
- Add multiple_signatures.php example demonstrating:
  - Creating a PDF document
  - Applying first signature
  - Applying second signature (incremental update)
  - Applying third signature (another incremental update)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Fix CmsBuilder to use ASN1::encodeDER() instead of non-existent saveDN()
- Add proper AcroForm, SigFlags, and Fields to document catalog
- Add Annots array to page for signature widget annotations
- Accumulate signature fields across multiple incremental updates
- Add appearance stream reference to signature widgets

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add pdfaConformance property to support A, B, U conformance levels
- Fix PDF version: use 1.7 for PDF/A-2 and PDF/A-3 (was only 1.4)
- Update XMP metadata to use dynamic conformance level
- Fix OutputIntents return for PDF-X mode
- Support modes: pdfa1a/b, pdfa2a/b/u, pdfa3a/b/u
- Add comprehensive PDF/A example

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add TimestampClient class for RFC 3161 Time-Stamp Protocol
- Integrate timestamp tokens into CMS signature unsigned attributes
- Support configurable TSA URL, authentication, and timeout
- Increase signature buffer size to accommodate timestamp tokens
- Add example demonstrating timestamped signatures

Timestamps provide proof that documents were signed at a specific time,
enabling long-term validation (LTV) of digital signatures.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Extend TEmbeddedFile type with mimeType, afRelationship, description, dates
- Add configurable MIME type and AFRelationship to addEmbeddedFile methods
- Add addXmlEmbeddedFile() convenience method for ZUGFeRD/Factur-X invoices
- Update getOutEmbeddedFiles() to use dynamic MIME types and relationships
- Add creation/modification dates to embedded file parameters
- Add example demonstrating PDF/A-3 with embedded invoice XML

Supports e-invoicing standards like ZUGFeRD, Factur-X, and XRechnung
by allowing arbitrary file embedding with proper PDF/A-3 metadata.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Implement LTV infrastructure for PDF signatures that remain verifiable
even after certificates expire or revocation services become unavailable.

New classes:
- OcspClient: OCSP protocol client for certificate status checking
- CrlFetcher: Downloads CRLs from distribution points
- DssBuilder: Creates Document Security Store (DSS) with VRI entries

SignatureManager additions:
- enableLtv() method to add validation data to signed PDFs
- Certificate chain extraction from existing CMS signatures
- DSS dictionary building with incremental PDF updates

Features:
- Embeds certificates, OCSP responses, and CRLs in PDF
- Creates per-signature VRI (Validation-Related Information)
- Compliant with PAdES-LTV specification
- Graceful fallback when validation data unavailable

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add FieldCalculation class for automatic field calculations (sum, product, average, min, max, custom)
- Add FieldValidator class for JavaScript-based field validation (required, email, number, range, length, regex)
- Add ConditionalVisibility class for dynamic show/hide based on field values
- Add Tcpdf helper methods: createFieldCalculation, createFieldValidator, createConditionalVisibility
- Add addCalculatedField and addValidatedField convenience methods
- Add advanced_acroforms.php example demonstrating all features
- Fix PdfMerger to properly copy content streams from source PDFs
- Fix PdfSplitter to properly copy content streams when splitting
- Fix SignatureManager regex too large error (use strpos instead)
- Fix SVG and image paths in examples/index.php to use __DIR__
- Fix index.php to save PDF to file instead of echoing to stdout
- Add HtmlRenderer class for HTML to PDF conversion
- Add html_to_pdf.php example demonstrating HTML features

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add src/Manipulate/PdfMetadataEditor.php with full metadata editing support
- Add examples/pdf_metadata.php demonstrating all features

Features:
- Load PDF from file or content
- Get/set Title, Author, Subject, Keywords, Creator, Producer
- Set/update creation and modification dates
- Bulk metadata updates via setMetadata()
- Remove individual fields or clear all metadata
- Add src/Manipulate/PdfBookmarkManager.php with full bookmark support
- Add examples/pdf_bookmarks.php demonstrating all features

Features:
- Load PDF from file or content
- Add bookmarks with title, page, level, and Y position
- Create hierarchical bookmark structures
- Bulk bookmark addition
- Read existing bookmarks
- Remove bookmarks by page or level
- Clear all bookmarks
- Add src/Manipulate/PdfBarcodeStamper.php with full barcode support
- Add examples/pdf_barcode.php demonstrating all features
- Integrate all 3 new classes with Tcpdf.php factory methods

Features:
- Add QR codes to documents
- Add Code 128, Code 39, EAN, UPC barcodes
- Add DataMatrix 2D codes
- Apply to all pages or specific pages
- Custom positioning and sizing
- Color support for barcodes
- Multiple barcodes per document
- Add src/Manipulate/PdfPageRotator.php with full rotation support
- Add examples/pdf_rotate.php demonstrating all features
- Integrate with Tcpdf.php via createPageRotator() factory method

Features:
- Rotate single or multiple pages
- Clockwise/counter-clockwise/upside-down shortcuts
- Rotate odd/even pages separately
- Multiple different rotations per document
- Reset page or all rotations
- Valid rotations: 0, 90, 180, 270 degrees
- Add src/Manipulate/PdfPageBoxEditor.php for page box manipulation
- Add examples/pdf_crop_resize.php demonstrating all features
- Integrate createPageBoxEditor() and cropPdfPages() methods in Tcpdf.php

Features:
- Set individual page boxes (MediaBox, CropBox, BleedBox, TrimBox, ArtBox)
- Crop pages to standard sizes (A0-A6, Letter, Legal, Tabloid)
- Crop to custom dimensions with positioning options
- Resize pages to standard or custom sizes
- Add uniform or individual margins
- Get current page box values
- Reset modifications per page or all at once
- Add src/Manipulate/PdfFormFiller.php for PDF form field manipulation
- Add examples/pdf_form_fill.php demonstrating all features
- Integrate createFormFiller() and fillPdfForm() methods in Tcpdf.php

Features:
- Load PDFs with AcroForm fields
- Inspect form fields (names, types, values, positions)
- Set individual or multiple field values
- Flatten fields to make them read-only
- Check field properties (required, read-only, options)
- Support for text, button, choice, and signature fields
- Add src/Manipulate/PdfEncryptor.php for PDF password protection
- Add examples/pdf_encrypt.php demonstrating all features
- Integrate createEncryptor() and encryptPdf() methods in Tcpdf.php

Features:
- User password (required to open document)
- Owner password (for full access)
- Multiple encryption modes: RC4_40, RC4_128, AES_128, AES_256
- Granular permission control (print, copy, modify, etc.)
- Convenience methods: allowPrinting, allowCopying, etc.
- Check if document is already encrypted
- Add src/Manipulate/PdfOptimizer.php for PDF file size reduction
- Add examples/pdf_optimize.php demonstrating all features
- Integrate createOptimizer() and optimizePdf() methods in Tcpdf.php

Features:
- Multiple optimization levels: MINIMAL, STANDARD, MAXIMUM
- Stream compression with configurable levels (1-9)
- Removal of unused PDF objects
- Detection and removal of duplicate objects
- Detailed statistics: originalSize, optimizedSize, compressionRatio
- Human-readable file size formatting
- Add src/Manipulate/PdfToImage.php for PDF to image conversion
- Add examples/pdf_to_image.php demonstrating all features
- Integrate createImageConverter() and pdfPageToImage() methods in Tcpdf.php

Features:
- Multiple format support: PNG, JPEG, WebP, GIF
- Configurable resolution (72-600 DPI)
- Quality settings for JPEG/WebP
- Imagick and Ghostscript backend support
- Backend auto-detection with graceful fallback
- Convert single page or all pages
- Add src/Manipulate/PdfLinearizer.php for fast web view optimization
- Add examples/pdf_linearize.php demonstrating all features
- Integrate createLinearizer(), linearizePdf(), isPdfLinearized() in Tcpdf.php

Features:
- Check if PDF is already linearized
- Linearize PDFs for progressive download/display
- Generate proper linearization dictionary
- Object reordering for first page priority
- Hint stream generation for quick page location
- Statistics tracking (original/linearized size, first page offset)
- PdfBookmarkManager: Fixed xref offset calculation by tracking current
  offset position and calculating offsets BEFORE appending object content.
  This fixes bookmarks not appearing in PDF viewers like Adobe Acrobat.

- PdfBarcodeStamper: Fixed barcode rendering by using getArray() method
  which returns bar coordinates [x, y, width, height] instead of getGrid()
  which returns a string. This fixes barcodes not appearing in output PDFs.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Extract shared Resources dictionary from source PDF during parsing
- Preserve ColorSpace objects (like /CS1 Separation color) when rebuilding
- Include ColorSpace references in page Resources dictionary

This fixes the issue where PDF content was not visible in Adobe Acrobat
because the ColorSpace referenced in content streams was missing from
the page Resources.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add extractNestedDict() helper to properly parse nested << >> structures
- Handle both reference (/Resources N 0 R) and inline (/Resources <<...>>)
  formats when extracting Resources
- Fixes issue where PDFs processed multiple times lost ColorSpace

This ensures content is visible when loading and re-processing PDFs
that were previously created by the bookmark manager.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add ColorSpace (CS1) resource preservation to ensure text content
renders properly in manipulated PDFs. Without this fix, PDFs with
Separation colorspace would show no content after processing.

Classes fixed:
- PdfEncryptor: encrypted PDFs now preserve ColorSpace
- PdfBarcodeStamper: barcode-stamped PDFs preserve ColorSpace
- PdfSplitter: split PDFs preserve ColorSpace
- PdfPageBoxEditor: cropped/resized PDFs preserve ColorSpace
- PdfMetadataEditor: metadata-edited PDFs preserve ColorSpace
- PdfMerger: merged PDFs preserve ColorSpace
- PdfPageRotator: rotated PDFs preserve ColorSpace

Each class now:
- Extracts Resources dictionary from source PDF
- Allocates and writes ColorSpace object when present
- Includes ColorSpace reference in page Resources

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
The modifyPdfWithStamps() method was a stub that returned the original
PDF without applying stamps. This commit adds proper implementation:

- Add extractObjects() to parse all PDF objects from content
- Add extractResources() to extract Resources from page objects
- Add extractNestedDict() for proper nested dictionary parsing
- Add findPageObjects() to locate page objects
- Add buildModifiedPageObject() to inject stamp content references
- Implement modifyPdfWithStamps() to rebuild PDF with stamps:
  - Creates new content stream objects for stamp content
  - Appends stamp references to page Contents arrays
  - Adds Helvetica font resources for text rendering
  - Preserves ColorSpace for proper text rendering
  - Rebuilds xref table and trailer

All stamp types now work: text stamps, watermarks, page numbers,
headers, footers, and date stamps.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Implement correct Algorithm 2.B (ISO 32000-2) with iterative hashing
  - Use SHA-256/384/512 selection based on SUM of first 16 bytes mod 3
  - Fix round counting to start at 1 and increment at loop start
  - Correct termination condition: roundNumber >= 64 AND lastByte <= (roundNumber - 32)
- Fix encrypt dictionary structure: add /Length 256 and /AuthEvent /DocOpen
- Fix permission value calculation using -4 (0xFFFFFFFC) as base
- Use PDF 1.7 with Adobe Extension Level 8 for Acrobat compatibility
- Passwords now work correctly in Preview, Adobe Acrobat, and Chrome

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants