-
Notifications
You must be signed in to change notification settings - Fork 132
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
Proposal: Incremental saving #112
base: master
Are you sure you want to change the base?
Conversation
Deleted objects are now handled when saving incrementally. Note: |
Hey @packdat - I have used your code and i have successfully achieved sign on multiple places and page. |
PDF Sharp 6.2 is adding support for digital signatures, incremental saving would be great addition to that to support multiple full covered signatures. EU validator: https://ec.europa.eu/digital-building-blocks/DSS/webapp-demo/validation |
Did you resolve that issue, if so, how? |
@Havunen - Permissions on signed document is still not done. We are looking for help too. |
I was recently tasked to evaluate the possibility to "stamp" existing documents.
A "stamp" is literally an image of an actual stamp that should be added to specific pages of a document.
Problem is, the document may be signed, so the stamp has to be added in a non-destructive manner to keep the signature intact.
I started to hack around and was able to come up with something that seems to work.
The idea was to just track changes to arrays (
PdfArray
) and dictionaries (PdfDictionary
).All other objects are basically immutable so this approach should work in theory.
Also, a new
PdfDocumentOpenMode
was added, namelyAppend
.When a document is opened in this mode, it starts to track changes to arrays and dictionaries.
When saving the document, only changed/added objects are saved; the changes are appended to the existing document.
Basic code (taken from the included test-case):
There may be more that is needed to work consistently (i.e. i haven't tested with encrypted documents yet as i was told the documents i have to work with will not be encrypted).
This change also does not handle the case, where object were deleted from a document.
These objects would need to be tracked separately as they would need special entries in the new XREF-table.
One potential issue i spotted was the fact that library modifies the document by just reading certain properties; thus accidentally marking those objects as "modified" although you haven't changed anything.
One example are the
*Box
- properties ofPdfPage
(e.g.TrimBox
,CropBox
, ...)If you read these properties and the document does not already contain values for them, a new value is added to the underlying dictionary.
I haven't looked too deeply but i expect there are more cases like that.
I have changed the
*Box
-properties to just returnPdfRectangle.Empty
when there is no value instead of adding a new value.There is also the case with type-transformations (e.g. exchanging a
PdfDictionary
with a more specific type likePdfPage
).These transformations happen "under the hood" and would normally also cause objects to be marked as modified.
I tried to prevent that by temporarily ignoring changes while doing the type-transformations by using the new method
This is quite "hack-ish", maybe you have better ideas on how to tackle this ?