Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. public static void concatenatePdfs(List<File> listOfPdfFiles, File outputFile) throws DocumentException, IOException {
  2. Document document = new Document();
  3. FileOutputStream outputStream = new FileOutputStream(outputFile);
  4. PdfWriter writer = PdfWriter.getInstance(document, outputStream);
  5. document.open();
  6. PdfContentByte cb = writer.getDirectContent();
  7. for (File inFile : listOfPdfFiles) {
  8. PdfReader reader = new PdfReader(inFile.getAbsolutePath());
  9. for (int i = 1; i <= reader.getNumberOfPages(); i++) {
  10. document.newPage();
  11. PdfImportedPage page = writer.getImportedPage(reader, i);
  12. cb.addTemplate(page, 0, 0);
  13. }
  14. }
  15. outputStream.flush();
  16. document.close();
  17. outputStream.close();
  18. }
  19.  
  20. Document document = new Document();
  21. PdfCopy copy = new PdfSmartCopy(document, new FileOutputStream(dest));
  22. document.open();
  23. PdfReader reader;
  24. String line = br.readLine();
  25. // loop over readers
  26. // add the PDF to PdfCopy
  27. reader = new PdfReader(baos.toByteArray());
  28. copy.addDocument(reader);
  29. reader.close();
  30. // end loop
  31. document.close();
  32.  
  33. public static void concatenatePdfs(List<File> listOfPdfFiles, File outputFile) throws DocumentException, IOException {
  34. Document document = new Document();
  35. FileOutputStream outputStream = new FileOutputStream(outputFile);
  36. PdfCopy copy = new PdfSmartCopy(document, outputStream);
  37. document.open();
  38. for (File inFile : listOfPdfFiles) {
  39. PdfReader reader = new PdfReader(inFile.getAbsolutePath());
  40. copy.addDocument(reader);
  41. reader.close();
  42. }
  43. document.close();
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement