[英]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.