嗨,我正在研究简单的功能,它可以将所有 jpg 文件保存为 pdf(使用openpdf)。每个图像都应该适合页面,并且在它们之间我想要一个空白页面。我已经有了:
def createFromImage(directory: String, targetFile: String): Unit = {
logger.info(s"Create pdf from images in $directory.")
val document = new Document()
PdfWriter.getInstance(document, new FileOutputStream(targetFile))
document.open()
val resultFiles = new File(directory).listFiles().toList.map(_.getAbsolutePath)
resultFiles.filter(x => x.contains(".jpg")).map {
file =>
import com.lowagie.text.Image
val jpg: Image = Image.getInstance(file)
document.setPageSize(PageSize.A4)
val ratio: Float = PageSize.A4.getWidth / jpg.getWidth
jpg.scalePercent(ratio * 100)
document.add(jpg)
}
document.close()
logger.info("Pdf created.")
}
如何添加空白页document
?