Package org.apache.pdfbox.cos

Examples of org.apache.pdfbox.cos.COSString


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


     * @throws IOException If there is an error reading from the stream.
     */
    protected COSString parseCOSString() throws IOException
    {
        char nextChar = (char)pdfSource.read();
        COSString retval = new COSString();
        char openBrace;
        char closeBrace;
        if( nextChar == '(' )
        {
            openBrace = '(';
            closeBrace = ')';
        }
        else if( nextChar == '<' )
        {
            return parseCOSHexString();
        }
        else
        {
            throw new IOException( "parseCOSString string should start with '(' or '<' and not '" +
                    nextChar + "' " + pdfSource );
        }

        //This is the number of braces read
        //
        int braces = 1;
        int c = pdfSource.read();
        while( braces > 0 && c != -1)
        {
            char ch = (char)c;
            int nextc = -2; // not yet read

            if(ch == closeBrace)
            {

                braces--;
                braces = checkForMissingCloseParen(braces);
                if( braces != 0 )
                {
                    retval.append( ch );
                }
            }
            else if( ch == openBrace )
            {
                braces++;
                retval.append( ch );
            }
            else if( ch == '\\' )
            {
                //patched by ram
                char next = (char)pdfSource.read();
                switch(next)
                {
                    case 'n':
                        retval.append( '\n' );
                        break;
                    case 'r':
                        retval.append( '\r' );
                        break;
                    case 't':
                        retval.append( '\t' );
                        break;
                    case 'b':
                        retval.append( '\b' );
                        break;
                    case 'f':
                        retval.append( '\f' );
                        break;
                    case ')':
                        // PDFBox 276 /Title (c:\)
                        braces = checkForMissingCloseParen(braces);
                        if( braces != 0 )
                        {
                            retval.append( next );
                        }
                        else
                        {
                            retval.append('\\');
                        }
                        break;
                    case '(':
                    case '\\':
                        retval.append( next );
                        break;
                    case 10:
                    case 13:
                        //this is a break in the line so ignore it and the newline and continue
                        c = pdfSource.read();
                        while( isEOL(c) && c != -1)
                        {
                            c = pdfSource.read();
                        }
                        nextc = c;
                        break;
                    case '0':
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    {
                        StringBuffer octal = new StringBuffer();
                        octal.append( next );
                        c = pdfSource.read();
                        char digit = (char)c;
                        if( digit >= '0' && digit <= '7' )
                        {
                            octal.append( digit );
                            c = pdfSource.read();
                            digit = (char)c;
                            if( digit >= '0' && digit <= '7' )
                            {
                                octal.append( digit );
                            }
                            else
                            {
                                nextc = c;
                            }
                        }
                        else
                        {
                            nextc = c;
                        }
   
                        int character = 0;
                        try
                        {
                            character = Integer.parseInt( octal.toString(), 8 );
                        }
                        catch( NumberFormatException e )
                        {
                            throw new IOException( "Error: Expected octal character, actual='" + octal + "'" );
                        }
                        retval.append( character );
                        break;
                    }
                    default:
                    {
                        // dropping the backslash
                        // see 7.3.4.2 Literal Strings for further information
                        retval.append( next );
                    }
                }
            }
            else
            {
                retval.append( ch );
            }
            if (nextc != -2)
            {
                c = nextc;
            }
View Full Code Here

    {
        COSBase oldBase = this.getCOSDictionary().getDictionaryObject(name);
        COSArray array = new COSArray();
        for (String value : values)
        {
            array.add(new COSString(value));
        }
        this.getCOSDictionary().setItem(name, array);
        COSBase newBase = this.getCOSDictionary().getDictionaryObject(name);
        this.potentiallyNotifyChanged(oldBase, newBase);
    }
View Full Code Here

     *
     * @param bytes contents to be used
     */
    public void setContents(byte[] bytes)
    {
        COSString string = new COSString(bytes);
        string.setForceHexForm(true);
        dictionary.setItem(COSName.CONTENTS, string);
    }
View Full Code Here

        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

            byte singleByte = readByte();
            while(singleByte != ')') {
                sb.append((char)singleByte);
                singleByte = readByte();
            }
            return new COSString(sb.toString());
        } else {
            throw new RuntimeException("Not yet implemented: " + string
                    + " loation=" + this.currentOffset);
        }
    }
View Full Code Here

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

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

     * Default constructor.
     */
    public FDFOptionElement()
    {
        option = new COSArray();
        option.add( new COSString( "" ) );
        option.add( new COSString( "" ) );
    }
View Full Code Here

     *
     * @param opt One of the available options.
     */
    public void setOption( String opt )
    {
        option.set( 0, new COSString( opt ) );
    }
View Full Code Here

     *
     * @param da The default appearance string.
     */
    public void setDefaultAppearanceString( String da )
    {
        option.set( 1, new COSString( da ) );
    }
View Full Code Here

TOP

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

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.