简体   繁体   English

如何在 Android 上创建受密码保护的 PDF 的可编辑副本?

[英]How to create an editable copy of a password-protected PDF on Android?

Context语境

I'm using a third-party library called PsPdfKit to edit PDF files, adding annotations - like PNG images, and text decorations - on top of the PDF document.我正在使用名为PsPdfKit的第三方库来编辑 PDF 文件,在 PDF 文档的顶部添加注释 - 例如 PNG 图像和文本装饰。 But there's a limitation of this library where I'm not able to use this annotation feature on password-protected PDF files.但是这个库有一个限制,我不能在受密码保护的 PDF 文件上使用这个注释功能。 I can open and see the documents, but I'm unable to actually drop these annotations in. What I'm trying to do now is to figure out whether could be possible to create an editable copy of the PDF file.我可以打开并查看文档,但实际上无法将这些注释放入其中。我现在要做的是弄清楚是否可以创建 PDF 文件的可编辑副本。

Question问题

Is there any way on Android to create an editable copy of a password protected PDF file? Android 上是否有任何方法可以创建受密码保护的 PDF 文件的可编辑副本? Again, these password protected PDF files are only preventing writing any changes on top of the PDF, you don't actually need a password to see the PDF content.同样,这些受密码保护的 PDF 文件只会阻止在 PDF 上写入任何更改,您实际上不需要密码即可查看 PDF 内容。

My idea is to create an editable copy of the PDF file and then pass that copy to the PsPdfKit library.我的想法是创建 PDF 文件的可编辑副本,然后将该副本传递给 PsPdfKit 库。

Okay, so I've finally figured out a workaround for this issue.好的,所以我终于找到了解决此问题的方法。 What I did was to instantiate the password protected PDF file via PsPdfKit and then create a writeable copy of the file using the page bitmaps of the password protected file.我所做的是通过 PsPdfKit 实例化受密码保护的 PDF 文件,然后使用受密码保护文件的页面位图创建文件的可写副本。 A bit of a hacky solution, but it did allow me to use the annotation feature.有点笨拙的解决方案,但它确实允许我使用注释功能。

// We open the password-protected file.
val readOnlyPdfDocument = PdfDocumentLoader.openDocument(applicationContext, readOnlyFile.toUri())
// Use the PsPdfKit API to create a copy of the pages of this document
val task = PdfProcessorTask.newPage(NewPage.fromPage(readOnlyPdfDocument, 0).backgroundColor(Color.RED).build())
for (i in 1 until readOnlyPdfDocument.pageCount) {
   task.addNewPage(NewPage.fromPage(readOnlyPdfDocument, i).backgroundColor(Color.RED).build(), i)
}
// Finally store the writeable PDF document in a new file
val writeableFile = File(applicationContext.cacheDir, "Writeable.pdf")
PdfProcessor.processDocument(task, writeableFile)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何创建普通的受密码保护的 ZIP 存档? - How to create a normal password-protected ZIP archive? 被Android访问时受密码保护的网页 - Password-protected web pages when accessed by Android Android签名错误:受信任的证书条目未受密码保护 - Android signing error: trusted certificate entries are not password-protected Android:使用Eclipse和受密码保护的密钥库在设备上调试应用程序? - Android: debug app on device with Eclipse and password-protected keystore? 如何使用Java解压缩由Linux创建的受密码保护的存档 - How to unzip a password-protected archive created by Linux, using Java 如何在android中读取受密码保护/从pdf中删除密码? - How to read password protected/ remove password from pdf in android? 以给定密码以编程方式打开受密码保护的SQLite数据库 - Programmatically open password-protected SQLite database with given password 如何通过以编程方式在Android应用程序中提供密码来打开受密码保护的pdf文件 - How to open password protected pdf file by providing password in android application programmatically 如何使用 MuPDF 打开受密码保护的 PDF - How to open password protected PDF using MuPDF 如何打开受编程保护的 PDF 文件 [不受密码保护] - How to open a programmatically protected PDF file [Not password protected]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM