-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
base: master
Are you sure you want to change the base?
Updates to PDF/A support #3579
Conversation
- Improves structure of embedded file metadata
- Adds initial support for defining the relationship between an object and an embedded file
0127893
to
e2af2d9
Compare
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 can this be merged ? |
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>