List of usage examples for org.apache.pdfbox.multipdf PDFMergerUtility setDestinationStream
public void setDestinationStream(OutputStream destStream)
From source file:io.github.qwefgh90.akka.pdf.PDFUtilWrapper.java
License:Apache License
private static PDFMergerUtility createPDFMergerUtility(List<InputStream> sources, ByteArrayOutputStream mergedPDFOutputStream) { LOG.info("Initialising PDF merge utility"); PDFMergerUtility pdfMerger = new PDFMergerUtility(); pdfMerger.addSources(sources);//from ww w . j av a 2 s. co m pdfMerger.setDestinationStream(mergedPDFOutputStream); return pdfMerger; }
From source file:org.egov.infra.utils.PdfUtils.java
License:Open Source License
public static byte[] appendFiles(List<InputStream> pdfStreams) { try (ByteArrayOutputStream destination = new ByteArrayOutputStream()) { PDFMergerUtility pdfMerger = new PDFMergerUtility(); pdfMerger.setDestinationStream(destination); pdfStreams.forEach(pdfMerger::addSource); pdfMerger.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly()); return destination.toByteArray(); } catch (IOException e) { throw new ApplicationRuntimeException("Error occurred while merging pdf files", e); }//w w w . j a va 2s. co m }
From source file:org.opensingular.lib.commons.pdf.PDFUtil.java
License:Apache License
/** * Concatena os pdf em um nico PDF.//from w ww . j ava 2 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); } } } }
From source file:us.kagome.pdfbox.PDFMergerExample.java
License:Apache License
private PDFMergerUtility createPDFMergerUtility(List<InputStream> sources, ByteArrayOutputStream mergedPDFOutputStream) { LOG.info("Initialising PDF merge utility"); PDFMergerUtility pdfMerger = new PDFMergerUtility(); pdfMerger.addSources(sources);//w w w . j av a2s. c o m pdfMerger.setDestinationStream(mergedPDFOutputStream); return pdfMerger; }