use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.
the class Overlay method overlayDocuments.
/**
* This will add overlays documents to a document.
*
* @param specificPageOverlayDocuments Optional map of overlay documents for specific pages. The
* page numbers are 1-based. The map must be empty (but not null) if no specific mappings are
* used.
*
* @return The modified input PDF document, which has to be saved and closed by the caller. If
* the input document was passed by {@link #setInputPDF(PDDocument) setInputPDF(PDDocument)}
* then it is that object that is returned.
*
* @throws IOException if something went wrong
*/
public PDDocument overlayDocuments(Map<Integer, PDDocument> specificPageOverlayDocuments) throws IOException {
loadPDFs();
for (Map.Entry<Integer, PDDocument> e : specificPageOverlayDocuments.entrySet()) {
PDDocument doc = e.getValue();
if (doc != null) {
specificPageOverlayPage.put(e.getKey(), getLayoutPage(doc));
}
}
processPages(inputPDFDocument);
return inputPDFDocument;
}
use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.
the class Overlay method overlay.
/**
* This will add overlays to a document.
*
* @param specificPageOverlayFile Optional map of overlay files for specific pages. The page
* numbers are 1-based. The map must be empty (but not null) if no specific mappings are used.
*
* @return The modified input PDF document, which has to be saved and closed by the caller. If
* the input document was passed by {@link #setInputPDF(PDDocument) setInputPDF(PDDocument)}
* then it is that object that is returned.
*
* @throws IOException if something went wrong
*/
public PDDocument overlay(Map<Integer, String> specificPageOverlayFile) throws IOException {
Map<String, PDDocument> loadedDocuments = new HashMap<String, PDDocument>();
Map<PDDocument, LayoutPage> layouts = new HashMap<PDDocument, LayoutPage>();
loadPDFs();
for (Map.Entry<Integer, String> e : specificPageOverlayFile.entrySet()) {
PDDocument doc = loadedDocuments.get(e.getValue());
if (doc == null) {
doc = loadPDF(e.getValue());
loadedDocuments.put(e.getValue(), doc);
layouts.put(doc, getLayoutPage(doc));
}
openDocuments.add(doc);
specificPageOverlayPage.put(e.getKey(), layouts.get(doc));
}
processPages(inputPDFDocument);
return inputPDFDocument;
}
use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.
the class PDFMergerUtility method optimizedMergeDocuments.
private void optimizedMergeDocuments(MemoryUsageSetting memUsageSetting) throws IOException {
PDDocument destination = null;
try {
destination = new PDDocument(memUsageSetting);
PDFCloneUtility cloner = new PDFCloneUtility(destination);
for (Object sourceObject : sources) {
PDDocument sourceDoc = null;
try {
if (sourceObject instanceof File) {
sourceDoc = PDDocument.load((File) sourceObject, memUsageSetting);
} else {
sourceDoc = PDDocument.load((InputStream) sourceObject, memUsageSetting);
}
for (PDPage page : sourceDoc.getPages()) {
PDPage newPage = new PDPage((COSDictionary) cloner.cloneForNewDocument(page.getCOSObject()));
newPage.setCropBox(page.getCropBox());
newPage.setMediaBox(page.getMediaBox());
newPage.setRotation(page.getRotation());
PDResources resources = page.getResources();
if (resources != null) {
// this is smart enough to just create references for resources that are used on multiple pages
newPage.setResources(new PDResources((COSDictionary) cloner.cloneForNewDocument(resources)));
} else {
newPage.setResources(new PDResources());
}
destination.addPage(newPage);
}
} finally {
IOUtils.closeQuietly(sourceDoc);
}
}
if (destinationStream == null) {
destination.save(destinationFileName);
} else {
destination.save(destinationStream);
}
} finally {
IOUtils.closeQuietly(destination);
}
}
use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.
the class PDFParser method getPDDocument.
/**
* This will get the PD document that was parsed. When you are done with
* this document you must call close() on it to release resources.
*
* @return The document at the PD layer.
*
* @throws IOException If there is an error getting the document.
*/
public PDDocument getPDDocument() throws IOException {
PDDocument doc = new PDDocument(getDocument(), source, getAccessPermission());
doc.setEncryptionDictionary(getEncryption());
return doc;
}
use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.
the class PDAcroFormTest method setUp.
@Before
public void setUp() {
document = new PDDocument();
acroForm = new PDAcroForm(document);
document.getDocumentCatalog().setAcroForm(acroForm);
}
Aggregations