wmjordan / wmjordan/PDFPatcher
保存pdf文件时,不勾选清理--清除复制、打印限制,也会移除编辑权限
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 12.7k
- Forks
- 1.6k
- PR merge metrics
- No merged PRs in 30d
Description
这个问题是5.5.14.0这个伪版本的iTextSharp\core\iTextSharp\text\pdf\PdfStamperImp.cs 代码中的bug。
if (reader.IsEncrypted() && append)
{
crypto = new PdfEncryption(reader.Decrypt);
}
这句代码只在追加的时候才会读取加密参数,所以在补丁丁里面直接保存pdf,就会丢失权限。
unethicalreading.zip 这是测试文件
在官方版本的5.5.13.4中,改成了
if (reader.IsEncrypted() && (append || PdfReader.unethicalreading))
这样也有bug,会造成保存pdf时,永远都会有加密。无法实现修改权限并删除加密提示的功能。
我反编译看了一个多小时代码,才发现这个问题。所以我增加了一个PdfReader.unethicalwriting参数
if (reader.IsEncrypted() && (append || !PdfReader.unethicalwriting))
{
crypto = new PdfEncryption(reader.Decrypt);
}
这样就可以通过设置PdfReader.unethicalwriting来决定是删除权限,还是保留权限。
至于pdf.RemoveUsageRights();和var form = pdf.Catalog.GetAsDict(PdfName.ACROFORM);这些删除权限的功能,对好多pdf是无效的。
从未来补丁丁的兼容性出发,我建议你在项目中直接使用官方的5.5.13.4的源代码,引用官方BouncyCastle.Cryptography包,这样方便修补ItextSharp中的若干bugs,也方便加上AES-V3支持(可以实现读写)。
这样还能方便大家共同调试iTextSharp中的问题。...
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with iTextSharp\core\iTextSharp\text\pdf\PdfStamperImp.cs and inspect how encrypted readers are handled when saving without append mode. Reproduce the behavior with the attached unethicalreading.zip, then verify that saving can preserve or remove PDF permissions according to the proposed setting; no test file or existing test entry point is named.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100