Package org.apache.pdfbox.cos

Examples of org.apache.pdfbox.cos.COSDocument


     *
     * @throws IOException If there is an error creating this document.
     */
    public PDDocument() throws IOException
    {
        document = new COSDocument();

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

View Full Code Here


        if(doc.isAllSecurityToBeRemoved())
        {
            this.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.getPDFName("Encrypt"));
        }
        else
        {
            SecurityHandler securityHandler = document.getSecurityHandler();
            if(securityHandler != null)
            {
                try
                {
                    securityHandler.prepareDocumentForEncryption(document);
                    this.willEncrypt = true;
                }
                catch(IOException e)
                {
                    throw new COSVisitorException( e );
                }
                catch(CryptographyException e)
                {
                    throw new COSVisitorException( e );
                }
            }
            else
            {
                    this.willEncrypt = false;
            }       
        }

        COSDocument cosDoc = document.getDocument();
        COSDictionary trailer = cosDoc.getTrailer();
        COSArray idArray = (COSArray)trailer.getDictionaryObject( "ID" );
        if( idArray == null )
        {
            try
            {

                //algothim 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
                MessageDigest md = MessageDigest.getInstance( "MD5" );
                md.update( Long.toString( System.currentTimeMillis()).getBytes() );
                COSDictionary info = (COSDictionary)trailer.getDictionaryObject( "Info" );
                if( info != null )
                {
                    Iterator values = info.getValues().iterator();
                    while( values.hasNext() )
                    {
                        md.update( values.next().toString().getBytes() );
                    }
                }
                idArray = new COSArray();
                COSString id = new COSString( md.digest() );
                idArray.add( id );
                idArray.add( id );
                trailer.setItem( "ID", idArray );
            }
            catch( NoSuchAlgorithmException e )
            {
                throw new COSVisitorException( e );
            }
        }

        /*
        List objects = doc.getObjects();
        Iterator iter = objects.iterator();
        long maxNumber = 0;
        while( iter.hasNext() )
        {
            COSObject object = (COSObject)iter.next();
            if( object.getObjectNumber() != null &&
                object.getGenerationNumber() != null )
            {
                COSObjectKey key = new COSObjectKey( object.getObjectNumber().longValue(),
                                                     object.getGenerationNumber().longValue() );
                objectKeys.put( object.getObject(), key );
                objectKeys.put( object, key );
                maxNumber = Math.max( key.getNumber(), maxNumber );
                setNumber( maxNumber );
            }
        }*/
        cosDoc.accept(this);
    }
View Full Code Here

     *
     * @throws IOException If there is an error creating this document.
     */
    public FDFDocument() throws IOException
    {
        document = new COSDocument();
        document.setHeaderString( "%FDF-1.2" );

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

View Full Code Here

     */
    protected void checkCIDSet(PDFontDescriptor pfDescriptor)
    {
        if (FontValidator.isSubSet(pfDescriptor.getFontName()))
        {
            COSDocument cosDocument = context.getDocument().getDocument();
            COSBase cidset = pfDescriptor.getCOSObject().getItem(COSName.getPDFName(FONT_DICTIONARY_KEY_CIDSET));
            if (cidset == null || !COSUtils.isStream(cidset, cosDocument))
            {
                this.fContainer.push(new ValidationResult.ValidationError(ERROR_FONTS_CIDSET_MISSING_FOR_SUBSET,
                        "The CIDSet entry is missing for the Composite Subset"));
View Full Code Here

     */
    protected void checkCIDSet(PDFontDescriptor pfDescriptor)
    {
        if (FontValidator.isSubSet(pfDescriptor.getFontName()))
        {
            COSDocument cosDocument = context.getDocument().getDocument();
            COSBase cidset = pfDescriptor.getCOSObject().getItem(COSName.getPDFName(FONT_DICTIONARY_KEY_CIDSET));
            if (cidset == null || !COSUtils.isStream(cidset, cosDocument))
            {
                this.fContainer.push(new ValidationResult.ValidationError(ERROR_FONTS_CIDSET_MISSING_FOR_SUBSET,
                        "The CIDSet entry is missing for the Composite Subset"));
View Full Code Here

    protected void checkEncoding()
    {
        COSBase encoding = ((COSDictionary) fontDictionary).getItem(COSName.ENCODING);
        if (encoding != null)
        {
            COSDocument cosDocument = context.getDocument().getDocument();
            if (COSUtils.isString(encoding, cosDocument))
            {
                String encodingName = COSUtils.getAsString(encoding, cosDocument);
                if (!(encodingName.equals(FONT_DICTIONARY_VALUE_ENCODING_MAC)
                        || encodingName.equals(FONT_DICTIONARY_VALUE_ENCODING_MAC_EXP)
View Full Code Here

    * @return the templates Appearance Stream
    * @throws IOException
    */
    public ByteArrayInputStream getTemplateAppearanceStream() throws IOException
    {
        COSDocument visualSignature = getVisualSignature();
        ByteArrayOutputStream memoryOut = new ByteArrayOutputStream();
        COSWriter memoryWriter = new COSWriter(memoryOut);
        memoryWriter.write(visualSignature);

        ByteArrayInputStream input = new ByteArrayInputStream(memoryOut.toByteArray());
View Full Code Here

     * @throws ValidationException
     */
    protected void validateExtGStates(PreflightContext context, PDResources resources) throws ValidationException
    {
        COSBase egsEntry = resources.getCOSObject().getItem(TRANPARENCY_DICTIONARY_KEY_EXTGSTATE);
        COSDocument cosDocument = context.getDocument().getDocument();
        COSDictionary extGState = COSUtils.getAsDictionary(egsEntry, cosDocument);
        if (egsEntry != null)
        {
            ContextHelper.validateElement(context, extGState, EXTGSTATE_PROCESS);
        }
View Full Code Here

        }
    }

    protected void validateXObjects(PreflightContext context, PDResources resources) throws ValidationException
    {
        COSDocument cosDocument = context.getDocument().getDocument();
        COSDictionary mapOfXObj = COSUtils.getAsDictionary(resources.getCOSObject().getItem(COSName.XOBJECT),
                cosDocument);
        if (mapOfXObj != null)
        {
            for (Entry<COSName, COSBase> entry : mapOfXObj.entrySet())
View Full Code Here

     */
    public List<COSDictionary> extractExtGStateDictionaries(PreflightContext context, COSDictionary egsEntry)
            throws ValidationException
            {
        List<COSDictionary> listOfExtGState = new ArrayList<COSDictionary>(0);
        COSDocument cosDocument = context.getDocument().getDocument();
        COSDictionary extGStates = COSUtils.getAsDictionary(egsEntry, cosDocument);

        if (extGStates != null)
        {
            for (Object object : extGStates.keySet())
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.