Package org.apache.pdfbox.cos

Examples of org.apache.pdfbox.cos.COSDocument


            co.setGenerationNumber(COSInteger.ZERO);
            co.setObjectNumber(COSInteger.get(10));

            assertFalse(COSUtils.isInteger(co, new IOCOSDocument()));

            COSDocument doc = new COSDocument();
            addToXref(doc, new COSObjectKey(co), 1000);
            COSUtils.isInteger(co, doc);
            doc.close();
        }
        catch (IOException e)
        {
            fail(e.getMessage());
        }
View Full Code Here


            co.setGenerationNumber(COSInteger.ZERO);
            co.setObjectNumber(COSInteger.get(10));

            assertFalse(COSUtils.isFloat(co, new IOCOSDocument()));

            COSDocument doc = new COSDocument();
            addToXref(doc, new COSObjectKey(co), 1000);
            COSUtils.isFloat(co, doc);
            doc.close();
        }
        catch (IOException e)
        {
            fail(e.getMessage());
        }
View Full Code Here

            co.setGenerationNumber(COSInteger.ZERO);
            co.setObjectNumber(COSInteger.get(10));

            assertFalse(COSUtils.isString(co, new IOCOSDocument()));

            COSDocument doc = new COSDocument();
            addToXref(doc, new COSObjectKey(co), 1000);
            COSUtils.isString(co, doc);
            doc.close();
        }
        catch (IOException e)
        {
            fail(e.getMessage());
        }
View Full Code Here

            co.setGenerationNumber(COSInteger.ZERO);
            co.setObjectNumber(COSInteger.get(10));

            assertFalse(COSUtils.isStream(co, new IOCOSDocument()));

            COSDocument doc = new COSDocument();
            addToXref(doc, new COSObjectKey(co), 1000);
            COSUtils.isStream(co, doc);
            doc.close();
        }
        catch (IOException e)
        {
            fail(e.getMessage());
        }
View Full Code Here

            co.setGenerationNumber(COSInteger.ZERO);
            co.setObjectNumber(COSInteger.get(10));

            assertFalse(COSUtils.isDictionary(co, new IOCOSDocument()));

            COSDocument doc = new COSDocument();
            addToXref(doc, new COSObjectKey(co), 1000);
            COSUtils.isDictionary(co, doc);
            doc.close();
        }
        catch (IOException e)
        {
            fail(e.getMessage());
        }
View Full Code Here

            co.setGenerationNumber(COSInteger.ZERO);
            co.setObjectNumber(COSInteger.get(10));

            assertFalse(COSUtils.isArray(co, new IOCOSDocument()));

            COSDocument doc = new COSDocument();
            addToXref(doc, new COSObjectKey(co), 1000);
            COSUtils.isArray(co, doc);
            doc.close();
        }
        catch (IOException e)
        {
            fail(e.getMessage());
        }
View Full Code Here

     *
     * @throws IOException If there is an error while parsing the visual signature.
     */
    public void parse() throws IOException
    {
        document = new COSDocument();
        skipToNextObj();

        boolean wasLastParsedObjectEOF = false;
        try
        {
View Full Code Here

    {
      try
      {
        if (doc != null)
        {
          COSDocument cosDoc = doc.getDocument();
         
          Map<COSObjectKey, Long> xrefTable = cosDoc.getXrefTable();
          Set<COSObjectKey> keySet = xrefTable.keySet();
          long highestNumber=0;
          for ( COSObjectKey cosObjectKey : keySet )
          {
            COSBase object = cosDoc.getObjectFromPool(cosObjectKey).getObject();
            if (object != null && cosObjectKey!= null && !(object instanceof COSNumber))
            {
            objectKeys.put(object, cosObjectKey);
            keyObject.put(cosObjectKey,object);
            }
View Full Code Here

        if(doc.isAllSecurityToBeRemoved())
        {
            willEncrypt = false;
            // also need to get rid of the "Encrypt" in the trailer so readers
            // don't try to decrypt a document which is not encrypted
            COSDocument cosDoc = doc.getDocument();
            COSDictionary trailer = cosDoc.getTrailer();
            trailer.removeItem(COSName.ENCRYPT);
        }
        else
        {
            if (document.getEncryption() != null)
            {
                SecurityHandler securityHandler = document.getEncryption().getSecurityHandler();
                if(securityHandler != null)
                {
                    securityHandler.prepareDocumentForEncryption(document);
                    willEncrypt = true;
                }
                else
                {
                    willEncrypt = false;
                }
            }
            else
            {
                willEncrypt = false;
            }
        }

        COSDocument cosDoc = document.getDocument();
        COSDictionary trailer = cosDoc.getTrailer();
        COSArray idArray = (COSArray)trailer.getDictionaryObject( COSName.ID );
        boolean missingID = true;
        // check for an existing documentID
        if (idArray != null && idArray.size() == 2)
        {
            missingID = false;
        }
        if( missingID || incrementalUpdate)
        {
            MessageDigest md5;
            try
            {
                md5 = MessageDigest.getInstance("MD5");
            }
            catch (NoSuchAlgorithmException e)
            {
                // should never happen
                throw new RuntimeException(e);
            }

            // algorithm says to use time/path/size/values in doc to generate the id.
            // we don't have path or size, so do the best we can
            md5.update( Long.toString(idTime).getBytes("ISO-8859-1") );

            COSDictionary info = (COSDictionary)trailer.getDictionaryObject( COSName.INFO );
            if( info != null )
            {
                Iterator<COSBase> values = info.getValues().iterator();
                while( values.hasNext() )
                {
                    md5.update( values.next().toString().getBytes("ISO-8859-1") );
                }
            }
            // reuse origin documentID if available as first value
            COSString firstID = missingID ? new COSString( md5.digest() ) : (COSString)idArray.get(0);
            COSString secondID = new COSString( md5.digest() );
            idArray = new COSArray();
            idArray.add( firstID );
            idArray.add( secondID );
            trailer.setItem( COSName.ID, idArray );
        }
        cosDoc.accept(this);
    }
View Full Code Here

     * Creates an empty PDF document.
     * You need to add at least one page for the document to be valid.
     */
    public PDDocument()
    {
        document = new COSDocument();

        // First we need a trailer
        COSDictionary trailer = new COSDictionary();
        document.setTrailer(trailer);

View Full Code Here

TOP

Related Classes of org.apache.pdfbox.cos.COSDocument

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.