Update pdfbox to 3.0.0

This commit is contained in:
eikek
2023-11-05 23:34:51 +01:00
parent 84612bc7e7
commit fe4a300b0e
6 changed files with 18 additions and 33 deletions

View File

@ -16,6 +16,7 @@ import docspell.logging.Logger
import org.apache.pdfbox.pdmodel.PDDocument
import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException
import org.apache.pdfbox.{Loader => PdfboxLoader}
/** Using PDFBox, the incoming pdf is loaded while trying the given passwords. */
object RemovePdfEncryption {
@ -76,7 +77,7 @@ object RemovePdfEncryption {
}
private def load(bytes: Array[Byte], pw: Password): Option[PDDocument] =
try Option(PDDocument.load(bytes, pw.pass))
try Option(PdfboxLoader.loadPDF(bytes, pw.pass))
catch {
case _: InvalidPasswordException =>
None

View File

@ -22,8 +22,8 @@ import docspell.common.util.File
import docspell.convert.ConversionResult.Handler
import docspell.files.TikaMimetype
import org.apache.pdfbox.pdmodel.PDDocument
import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException
import org.apache.pdfbox.{Loader => PdfboxLoader}
trait FileChecks {
@ -42,7 +42,7 @@ trait FileChecks {
isType(MimeType.text("plain"))
def isUnencryptedPDF: Boolean =
Try(PDDocument.load(p.toNioPath.toFile)).map(_.close()).isSuccess
Try(PdfboxLoader.loadPDF(p.toNioPath.toFile)).map(_.close()).isSuccess
}
implicit class ByteStreamOps(delegate: Stream[IO, Byte]) {
@ -58,14 +58,14 @@ trait FileChecks {
def isUnencryptedPDF: IO[Boolean] =
delegate.compile
.to(Array)
.map(PDDocument.load(_))
.map(PdfboxLoader.loadPDF)
.map(_.close())
.map(_ => true)
def isEncryptedPDF: IO[Boolean] =
delegate.compile
.to(Array)
.map(PDDocument.load(_))
.map(PdfboxLoader.loadPDF)
.attempt
.map(e =>
e.fold(