8000 Updates to PDF/A support by bsweeney · Pull Request #3579 · dompdf/dompdf · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Updates to PDF/A support #3579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Updates to PDF/A support #3579

wants to merge 5 commits into from

Conversation

bsweeney
Copy link
Member
  • Improves structure of embedded file metadata
  • Adds initial support for defining the relationship between an object and an embedded file

@bsweeney bsweeney added this to the 3.1.1 milestone Jan 20, 2025
lib/Cpdf.php Outdated
*/
public function addEmbeddedFile(string $filepath, string $embeddedFilename, string $description): void
public function addEmbeddedFile(string $filepath, string $embeddedFilename, string $description, string $mimeType = "application/octet-stream", $relatedTo = []): void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is missing like in mpdf the array param to add other attributes like afRelationship and mime

Copy link
Member Author
@bsweeney bsweeney Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$mimeType will address the mime type of the file.

$relatedTo is intended to define the relationship to another object where the key is the object ID and the value is the relationship (e.g., "Data"). Thinking on this more, referencing a file from more than one object is ... unlikely? I don't recall seeing that it was not possible, but it doesn't seem like a common scenario. I should maybe change the signature to:

public function addEmbeddedFile(string $filepath, string $embeddedFilename, string $description, string $mimeType = "application/octet-stream", int? $relatedObject, string? $relationship = "Unspecified"): void

Or, I could just take the relationship arguments out and leave file association as an additional call for the user via the associateFile method (just below this one). However, that's a bit more work because you have to find the embedded file dictionary object number in the object collection first.

FYI, I set the relationship logic up this way because the PDF spec allows associating files with more than just the catalog. You can add associated files for other embedded object (fonts, images) as well. Looking at the mpdf logic that library seems to only support associating files with the catalog object. Though Cpdf currently only supports associating files with the catalog I wanted to make sure it could associate with other objects in the future with minimal change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @bsweeney
My eyes where not aligned, the current signature is perfect
I am not not sure there is anything that needs a change

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be sure to document the last parameter better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added phpstan annotations, it will help a lot users that implement and use tools like Psalm or PHPStan.
That said the doc comment in unclear if the user should create it's own object IDs

Copy link
Member Author
@bsweeney bsweeney Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll tweak the $relatedTo description to read:

relationship of the embedded file to other PDF objects; the key is the object ID generated by Cpdf when the related object was added to the document and the value is a string (constrained list) naming the relationship type.

This relationship value should probably just be an enum ... but for PHP 7 support 😬. We could use constants instead. Or keep it as a string for now and consider switching to an enum once the minimum PHP version bumped to 8.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll also add information to the wiki about how to use this method in relation to factur-x.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can post a full test of example when more scaffolding is merged

@bsweeney bsweeney linked an issue Jan 21, 2025 that may be closed by this pull request
1 task
@williamdes
Copy link
Contributor

@bsweeney can this be merged ?
maybe with the phpstan annotations I suggested, else discard them I can do a PR for it

PDF names can include characters that are interpreted as operative delimeters (e.g., a slash) so long as the characters are escaped. This change adds a helper function to esacpe delimeters and characters out side the code point range of 33-126, per section 3.2.4 of the PDF 1.7 spec.
- fixes support for conditional file compression
- fixes checksum calculation for compressed file
- adds support for additional properties required by PDF/A (MimeType, ModDate)

partially addresses #3576
Currently only implemented by the catalog object.

fixes #3576
Until Cpdf supports annotation types other than links the ony flag that needs to be set for PDF/A support is the Print flag.

fixes #3586
Co-authored-by: William Desportes <williamdes@wdes.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants
0