List of usage examples for org.apache.pdfbox.io MemoryUsageSetting setupTempFileOnly
public static MemoryUsageSetting setupTempFileOnly()
From source file:org.opensingular.lib.commons.pdf.PDFUtil.java
License:Apache License
/** * Concatena os pdf em um nico PDF./* w ww. j a va2 s. co m*/ * @param pdfs * @return O arquivo retornado temporrio e deve ser apagado pelo solicitante para no deixa lixo. */ @Nonnull public File merge(@Nonnull List<InputStream> pdfs) throws SingularPDFException { try (TempFileProvider tmp = TempFileProvider.createForUseInTryClause(this)) { PDFMergerUtility pdfMergerUtility = new PDFMergerUtility(); pdfs.forEach(pdfMergerUtility::addSource); File tempMergedFile = tmp.createTempFileByDontPutOnDeleteList("merge.pdf"); try (FileOutputStream output = new FileOutputStream(tempMergedFile)) { pdfMergerUtility.setDestinationStream(output); pdfMergerUtility.mergeDocuments(MemoryUsageSetting.setupTempFileOnly()); return tempMergedFile; } } catch (Exception e) { throw new SingularPDFException("Erro realizando merge de arquivos PDF", e); } finally { for (InputStream in : pdfs) { try { in.close(); } catch (IOException e) { getLogger().error("Erro fechando inputStrem", e); } } } }