PDFsharp & MigraDoc Foundation http://forum.pdfsharp.com/ |
|
PDFsharp-MigraDoc (6.0.0-preview-4) cannot be modified http://forum.pdfsharp.com/viewtopic.php?f=2&t=4492 |
Page 1 of 1 |
Author: | SomePie [ Wed Oct 18, 2023 11:02 am ] |
Post subject: | PDFsharp-MigraDoc (6.0.0-preview-4) cannot be modified |
The moment I try to open a readonly pdf document with the following method: sourceDocument = PdfReader.Open(file, PdfDocumentOpenMode.ReadOnly); I get the error System.InvalidOperationException: 'The document cannot be modified.' This so far only occorured with 1 single pdf file The pdf I'm trying to open is the following pdf https://dlcdnets.asus.com/pub/ASUS/mb/L ... V2_WEB.pdf Am I doing something wrong or..? with regards SomePie |
Author: | Thomas Hoevel [ Wed Oct 18, 2023 11:30 am ] |
Post subject: | Re: PDFsharp-MigraDoc (6.0.0-preview-4) cannot be modified |
SomePie wrote: Am I doing something wrong or..? Well, the file is inconsistent: The PDF version is set to 1.7, but the encryption level is set to 5.Encryption level 5 came with PDF 2.0, therefore PDFsharp tries to change the version to 2.0 - and this fails. I think I'll change PDFsharp to not adjust the incorrect version number for files opened in ReadOnly mode. Will discuss this with my fellow worker. Thanks for your feedback. As a workaround, you could open the file in "modify" mode until the next release comes. Update: File cannot be opened in Import mode, this leads to a different error message. I'll discuss this with my fellow worker, too. |
Author: | SomePie [ Wed Oct 18, 2023 11:36 am ] |
Post subject: | Re: PDFsharp-MigraDoc (6.0.0-preview-4) cannot be modified |
Thomas Hoevel wrote: SomePie wrote: Am I doing something wrong or..? Well, the file is inconsistent: The PDF version is set to 1.7, but the encryption level is set to 5.Encryption level 5 came with PDF 2.0, therefore PDFsharp tries to change the version to 2.0 - and this fails. I think I'll change PDFsharp to not adjust the incorrect version number for files opened in ReadOnly mode. Thanks for your feedback. As a workaround, you could open the file in "modify" mode until the next release comes. Thanks for your quick reply, though the modify mode would only be possible if I had the actual password for this one with regards, SomePie |
Author: | Thomas Hoevel [ Wed Oct 18, 2023 11:42 am ] |
Post subject: | Re: PDFsharp-MigraDoc (6.0.0-preview-4) cannot be modified |
SomePie wrote: Thanks for your quick reply, though the modify mode would only be possible if I had the actual password for this one I already noticed that.Will discuss this with my fellow worker. Encryption is not my area of expertise. |
Author: | Thomas Hoevel [ Wed Oct 18, 2023 12:00 pm ] |
Post subject: | Re: PDFsharp-MigraDoc (6.0.0-preview-4) cannot be modified |
I made a change to SetRequiredVersion in PdfDocument. Here's the change if you want to try it out: Code: /// <summary>
/// Adjusts the version if the current version is lower than the required version. /// Version is not adjusted for inconsistent files in ReadOnly mode. /// </summary> /// <param name="requiredVersion">The minimum version number to set version to.</param> /// <returns>True, if Version was modified.</returns> public bool SetRequiredVersion(int requiredVersion) { if (requiredVersion > Version && CanModify) { Version = requiredVersion; return true; } return false; } |
Author: | SomePie [ Wed Oct 18, 2023 1:26 pm ] |
Post subject: | Re: PDFsharp-MigraDoc (6.0.0-preview-4) cannot be modified |
Thomas Hoevel wrote: I made a change to SetRequiredVersion in PdfDocument. Here's the change if you want to try it out: Code: /// <summary> /// Adjusts the version if the current version is lower than the required version. /// Version is not adjusted for inconsistent files in ReadOnly mode. /// </summary> /// <param name="requiredVersion">The minimum version number to set version to.</param> /// <returns>True, if Version was modified.</returns> public bool SetRequiredVersion(int requiredVersion) { if (requiredVersion > Version && CanModify) { Version = requiredVersion; return true; } return false; } I'll pull the repo later on this week and try this change in it! thank you |
Author: | SomePie [ Fri Oct 20, 2023 10:33 am ] |
Post subject: | Re: PDFsharp-MigraDoc (6.0.0-preview-4) cannot be modified |
Thomas Hoevel wrote: I made a change to SetRequiredVersion in PdfDocument. Here's the change if you want to try it out: Code: /// <summary> /// Adjusts the version if the current version is lower than the required version. /// Version is not adjusted for inconsistent files in ReadOnly mode. /// </summary> /// <param name="requiredVersion">The minimum version number to set version to.</param> /// <returns>True, if Version was modified.</returns> public bool SetRequiredVersion(int requiredVersion) { if (requiredVersion > Version && CanModify) { Version = requiredVersion; return true; } return false; } I downloaded the repo, added the change in 'PdfSharp\src\foundation\src\PDFsharp\src\PdfSharp\Pdf\PdfDocument.cs' built the dll, replaced it in the debug of my project after rebuilding, same error still comes up did I miss a step? [edit] When I try Code: form = XPdfForm.FromFile(file); and then read the form.PageCount the same error applies [/edit] |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |