Search in sources :

Example 76 with PDDocument

use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.

the class TestRendering method render.

public void render(File file) throws IOException {
    PDDocument document = PDDocument.load(file);
    render(document, file.getName());
}
Also used : PDDocument(com.tom_roush.pdfbox.pdmodel.PDDocument)

Example 77 with PDDocument

use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.

the class TestRendering method render.

public void render(String fileName) throws IOException {
    PDDocument document = PDDocument.load(testContext.getAssets().open(fileName));
    render(document, fileName.substring(fileName.lastIndexOf("/") + 1));
}
Also used : PDDocument(com.tom_roush.pdfbox.pdmodel.PDDocument)

Example 78 with PDDocument

use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.

the class PDVisibleSigBuilder method createTemplate.

/**
 * Creates a PDDocument and adds the page parameter to it and keeps this as a template in the
 * PDF template Structure.
 *
 * @param page
 * @throws IOException
 */
@Override
public void createTemplate(PDPage page) throws IOException {
    PDDocument template = new PDDocument();
    template.addPage(page);
    pdfStructure.setTemplate(template);
}
Also used : PDDocument(com.tom_roush.pdfbox.pdmodel.PDDocument)

Example 79 with PDDocument

use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.

the class PDVisibleSignDesigner method calculatePageSizeFromStream.

private void calculatePageSizeFromStream(InputStream documentStream, int page) throws IOException {
    // create PD document
    PDDocument document = PDDocument.load(documentStream);
    // calculate height and width of document page
    calculatePageSize(document, page);
    document.close();
}
Also used : PDDocument(com.tom_roush.pdfbox.pdmodel.PDDocument)

Example 80 with PDDocument

use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.

the class TestLayerUtility method testLayerImport.

/**
 * Tests layer import.
 *
 * @throws Exception if an error occurs
 */
public void testLayerImport() throws Exception {
    File mainPDF = createMainPDF();
    File overlay1 = createOverlay1();
    File targetFile = new File(testResultsDir, "text-with-form-overlay.pdf");
    PDDocument targetDoc = PDDocument.load(mainPDF);
    PDDocument overlay1Doc = PDDocument.load(overlay1);
    try {
        LayerUtility layerUtil = new LayerUtility(targetDoc);
        PDFormXObject form = layerUtil.importPageAsForm(overlay1Doc, 0);
        PDPage targetPage = targetDoc.getPage(0);
        layerUtil.wrapInSaveRestore(targetPage);
        AffineTransform at = new AffineTransform();
        layerUtil.appendFormAsLayer(targetPage, form, at, "overlay");
        targetDoc.save(targetFile.getAbsolutePath());
    } finally {
        targetDoc.close();
        overlay1Doc.close();
    }
    PDDocument doc = PDDocument.load(targetFile);
    try {
        PDDocumentCatalog catalog = doc.getDocumentCatalog();
        // OCGs require PDF 1.5 or later
        assertEquals(1.5f, doc.getVersion());
        PDPage page = doc.getPage(0);
        PDOptionalContentGroup ocg = (PDOptionalContentGroup) page.getResources().getProperties(COSName.getPDFName("oc1"));
        assertNotNull(ocg);
        assertEquals("overlay", ocg.getName());
        PDOptionalContentProperties ocgs = catalog.getOCProperties();
        PDOptionalContentGroup overlay = ocgs.getGroup("overlay");
        assertEquals(ocg.getName(), overlay.getName());
    } finally {
        doc.close();
    }
}
Also used : PDPage(com.tom_roush.pdfbox.pdmodel.PDPage) PDDocument(com.tom_roush.pdfbox.pdmodel.PDDocument) PDOptionalContentGroup(com.tom_roush.pdfbox.pdmodel.graphics.optionalcontent.PDOptionalContentGroup) PDFormXObject(com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject) AffineTransform(com.tom_roush.harmony.awt.geom.AffineTransform) PDOptionalContentProperties(com.tom_roush.pdfbox.pdmodel.graphics.optionalcontent.PDOptionalContentProperties) File(java.io.File) PDDocumentCatalog(com.tom_roush.pdfbox.pdmodel.PDDocumentCatalog)

Aggregations

PDDocument (com.tom_roush.pdfbox.pdmodel.PDDocument)137 File (java.io.File)80 Test (org.junit.Test)69 PDPage (com.tom_roush.pdfbox.pdmodel.PDPage)37 PDPageContentStream (com.tom_roush.pdfbox.pdmodel.PDPageContentStream)22 InputStream (java.io.InputStream)21 Bitmap (android.graphics.Bitmap)18 IOException (java.io.IOException)14 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)11 PDFRenderer (com.tom_roush.pdfbox.rendering.PDFRenderer)11 ArrayList (java.util.ArrayList)11 PDDocumentCatalog (com.tom_roush.pdfbox.pdmodel.PDDocumentCatalog)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 FileInputStream (java.io.FileInputStream)9 FileOutputStream (java.io.FileOutputStream)9 COSArray (com.tom_roush.pdfbox.cos.COSArray)8 PDEmbeddedFile (com.tom_roush.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile)8 PDFont (com.tom_roush.pdfbox.pdmodel.font.PDFont)8 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)7 Paint (android.graphics.Paint)6