Package org.pdfbox.cos

Examples of org.pdfbox.cos.COSDictionary


            if( resources == null )
            {
                resources = new PDResources();
                page.setResources( resources );
            }
            COSDictionary res = resources.getCOSDictionary();

            if( contents instanceof COSStream )
            {
                COSStream stream = (COSStream) contents;
                Map objectNameMap = new TreeMap();
View Full Code Here


            }

            baos.write(b);
        }

        COSDictionary streamDict = new COSDictionary();
        streamDict.setItem(COSName.LENGTH, new COSInteger(baos.size()));
        COSStream output = new COSStream(streamDict, pdfDocument.getDocument().getScratchFile());
        output.setFilters(stream.getFilters());
        OutputStream os = output.createUnfilteredStream();
        baos.writeTo(os);
        os.close();
View Full Code Here

    {
        Iterator pageIter = pages.iterator();
        while( pageIter.hasNext() )
        {
            PDPage page = (PDPage)pageIter.next();
            COSDictionary pageDictionary = page.getCOSDictionary();
            COSBase contents = pageDictionary.getDictionaryObject( COSName.CONTENTS );
            if( contents instanceof COSStream )
            {
                COSStream contentsStream = (COSStream)contents;
                // System.err.println("stream");
                pageCount++;

                COSArray array = new COSArray();

                array.add(contentsStream);

                mergePage( array, page );

                pageDictionary.setItem(COSName.CONTENTS, array);
            }
            else if( contents instanceof COSArray )
            {
                COSArray contentsArray = (COSArray)contents;
View Full Code Here

        if( resources == null )
        {
            resources = new PDResources();
            page.setResources( resources );
        }
        COSDictionary docResDict = resources.getCOSDictionary();
        COSDictionary layoutResDict = layoutPage.res;
        mergeArray(PROC_SET, docResDict, layoutResDict);
        mergeDictionary(COSName.FONT, docResDict, layoutResDict, layoutPage.objectNameMap);
        mergeDictionary(XOBJECT, docResDict, layoutResDict, layoutPage.objectNameMap);
        mergeDictionary(EXT_G_STATE, docResDict, layoutResDict, layoutPage.objectNameMap);
View Full Code Here

     * @param dest
     * @param source
     */
    private void mergeDictionary(COSName name, COSDictionary dest, COSDictionary source, Map objectNameMap)
    {
        COSDictionary destDict = (COSDictionary) dest.getDictionaryObject(name);
        COSDictionary sourceDict = (COSDictionary) source.getDictionaryObject(name);

        if (destDict == null)
        {
            destDict = new COSDictionary();
            dest.setItem(name, destDict);
        }
        if( sourceDict != null )
        {

            Iterator iterKeys = sourceDict.keyList().iterator();
            while (iterKeys.hasNext())
            {
                COSName key = (COSName) iterKeys.next();
                COSName mappedKey = (COSName) objectNameMap.get(key.getName());
                if (mappedKey == null)
                {
                    // object not needet
                    continue;
                }

                destDict.setItem(mappedKey, sourceDict.getItem(key));
            }
        }
    }
View Full Code Here

     * @throws IOException If there is an error writing the data.
     * @throws COSVisitorException If there is an error generating the data.
     */
    protected void doWriteBody(COSDocument doc) throws IOException, COSVisitorException
    {
        COSDictionary trailer = doc.getTrailer();
        COSDictionary root = (COSDictionary)trailer.getDictionaryObject( COSName.ROOT );
        COSDictionary info = (COSDictionary)trailer.getDictionaryObject( COSName.getPDFName( "Info" ) );
        COSDictionary encrypt = (COSDictionary)trailer.getDictionaryObject( COSName.getPDFName( "Encrypt" ) );
        if( root != null )
        {
            addObjectToWrite( root );
        }
        if( info != null )
View Full Code Here

    protected void doWriteTrailer(COSDocument doc) throws IOException, COSVisitorException
    {
        getStandardOutput().write(TRAILER);
        getStandardOutput().writeEOL();

        COSDictionary trailer = doc.getTrailer();
        //sort xref, needed only if object keys not regenerated
        Collections.sort(getXRefEntries());
        COSWriterXRefEntry lastEntry = (COSWriterXRefEntry)getXRefEntries().get( getXRefEntries().size()-1);
        trailer.setInt(COSName.getPDFName("Size"), (int)lastEntry.getKey().getNumber()+1);
        trailer.removeItem( COSName.PREV );
        /**
        COSObject catalog = doc.getCatalog();
        if (catalog != null)
        {
            trailer.setItem(COSName.getPDFName("Root"), catalog);
        }
        */
        trailer.accept(this);

        getStandardOutput().write(STARTXREF);
        getStandardOutput().writeEOL();
        getStandardOutput().write(String.valueOf(getStartxref()).getBytes());
        getStandardOutput().writeEOL();
View Full Code Here

        {
                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() );
                    }
                }
View Full Code Here

        {
            key = COSName.getPDFName( colorSpace.getName() );
        }
        else
        {
            COSDictionary colorSpaces =
                (COSDictionary)resources.getCOSDictionary().getDictionaryObject(COSName.COLORSPACE);
            if( colorSpaces == null )
            {
                colorSpaces = new COSDictionary();
                resources.getCOSDictionary().setItem( COSName.COLORSPACE, colorSpaces );
            }
            key = colorSpaces.getKeyForValue( colorSpace.getCOSObject() );
           
            if( key == null )
            {
                int counter = 0;
                String csName = "CS";
                while( colorSpaces.containsValue( csName + counter ) )
                {
                    counter++;
                }
                key = COSName.getPDFName( csName + counter );
                colorSpaces.setItem( key, colorSpace );
            }
        }
        key.writePDF( output );
        appendRawCommands( SPACE );
    }
View Full Code Here

     * @param theAcroForm The form that this field is part of.
     */
    public PDField( PDAcroForm theAcroForm )
    {
        acroForm = theAcroForm;
        dictionary = new COSDictionary();
        //no required fields in base field class
    }
View Full Code Here

TOP

Related Classes of org.pdfbox.cos.COSDictionary

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.