Package org.pdfbox.pdmodel

Examples of org.pdfbox.pdmodel.PDDocumentCatalog


     *
     * @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


     *
     * @throws IOException If there is an error getting the fields.
     */
    public void printFields( PDDocument pdfDocument ) throws IOException
    {
        PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
        PDAcroForm acroForm = docCatalog.getAcroForm();
        List fields = acroForm.getFields();
        Iterator fieldsIter = fields.iterator();
       
        System.out.println(new Integer(fields.size()).toString() + " top-level fields were found on the form");

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

        }
        PDDocumentInformation destInfo = destination.getDocumentInformation();
        PDDocumentInformation srcInfo = source.getDocumentInformation();
        destInfo.getDictionary().mergeInto( srcInfo.getDictionary() );
       
        PDDocumentCatalog destCatalog = destination.getDocumentCatalog();
        PDDocumentCatalog srcCatalog = source.getDocumentCatalog();

        if( destCatalog.getOpenAction() == null )
        {
            destCatalog.setOpenAction( srcCatalog.getOpenAction() );
        }

        PDAcroForm destAcroForm = destCatalog.getAcroForm();
        PDAcroForm srcAcroForm = srcCatalog.getAcroForm();
        if( destAcroForm == null )
        {
            cloneForNewDocument( destination, srcAcroForm );
            destCatalog.setAcroForm( srcAcroForm );
        }
        else
        {
            mergeAcroForm(destination, destAcroForm, srcAcroForm);
        }

        COSArray destThreads = (COSArray)destCatalog.getCOSDictionary().getDictionaryObject(
                COSName.getPDFName( "Threads" ));
        COSArray srcThreads = (COSArray)cloneForNewDocument(
                destination,
                destCatalog.getCOSDictionary().getDictionaryObject( COSName.getPDFName( "Threads" )));
        if( destThreads == null )
        {
            destCatalog.getCOSDictionary().setItem( COSName.getPDFName( "Threads" ), srcThreads );
        }
        else
        {
            destThreads.addAll( srcThreads );
        }

        COSName names = COSName.getPDFName( "Names" );
        PDDocumentNameDictionary destNames = destCatalog.getNames();
        PDDocumentNameDictionary srcNames = srcCatalog.getNames();
        if( srcNames != null )
        {
            if( destNames == null )
            {
                destCatalog.getCOSDictionary().setItem( names, cloneForNewDocument( destination, srcNames ) );
            }
            else
            {
                //warning, potential for collision here!!
                destNames.getCOSDictionary().mergeInto( (COSDictionary)cloneForNewDocument( destination, srcNames ) );
            }
        }
       
        PDDocumentOutline destOutline = destCatalog.getDocumentOutline();
        PDDocumentOutline srcOutline = srcCatalog.getDocumentOutline();
        if( srcOutline != null )
        {
            if( destOutline == null )
            {
                PDDocumentOutline cloned =
                    new PDDocumentOutline( (COSDictionary)cloneForNewDocument( destination, srcOutline ) );
                destCatalog.setDocumentOutline( cloned );
            }
            else
            {
                PDOutlineItem first = srcOutline.getFirstChild();
                PDOutlineItem clonedFirst = new PDOutlineItem( (COSDictionary)cloneForNewDocument(
                        destination, first ));
                destOutline.appendChild( clonedFirst );
            }
        }
       
        String destPageMode = destCatalog.getPageMode();
        String srcPageMode = srcCatalog.getPageMode();
        if( destPageMode == null )
        {
            destCatalog.setPageMode( srcPageMode );
        }

        COSName pageLabels = COSName.getPDFName( "PageLabels" );
        COSDictionary destLabels = (COSDictionary)destCatalog.getCOSDictionary().getDictionaryObject( pageLabels );
        COSDictionary srcLabels = (COSDictionary)srcCatalog.getCOSDictionary().getDictionaryObject( pageLabels );
        if( srcLabels != null )
        {
            int destPageCount = destination.getNumberOfPages();
            COSArray destNums = null;
            if( destLabels == null )
            {
                destLabels = new COSDictionary();
                destNums = new COSArray();
                destLabels.setItem( COSName.getPDFName( "Nums" ), destNums );
                destCatalog.getCOSDictionary().setItem( pageLabels, destLabels );
            }
            else
            {
                destNums = (COSArray)destLabels.getDictionaryObject( COSName.getPDFName( "Nums" ) );
            }
            COSArray srcNums = (COSArray)srcLabels.getDictionaryObject( COSName.getPDFName( "Nums" ) );
            for( int i=0; i<srcNums.size(); i+=2 )
            {
                COSNumber labelIndex = (COSNumber)srcNums.getObject( i );
                long labelIndexValue = labelIndex.intValue();
                destNums.add( new COSInteger( labelIndexValue + destPageCount ) );
                destNums.add( cloneForNewDocument( destination, srcNums.getObject( i+1 ) ) );
            }
        }
       
        COSName metadata = COSName.getPDFName( "Metadata" );
        COSStream destMetadata = (COSStream)destCatalog.getCOSDictionary().getDictionaryObject( metadata );
        COSStream srcMetadata = (COSStream)srcCatalog.getCOSDictionary().getDictionaryObject( metadata );
        if( destMetadata == null && srcMetadata != null )
        {
            PDStream newStream = new PDStream( destination, srcMetadata.getUnfilteredStream(), false );
            newStream.getStream().mergeInto( srcMetadata );
            newStream.addCompression();
View Full Code Here

                if( document.isEncrypted() )
                {
                    System.err.println( "Error: Cannot add metadata to encrypted document." );
                    System.exit( 1 );
                }
                PDDocumentCatalog catalog = document.getDocumentCatalog();
                PDDocumentInformation info = document.getDocumentInformation();
               
                //Right now, PDFBox does not have any XMP library, so we will
                //just consruct the XML by hand.
                StringBuffer xmp= new StringBuffer();
                xmp.append(
                "<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>\n" +
                "<?adobe-xap-filters esc=\"CRLF\"?>\n" +
                "<x:xmpmeta>\n" +
                "    <rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n" +
                "        <rdf:Description rdf:about='' xmlns:pdf='http://ns.adobe.com/pdf/1.3/' " +
                                         "pdf:Keywords='" + fixNull( info.getKeywords() ) + "' " +
                                         "pdf:Producer='" + fixNull( info.getProducer() ) + "'></rdf:Description>\n" +
                "        <rdf:Description rdf:about='' xmlns:xap='http://ns.adobe.com/xap/1.0/' " +
                                         "xap:ModifyDate='" + fixNull( info.getModificationDate() ) + "' " +
                                         "xap:CreateDate='" + fixNull( info.getCreationDate() ) + "' " +
                                         "xap:CreatorTool='" + fixNull( info.getCreator() ) + "' " +
                                         "xap:MetadataDate='" + fixNull( new GregorianCalendar() )+ "'>\n" +
                "        </rdf:Description>\n" +
                "        <rdf:Description rdf:about='' xmlns:dc='http://purl.org/dc/elements/1.1/' " +
                                         "dc:format='application/pdf'>\n" +
                "            <dc:title>\n" +
                "                <rdf:Alt>\n" +
                "                    <rdf:li xml:lang='x-default'>" + fixNull( info.getTitle() ) +"</rdf:li>\n" +
                "                </rdf:Alt>\n" +
                "            </dc:title>\n" +
                "            <dc:creator>\n" +
                "                <rdf:Seq>\n" +
                "                    <rdf:li>PDFBox.org</rdf:li>\n" +
                "                </rdf:Seq>\n" +
                "            </dc:creator>\n" +
                "            <dc:description>\n" +
                "                <rdf:Alt>\n" +
                "                    <rdf:li xml:lang='x-default'>" + fixNull( info.getSubject() ) +"</rdf:li>\n" +
                "                </rdf:Alt>\n" +
                "            </dc:description>\n" +
                "        </rdf:Description>\n" +
                "    </rdf:RDF>\n" +
                "</x:xmpmeta>\n" );
               
                //xmp spec says we should put padding, so that the metadata can be appended to
                //in place
                xmp.append( PADDING );
                xmp.append( PADDING );
                xmp.append( PADDING );
                xmp.append( "\n<?xpacket end='w'?>" );
                ByteArrayInputStream mdInput = new ByteArrayInputStream( xmp.toString().getBytes() );
                PDMetadata metadataStream = new PDMetadata(document, mdInput, false );
                catalog.setMetadata( metadataStream );
               
               
                document.save( args[1] );
            }
            finally
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 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

            FileWriter out = new FileWriter(outfile);
            PDFParser parser =
                    new PDFParser(new FileInputStream(infile));
            parser.parse();
            PDDocument document = parser.getPDDocument();
            PDDocumentCatalog catalog = document.getDocumentCatalog();
            int i = 0;
            for (Object page: catalog.getAllPages()) {
                i++;
                out.write("/Page " + i + " " + "/Rotate "
                        + ((PDPage)page).findRotation() + "\n");
            }
            document.close();
View Full Code Here

          throw new IOException(ex.getMessage());
        }
      }
 
      PDDocumentInformation info = doc.getDocumentInformation();
      PDDocumentCatalog catlog = doc.getDocumentCatalog();
      COSDocument cosDoc = doc.getDocument();   
     
      ctx.fireStartParseEvent("pdf-meta");
 
      COSArray array = cosDoc.getDocumentID();
      if(array != null && array.size() == 2) {
        ctx.fireParseEvent("doc-id", ((COSString) array.get(0)).getHexString());
        ctx.fireParseEvent("iteration-id", ((COSString) array.get(1)).getHexString());
      }
     
      if(array == null || array.size() != 2) {
        ctx.fireParseEvent("original", "unknown");
      }
      else {
        boolean orig = ((COSString) array.get(0)).getHexString().equals(((COSString) array.get(1)).getHexString());
        ctx.fireParseEvent("original", orig);
      }
     
      fireSpecialNull(ctx, "title", info.getTitle());
      fireSpecialNull(ctx, "language", catlog.getLanguage());
      fireSpecialNull(ctx, "author", info.getAuthor());
      fireSpecialNull(ctx, "creator", info.getCreator());
      fireSpecialNull(ctx, "subject", info.getSubject());
      fireSpecialNull(ctx, "producer", info.getProducer());
      fireSpecialNull(ctx, "keywords", info.getKeywords());   
     
      ctx.fireStartParseEvent("creation-date");
      fireDate(ctx, info.getCreationDate());
      ctx.fireEndParseEvent("creation-date");
     
      ctx.fireStartParseEvent("modified-date");
      fireDate(ctx, info.getModificationDate());
      ctx.fireEndParseEvent("modified-date");
     
      ctx.fireParseEvent("has-forms", catlog.getAcroForm() != null);
      ctx.fireParseEvent("has-metadata-stream", catlog.getMetadata() != null);
      ctx.fireParseEvent("has-outline", catlog.getDocumentOutline() != null);
      ctx.fireParseEvent("has-threads", catlog.getThreads().size() > 0);
      ctx.fireParseEvent("tagged", catlog.getMarkInfo() != null);
      fireSpecialNull(ctx, "page-layout", catlog.getPageLayout());
      fireSpecialNull(ctx, "page-mode", catlog.getPageMode());
      fireSpecialNull(ctx, "trapped", info.getTrapped());
     
      fireSpecialNull(ctx, "version", Float.toString(cosDoc.getVersion()));
     
      ctx.fireStartParseEvent("security");
View Full Code Here

     *
     * @param pdfDocument The PDF to get the fields from.
     */
    public void printFields( PDDocument pdfDocument )
    {
        PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
        PDAcroForm acroForm = docCatalog.getAcroForm();
        List fields = acroForm.getFields();
        Iterator fieldsIter = fields.iterator();

        while( fieldsIter.hasNext() )
        {
View Full Code Here

TOP

Related Classes of org.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.