Package org.apache.pdfbox.pdmodel

Examples of org.apache.pdfbox.pdmodel.PDDocumentCatalog


        PDDocument doc = new PDDocument();
        try
        {
            //OCGs have been introduced with PDF 1.5
            doc.getDocument().setHeaderString("%PDF-1.5");
            PDDocumentCatalog catalog = doc.getDocumentCatalog();
            catalog.setVersion("1.5");

            //Create new page
            PDPage page = new PDPage();
            doc.addPage(page);
            PDResources resources = page.findResources();
            if( resources == null )
            {
                resources = new PDResources();
                page.setResources( resources );
            }

            //Prepare OCG functionality
            PDOptionalContentProperties ocprops = new PDOptionalContentProperties();
            catalog.setOCProperties(ocprops);
            //ocprops.setBaseState(BaseState.ON); //ON=default

            //Create OCG for background
            PDOptionalContentGroup background = new PDOptionalContentGroup("background");
            ocprops.addGroup(background);
View Full Code Here


        PDDocument doc = PDDocument.load(pdfFile);
        try
        {
            assertEquals("%PDF-1.5", doc.getDocument().getHeaderString());
            PDDocumentCatalog catalog = doc.getDocumentCatalog();
            assertEquals("1.5", catalog.getVersion());

            PDPage page = (PDPage)catalog.getAllPages().get(0);
            PDPropertyList props = page.findResources().getProperties();
            assertNotNull(props);
            PDOptionalContentGroup ocg = props.getOptionalContentGroup(COSName.getPDFName("MC0"));
            assertNotNull(ocg);
            assertEquals("background", ocg.getName());

            assertNull(props.getOptionalContentGroup(COSName.getPDFName("inexistent")));

            PDOptionalContentProperties ocgs = catalog.getOCProperties();
            assertEquals(BaseState.ON, ocgs.getBaseState());
            Set<String> names = new java.util.HashSet<String>(Arrays.asList(ocgs.getGroupNames()));
            assertEquals(3, names.size());
            assertTrue(names.contains("background"));
View Full Code Here

     */
    public PDOptionalContentGroup appendFormAsLayer(PDPage targetPage,
            PDXObjectForm form, AffineTransform transform,
            String layerName) throws IOException
    {
        PDDocumentCatalog catalog = targetDoc.getDocumentCatalog();
        PDOptionalContentProperties ocprops = catalog.getOCProperties();
        if (ocprops == null)
        {
            ocprops = new PDOptionalContentProperties();
            catalog.setOCProperties(ocprops);
        }
        if (ocprops.hasGroup(layerName))
        {
            throw new IllegalArgumentException("Optional group (layer) already exists: " + layerName);
        }
View Full Code Here

    public PDDocument overlay( PDDocument overlay, PDDocument destination ) throws IOException
    {
        pdfOverlay = overlay;
        pdfDocument = destination;

        PDDocumentCatalog overlayCatalog = pdfOverlay.getDocumentCatalog();
        collectLayoutPages( overlayCatalog.getAllPages() );

        COSDictionary saveGraphicsStateDic = new COSDictionary();
        saveGraphicsStateStream = new COSStream( saveGraphicsStateDic, pdfDocument.getDocument().getScratchFile() );
        OutputStream saveStream = saveGraphicsStateStream.createUnfilteredStream();
        saveStream.write( " q\n".getBytes() );
        saveStream.flush();

        restoreGraphicsStateStream = new COSStream( saveGraphicsStateDic, pdfDocument.getDocument().getScratchFile() );
        OutputStream restoreStream = restoreGraphicsStateStream.createUnfilteredStream();
        restoreStream.write( " Q\n".getBytes() );
        restoreStream.flush();


        PDDocumentCatalog pdfCatalog = pdfDocument.getDocumentCatalog();
        processPages( pdfCatalog.getAllPages() );

        return pdfDocument;
    }
View Full Code Here

      reader.close();
        pdfDoc.close();
       
        // In order for the PDF document to be openable by Adobe Reader, it needs
        // to have some pages in it. So we'll check that.
        PDDocumentCatalog docCatalog = pdfDoc.getDocumentCatalog();
        List allPages = docCatalog.getAllPages();
        assertNotNull("All Pages was unexpectedly null.", allPages);
        assertEquals("Wrong number of pages.", 1, allPages.size());
    }
View Full Code Here

        PDDocument overlay1Doc = PDDocument.load(overlay1);
        try
        {
            LayerUtility layerUtil = new LayerUtility(targetDoc);
            PDXObjectForm form = layerUtil.importPageAsForm(overlay1Doc, 0);
            PDDocumentCatalog catalog = targetDoc.getDocumentCatalog();
            PDPage targetPage = (PDPage)catalog.getAllPages().get(0);
            layerUtil.wrapInSaveRestore(targetPage);
            AffineTransform at = new AffineTransform();
            PDOptionalContentGroup ocg = layerUtil.appendFormAsLayer(
                    targetPage, form, at, "overlay");

            //This is how the layer could be disabled after adding it
            //catalog.getOCProperties().setGroupEnabled(ocg.getName(), false);

            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
            //TODO need some comfortable way to enable/check the PDF version
            //assertEquals("%PDF-1.5", doc.getDocument().getHeaderString());
            //assertEquals("1.5", catalog.getVersion());

            PDPage page = (PDPage)catalog.getAllPages().get(0);
            PDPropertyList props = page.findResources().getProperties();
            assertNotNull(props);
            PDOptionalContentGroup ocg = props.getOptionalContentGroup(COSName.getPDFName("MC0"));
            assertNotNull(ocg);
            assertEquals("overlay", ocg.getName());

            PDOptionalContentProperties ocgs = catalog.getOCProperties();
            PDOptionalContentGroup overlay = ocgs.getGroup("overlay");
            assertEquals(ocg.getName(), overlay.getName());
        }
        finally
        {
View Full Code Here

                    catch( org.apache.pdfbox.exceptions.CryptographyException e )
                    {
                        e.printStackTrace();
                    }
                }
                PDDocumentCatalog catalog = document.getDocumentCatalog();
                PDMetadata meta = catalog.getMetadata();
                if ( meta != null)
                {
                    XMPMetadata metadata = meta.exportXMPMetadata();
   
                    XMPSchemaDublinCore dc = metadata.getDublinCoreSchema();
View Full Code Here

     *
     * @throws IOException If there is an error setting the data in the field.
     */
    public void importFDF( PDDocument pdfDocument, FDFDocument fdfDocument ) throws IOException
    {
        PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
        PDAcroForm acroForm = docCatalog.getAcroForm();
        acroForm.setCacheFields( true );
        acroForm.importFDF( fdfDocument );
    }
View Full Code Here

     * @throws IOException If there is an error getting the page count.
     */
    public void printMetadata( PDDocument document ) throws IOException
    {
        PDDocumentInformation info = document.getDocumentInformation();
        PDDocumentCatalog cat = document.getDocumentCatalog();
        PDMetadata metadata = cat.getMetadata();
        System.out.println( "Page Count=" + document.getNumberOfPages() );
        System.out.println( "Title=" + info.getTitle() );
        System.out.println( "Author=" + info.getAuthor() );
        System.out.println( "Subject=" + info.getSubject() );
        System.out.println( "Keywords=" + info.getKeywords() );
View Full Code Here

     *
     * @throws IOException If there is an error setting the field.
     */
    public void setField( PDDocument pdfDocument, String name, String value ) throws IOException
    {
        PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
        PDAcroForm acroForm = docCatalog.getAcroForm();
        PDField field = acroForm.getField( name );
        if( field != null )
        {
            field.setValue( value );
        }
View Full Code Here

TOP

Related Classes of org.apache.pdfbox.pdmodel.PDDocumentCatalog

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.