I use the PDFBox function, such as convertToImage, everything works fine, but PDFBox does not clear the temporary files after the conversion. In my system in the directory for temporary files "/tmp" there are many files such us +~JF132216249314633400.tmp, they are deleted only after restarting my application, but when the application continues to work, temporary files are not deleted.
PDFBox version - 1.8.15
when I use this
page.convertToImage(BufferedImage.TYPE_INT_RGB, 300)
the PDFbox library creates tmp files such as "+~JF132216249314633400.tmp"
my method:
def splitPdfToImages(file: File): List[File] = {
val document = PDDocument.load(file)
val pages = (for (i <- 0 until document.getNumberOfPages)
yield document.getDocumentCatalog.getAllPages.get(i).asInstanceOf[PDPage]).toList
val imgFiles = pages.zipWithIndex.map { case (page, i) =>
val baos = IOUtils.createBAOS
ImageIO.write(page.convertToImage(BufferedImage.TYPE_INT_RGB, 300), "jpg", baos)
val bais = IOUtils.createBAIS(baos.toByteArray)
try {
val img = Image.fromStream(bais)
implicit val writer = JpegWriter().withCompression(100)
val tmpFile = File.createTempFile(s"""${file.getName.split("\\.").head}_$i""", file.getName.split("\\.").last)
img.output(tmpFile)
} finally {
baos.close()
bais.close()
}
}
document.close()
imgFiles
}
Please help me to solve this issue.
File.createTempFile
page.convertToImage(BufferedImage.TYPE_INT_RGB, 300)
I not know what file name is created and I can not to delete its.@BASEe]½FDSIGlÚÉ»ë(äGDEFÒêÕ¾\~GPOSÿ§¡ÜXGSUB#Iãµ4OS/2¼×òÈ
SVG Ôòû÷ÎÈcmapjÀg¾d5,cvt ¿qQH"fpgmY7OsgaspÿÿglyfÓiÙ]ñ¼headú7L6hhea3$hmtx1=ò(<loca÷ÄQl maxp4w¨ name¤»OHtpostæKf¼8Nprepú6ÀÄQBpÇ,ð_<õ èÑÁÇJÑÂ)»ÿ?þp$ ØþïXÿ?ÿ?r
file example