Package org.apache.pdfbox.cos

Examples of org.apache.pdfbox.cos.COSStream


    private void testContentStreamContains( PDDocument doc, PDFieldTreeNode field, String expected ) throws Exception
    {
        PDAnnotationWidget widget = field.getWidget();
        PDAppearanceEntry normalAppearance = widget.getAppearance().getNormalAppearance();
        PDAppearanceStream appearanceStream = normalAppearance.getAppearanceStream();
        COSStream actual = appearanceStream.getCOSStream();

        List<Object> actualTokens = getStreamTokens( doc, actual );
        assertTrue( actualTokens.contains( new COSString( expected ) ) );
    }
View Full Code Here


    private void testContentStreams( PDDocument doc, PDFieldTreeNode field, String expected ) throws Exception
    {
        PDAnnotationWidget widget = field.getWidget();
        PDAppearanceEntry normalAppearance = widget.getAppearance().getNormalAppearance();
        PDAppearanceStream appearanceStream = normalAppearance.getAppearanceStream();
        COSStream actual = appearanceStream.getCOSStream();

        List<Object> actualTokens = getStreamTokens( doc, actual );
        List<Object> expectedTokens = getStreamTokens( doc, expected );
        assertEquals( actualTokens.size(), expectedTokens.size() );
        for( int i=0; i<actualTokens.size(); i++ )
View Full Code Here

{
    static public void validate(PDImageXObject ximage, int bpc, int width, int height, String format, String colorSpaceName) throws IOException
    {
        // check the dictionary
        assertNotNull(ximage);
        COSStream cosStream = ximage.getCOSStream();
        assertNotNull(cosStream);
        assertEquals(COSName.XOBJECT, cosStream.getItem(COSName.TYPE));
        assertEquals(COSName.IMAGE, cosStream.getItem(COSName.SUBTYPE));
        assertTrue(ximage.getCOSStream().getFilteredLength() > 0);
        assertEquals(bpc, ximage.getBitsPerComponent());
        assertEquals(width, ximage.getWidth());
        assertEquals(height, ximage.getHeight());
        assertEquals(format, ximage.getSuffix());
View Full Code Here

    /**
     * Create a fresh XRef stream like for a fresh file or an incremental update.
     */
    public PDFXRefStream()
    {
        this.stream = new COSStream(new COSDictionary());
        streamData = new TreeMap<Integer, Object>();
        objectNumbers = new TreeSet<Integer>();
    }
View Full Code Here

        for (COSObject obj : document.getObjects())
        {
            if (obj.getObject() instanceof COSStream
                    && streamLengthCheckSet.contains((COSStream) obj.getObject()))
            {
                COSStream stream = (COSStream) obj.getObject();

                long filteredLength = stream.getFilteredLength();
                long filteredLengthWritten = stream.getFilteredLengthWritten();
                if (Math.abs(filteredLength - filteredLengthWritten) > 2)
                {
                    // adjust the length, but only if the difference is > 2,
                    // i.e. don't bother with CR LF differences
                    LOG.warn("/Length of " + obj + " corrected from " + filteredLength + " to " + filteredLengthWritten);
                    stream.setLong(COSName.LENGTH, filteredLengthWritten);
                    stream.setFilteredLength(filteredLengthWritten);
                }
            }
        }
    }
View Full Code Here

                if( pb instanceof COSDictionary )
                {
                    pb = parseCOSStream( (COSDictionary)pb );

                    // test for XRef type
                    final COSStream strmObj = (COSStream) pb;
                   
                    // remember streams without length to check them later
                    COSBase streamLength = strmObj.getItem(COSName.LENGTH);
                    int length = -1;
                    if (streamLength instanceof COSNumber)
                    {
                        length = ((COSNumber) streamLength).intValue();
                    }
                    if (length == -1)
                    {
                        streamLengthCheckSet.add(strmObj);
                    }
                   
                    final COSName objectType = (COSName)strmObj.getItem( COSName.TYPE );
                    if( objectType != null && objectType.equals( COSName.XREF ) )
                    {
                        // XRef stream
                        parseXrefStream( strmObj, currentObjByteOffset );
                    }
View Full Code Here

    @Test
    public void testIsStream()
    {
        try
        {
            COSObject co = new COSObject(new COSStream());
            co.setGenerationNumber(COSInteger.ZERO);
            co.setObjectNumber(COSInteger.get(10));

            assertFalse(COSUtils.isStream(co, new IOCOSDocument()));
View Full Code Here

        }
    }

    public void validateStreamObject(PreflightContext context, COSObject cObj) throws ValidationException
    {
        COSStream streamObj = (COSStream) cObj.getObject();

        // ---- Check dictionary entries
        // ---- Only the Length entry is mandatory
        // ---- In a PDF/A file, F, FFilter and FDecodeParms are forbidden
        checkDictionaryEntries(context, streamObj);
View Full Code Here

        return false;
    }

    protected void checkStreamLength(PreflightContext context, COSObject cObj) throws ValidationException
    {
        COSStream streamObj = (COSStream) cObj.getObject();
        int length = streamObj.getInt(COSName.LENGTH);
        InputStream ra = null;
        try
        {
            ra = context.getSource().getInputStream();
            Long offset = context.getDocument().getDocument().getXrefTable().get(new COSObjectKey(cObj));
View Full Code Here

        contentStream.setNonStrokingColor(
                new Color(colorSpace, new float[]{0.1f, 0.2f, 0.3f, 0.4f}, 1.0f));
        contentStream.close();

        // now read the PDF stream and verify that the CMYK values are correct
        COSStream stream = page.getContents().getStream();
        PDFStreamParser parser = new PDFStreamParser(stream);
        parser.parse();
        java.util.List<Object>  pageTokens = parser.getTokens();
        // expected five tokens :
        // [0] = COSFloat{0.1}
View Full Code Here

TOP

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