Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void concatenatePdfs(List<File> listOfPdfFiles, File outputFile) throws DocumentException, IOException {
- Document document = new Document();
- FileOutputStream outputStream = new FileOutputStream(outputFile);
- PdfWriter writer = PdfWriter.getInstance(document, outputStream);
- document.open();
- PdfContentByte cb = writer.getDirectContent();
- for (File inFile : listOfPdfFiles) {
- PdfReader reader = new PdfReader(inFile.getAbsolutePath());
- for (int i = 1; i <= reader.getNumberOfPages(); i++) {
- document.newPage();
- PdfImportedPage page = writer.getImportedPage(reader, i);
- cb.addTemplate(page, 0, 0);
- }
- }
- outputStream.flush();
- document.close();
- outputStream.close();
- }
- Document document = new Document();
- PdfCopy copy = new PdfSmartCopy(document, new FileOutputStream(dest));
- document.open();
- PdfReader reader;
- String line = br.readLine();
- // loop over readers
- // add the PDF to PdfCopy
- reader = new PdfReader(baos.toByteArray());
- copy.addDocument(reader);
- reader.close();
- // end loop
- document.close();
- public static void concatenatePdfs(List<File> listOfPdfFiles, File outputFile) throws DocumentException, IOException {
- Document document = new Document();
- FileOutputStream outputStream = new FileOutputStream(outputFile);
- PdfCopy copy = new PdfSmartCopy(document, outputStream);
- document.open();
- for (File inFile : listOfPdfFiles) {
- PdfReader reader = new PdfReader(inFile.getAbsolutePath());
- copy.addDocument(reader);
- reader.close();
- }
- document.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement