Package org.pdfbox.cos

Examples of org.pdfbox.cos.COSStream


        InputStream is = null;
        OutputStream os = null;
        try
        {
            PDStream src = page.getContents();
            PDStream dest = new PDStream( new COSStream( src.getStream(), document.getScratchFile() ) );
            importedPage.setContents( dest );
            os = dest.createOutputStream();

            byte[] buf = new byte[10240];
            int amountRead = 0;
View Full Code Here


     * @param document The document that the stream will be part of.
     * @return A new stream object.
     */
    public static PDObjectStream createStream( PDDocument document )
    {
        COSStream cosStream = new COSStream( document.getDocument().getScratchFile() );
        PDObjectStream strm = new PDObjectStream( cosStream );
        strm.getStream().setName( "Type", "ObjStm" );
        return strm;
    }
View Full Code Here

     * @return The object that this stream is an extension.
     */
    public PDObjectStream getExtends()
    {
        PDObjectStream retval = null;
        COSStream stream = (COSStream)getStream().getDictionaryObject( "Extends" );
        if( stream != null )
        {
            retval = new PDObjectStream( stream );
        }
        return retval;
View Full Code Here

            mediaBox.add( new COSInteger(792));
            page.setItem(COSName.getPDFName("MediaBox"), mediaBox);
            byte[] bytes = ("BT /F1 24 Tf 100 100 Td (" + message + ") Tj ET").getBytes();
            COSDictionary streamDict = new COSDictionary();
            streamDict.setItem(COSName.LENGTH, new COSInteger(bytes.length));
            COSStream contents = new COSStream(streamDict,doc.getScratchFile());
            OutputStream output = contents.createUnfilteredStream();
            output.write(bytes);
            output.close();
            page.setItem(COSName.CONTENTS, doc.createObject(contents));
            COSDictionary resources = new COSDictionary();
            // the procset
View Full Code Here

            {
                COSBase base = ((COSObject) i.next()).getObject();
                if (base instanceof COSStream)
                {
                    // just kill the filters
                    COSStream cosStream = (COSStream)base;
                    cosStream.getUnfilteredStream();
                    cosStream.setFilters(null);
                }
            }

            os = new java.io.FileOutputStream(out);
            writer = new COSWriter(os);
View Full Code Here

    {
        if( log.isDebugEnabled() )
        {
            log.debug("parseCOSStream() " + pdfSource );
        }
        COSStream stream = new COSStream( dic, file );
        OutputStream out = null;
        try
        {
            char c;
            String streamString = readString();
            int streamOffset;
            //long streamLength;

            if (!streamString.equals("stream"))
            {
                throw new IOException("expected='stream' actual='" + streamString + "'");
            }

            //PDF Ref 3.2.7 A stream must be followed by either
            //a CRLF or LF but nothing else.

            int whitespace = pdfSource.read();
            if( whitespace == 0x0D )
            {
                whitespace = pdfSource.read();
                if( whitespace != 0x0A )
                {
                    pdfSource.unread( whitespace );
                    //The spec says this is invalid but it happens in the real
                    //world so we must support it.
                    //throw new IOException("expected='0x0A' actual='0x" + Integer.toHexString(whitespace) + "' " + pdfSource);
                }
            }
            else if (whitespace == 0x0A)
            {
                //that is fine
            }
            else
            {
                //we are in an error.
                //but again we will do a lenient parsing and just assume that everything
                //is fine
                pdfSource.unread( whitespace );
                //throw new IOException("expected='0x0D or 0x0A' actual='0x" + Integer.toHexString(whitespace) + "' " + pdfSource);

            }


            COSBase streamLength = dic.getDictionaryObject(COSName.LENGTH);
            long length = -1;
            if( streamLength instanceof COSNumber )
            {
                length = ((COSNumber)streamLength).intValue();
            }
            else if( streamLength instanceof COSObject &&
                     ((COSObject)streamLength).getObject() instanceof COSNumber )
            {
                length = ((COSNumber)((COSObject)streamLength).getObject()).intValue();
            }

            //length = -1;
            //streamLength = null;
            out = stream.createFilteredStream( streamLength );
            if( length != -1 )
            {
                byte[] buffer = new byte[1024];
                int amountRead = 0;
                int totalAmountRead = 0;
View Full Code Here

            fontSubtype.getName().equals( "TrueType" ) ) &&
            font.getDictionaryObject( COSName.getPDFName( "ToUnicode" ) ) != null )
        //if( getDictionaryObject( COSName.getPDFName( "ToUnicode" ) ) != null )
        {
            retval = "";
            COSStream toUnicode = (COSStream)font.getDictionaryObject( COSName.getPDFName( "ToUnicode" ) );
            if( toUnicode != null )
            {
                if( cmap == null )
                {
                    CMapParser parser = new CMapParser( toUnicode.getUnfilteredStream(), toUnicode.getScratchFile() );
                    parser.parse();
                    cmap = parser.getResult();
                }
                retval = cmap.lookup( c, offset, length );
            }
View Full Code Here

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

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

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

View Full Code Here

            }
            COSDictionary res = resources.getCOSDictionary();

            if( contents instanceof COSStream )
            {
                COSStream stream = (COSStream) contents;
                Map objectNameMap = new TreeMap();
                stream = makeUniqObjectNames(objectNameMap, stream);

                layoutPages.add(new LayoutPage(stream, res, objectNameMap));
            }
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();

        return output;
    }
View Full Code Here

TOP

Related Classes of org.pdfbox.cos.COSStream

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.