/** * Creates an instance of the concatenation class. * @param os the OutputStream for the PDF document * @param smart do we want PdfCopy to detect redundant content? */ public PdfConcatenate(OutputStream os, boolean smart) throws DocumentException { document = new Document(); if (smart) copy = new PdfSmartCopy(document, os); else copy = new PdfCopy(document, os); }
/** * Creates an instance of the concatenation class. * @param os the OutputStream for the PDF document * @param smart do we want PdfCopy to detect redundant content? */ public PdfConcatenate(OutputStream os, boolean smart) throws DocumentException { document = new Document(); if (smart) copy = new PdfSmartCopy(document, os); else copy = new PdfCopy(document, os); }
public ArrayList<String> splitPDF(String path) { ArrayList<String> outputPaths = new ArrayList<>(); try { String folderPath = mSharedPreferences.getString(STORAGE_LOCATION, getDefaultStorageLocation()); PdfReader reader = new PdfReader(path); PdfCopy copy; Document document; int pages = reader.getNumberOfPages(); for (int i = 1; i <= pages; i++) { document = new Document(); String fileName = folderPath + FileUtils.getFileName(path); fileName = fileName.replace(mContext.getString(R.string.pdf_ext), i + mContext.getString(R.string.pdf_ext)); Log.v("splitting", fileName); copy = new PdfCopy(document, new FileOutputStream(fileName)); document.open(); copy.addPage(copy.getImportedPage(reader, i)); document.close(); outputPaths.add(fileName); new DatabaseHelper(mContext).insertRecord(fileName, mContext.getString(R.string.created)); } } catch (IOException | DocumentException e) { e.printStackTrace(); showSnackbar(mContext, R.string.file_access_error); } return outputPaths; }
PdfCopy copy = new PdfCopy(document, new FileOutputStream(mFinPath));
Document document = new Document(); PdfCopy copy = new PdfCopy(document, os);