Cocoa PDFKit 解锁加密文件
我有一个 PDF 文档,设置了所有者密码,但没有用户密码。因此它是加密的。
我知道所有者密码,并想使用 PDFKit 来确认文档何时已解密。
我使用了 PDFDocumentunlockWithPassword 方法,当文件解锁时该方法返回 YES。但是,当文件已通过用户密码而不是所有者密码解锁时,此方法也会返回 yes。
unlockWithPassword 方法似乎不会更改 isEncrpyted 方法的状态,我尝试使用该方法来确认解密。
我想解密该文件,以便我可以使用写入方法在没有安全性的情况下写入新文件。目前,在文档对象上调用此方法会导致创建零长度文件。我认为这是因为加密。
我是否以正确的方式处理此问题,或者我应该使用不同的方法来解密 pdf 文件。
I have a PDF document that has an owner password set but no user password. Therefore it is encrypted.
I know the owner password and want to use PDFKit to confirm when the document has been decrypted.
I have used the PDFDocument unlockWithPassword method which returns YES when the file is unlocked. However this method also returns yes when the file has been unlocked by a user password and not the owner password.
The unlockWithPassword method appears not to change the state of the isEncrpyted method which I tried to use to confirm the decryption.
I want to decrpyt the file so that I can use the write methods to write a new file with no security. At the moment calling this method on the document object results in a zero length file being created. I assume this is because of the encryption.
Am I going about this the right way or should I be using a different method for decrypting the pdf file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解锁 PDF 后,您需要使用以下方法将其写回文件:
或
Options 作为
NSDictionary
。根据 Apple 的说法:
最常用的选项是 kCGPDFContextOwnerPassword、kCGPDFContextUserPassword、kCGPDFContextAllowsCopying 和 kCGPDFContextAllowsPrinting。
“有关这些选项的更多详细信息,请参阅 CGPDFContext Reference 中的辅助字典键, Quartz 2D 参考的一部分。”
Once you unlock the PDF, you will need to write it back to a file using:
or
Options being an
NSDictionary
.According to Apple:
The most commonly-used options are kCGPDFContextOwnerPassword, kCGPDFContextUserPassword, kCGPDFContextAllowsCopying and kCGPDFContextAllowsPrinting.
"For more details about these options, see the Auxiliary Dictionary Keys in CGPDFContext Reference, part of the Quartz 2D Reference."