Skip to content

Commit

Permalink
Return original pdf if unable to alter title using pdfbox.
Browse files Browse the repository at this point in the history
Co-authored-by: Andreas Jonsson <[email protected]>
  • Loading branch information
oyvind-wedoe and flexable777 committed Apr 30, 2024
1 parent d58b1bd commit 5bb4e08
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/main/kotlin/no/nav/klage/oppgave/service/DokumentService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,24 @@ class DokumentService(
}

fun changeTitleInPDF(documentBytes: ByteArray, title: String): ByteArray {
val baos = ByteArrayOutputStream()
val timeMillis = measureTimeMillis {
val document: PDDocument =
Loader.loadPDF(RandomAccessReadBuffer(documentBytes), getMixedMemorySettingsForPDFBox(50_000_000))

val info: PDDocumentInformation = document.documentInformation
info.title = title
document.isAllSecurityToBeRemoved = true
document.save(baos)
document.close()
try {
val baos = ByteArrayOutputStream()
val timeMillis = measureTimeMillis {
val document: PDDocument =
Loader.loadPDF(RandomAccessReadBuffer(documentBytes), getMixedMemorySettingsForPDFBox(50_000_000))

val info: PDDocumentInformation = document.documentInformation
info.title = title
document.isAllSecurityToBeRemoved = true
document.save(baos)
document.close()
}
secureLogger.debug("changeTitleInPDF with title $title took $timeMillis ms")
return baos.toByteArray()
} catch (e: Exception) {
secureLogger.warn("Unable to change title for pdf content", e)
return documentBytes
}
secureLogger.debug("changeTitleInPDF with title $title took $timeMillis ms")
return baos.toByteArray()
}

fun getDokumentReferanse(journalpostId: String, behandling: Behandling): DokumentReferanse {
Expand Down

0 comments on commit 5bb4e08

Please sign in to comment.