Cocoa PDFKit 解锁加密文件

发布于 2024-08-13 19:18:00 字数 381 浏览 13 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

作死小能手 2024-08-20 19:18:00

解锁 PDF 后,您需要使用以下方法将其写回文件:

writeToFile:withOptions:

writeToURL:withOptions:

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:

writeToFile:withOptions:

or

writeToURL:withOptions:

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."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文