Package org.pdfbox.cos

Examples of org.pdfbox.cos.COSString


     */
    public PDDocumentCatalog( PDDocument doc )
    {
        document = doc;
        root = new COSDictionary();
        root.setItem( COSName.TYPE, new COSString( "Catalog" ) );
        document.getDocument().getTrailer().setItem( COSName.ROOT, root );
    }
View Full Code Here


     *
     * @param dest The named destination.
     */
    public PDNamedDestination( String dest )
    {
        namedDestination = new COSString( dest );
    }
View Full Code Here

     */
    public void setNamedDestination( String dest ) throws IOException
    {
        if( namedDestination instanceof COSString )
        {
            COSString string = ((COSString)namedDestination);
            string.reset();
            string.append( dest.getBytes() );
        }
        else if( dest == null )
        {
            namedDestination = null;
        }
        else
        {
            namedDestination = new COSString( dest );
        }
    }
View Full Code Here

        + key.getName() + "' does not exist.");
  }

  public String getDocumentTitle() {
    assertKeyExists(INFO_PROPERTY_TITLE, getInfoDictionary());
    COSString title = (COSString) getInfoDictionary().getItem(
        INFO_PROPERTY_TITLE);
    return title.getString();
  }
View Full Code Here

        int dicPermissions = dictionary.getPermissions();
        int dicRevision = dictionary.getRevision();
        int dicLength = dictionary.getLength()/8;

        COSString id = (COSString) getPDFDocument().getDocument().getDocumentID().getObject( 0 );
        byte[] u = dictionary.getUserKey();
        byte[] o = dictionary.getOwnerKey();

        if (userPassword)
        {
          return secHandler.isUserPassword(password.getBytes(), u,
              o, dicPermissions, id.getBytes(), dicRevision, dicLength );
        }
        else
        {
          return secHandler.isOwnerPassword(password.getBytes(), u,
              o, dicPermissions, id.getBytes(), dicRevision, dicLength );
        }
  }
View Full Code Here

            PDFParser parser = new PDFParser(is);
            parser.parse();

            doc = parser.getDocument();

            setField(doc, new COSString(name), new COSString(value));

            os = new FileOutputStream(out);
            writer = new COSWriter(os);

            writer.write(doc);
View Full Code Here

                        COSName subFilter = (COSName)cert.getDictionaryObject( COSName.getPDFName( "SubFilter" ) );
                        if( subFilter != null )
                        {
                            if( subFilter.getName().equals( "adbe.x509.rsa_sha1" ) )
                            {
                                COSString certString = (COSString)cert.getDictionaryObject( COSName.getPDFName( "Cert" ) );
                                byte[] certData = certString.getBytes();
                                CertificateFactory factory = CertificateFactory.getInstance( "X.509" );
                                Collection certs = factory.generateCertificates( new ByteArrayInputStream( certData ) );
                                System.out.println( "certs=" + certs );
                            }
                            else
View Full Code Here

            is2 = new FileInputStream(in2);
            parser2 = new PDFParser(is2);
            parser2.parse();
            doc2 = parser2.getDocument();

            setField(doc1, "doc1", new COSString(name1), new COSString(value1));
            setField(doc2, "doc2", new COSString(name2), new COSString(value2));

            appendDocument(doc1, doc2);

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

                        // we found the field
                        COSBase fname = dict.getItem(COSName.getPDFName("T"));
                        if (fname != null && fname.equals(name))
                        {
                            dict.setItem(COSName.getPDFName("V"), value);
                            dict.setItem(COSName.getPDFName("T"), new COSString(prefix  + name.getString()));
                        }
                    }
                }
            }
        }
View Full Code Here

        {
            log.debug("parseCOSString() " + pdfSource );
        }
        char nextChar = (char)pdfSource.read();
        //System.out.println( "parseCOSString() nextChar=" + nextChar );
        COSString retval = new COSString();
        char openBrace;
        char closeBrace;
        if( nextChar == '(' )
        {
            openBrace = '(';
            closeBrace = ')';
        }
        else if( nextChar == '<' )
        {
            openBrace = '<';
            closeBrace = '>';
        }
        else
        {
            throw new IOException( "parseCOSString string should start with '(' or '<' and not '" + nextChar + "' " + pdfSource );
        }

        //This is the number of braces read
        //
        int braces = 1;
        while( braces > 0 && !pdfSource.isEOF())
        {
            char c = (char)pdfSource.read();

            if(c == closeBrace)
            {
                braces--;
                if( braces != 0 )
                {
                    retval.append( c );
                }
            }
            else if( c == openBrace )
            {
                braces++;
                retval.append( c );
            }
            else if( c == '\\' )
            {

                int next = pdfSource.read();
                switch(next)
                {
                    case 'n':
                        retval.append( (char)10 );
                        break;
                    case 'r':
                        retval.append( (char)13 );
                        break;
                    case 't':
                        retval.append( (char)9 );
                        break;
                    case 'b':
                        retval.append( (char)8 );
                        break;
                    case 'f':
                        retval.append( (char)12 );
                    case '(':
                    case ')':
                    case '\\':
                        retval.append( (char)next );
                        break;
                    case 10:
                    case 13:
                        //this is a break in the line so ignore it and the newline and continue
                        while( isEOL() && !pdfSource.isEOF())
                        {
                            pdfSource.read();
                        }
                        break;
                    case '0':
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    {
                        StringBuffer octal = new StringBuffer();
                        octal.append( "" + (char)next );
                        if( (char)pdfSource.peek() >= '0' && (char)pdfSource.peek() <= '7' )
                        {
                            octal.append( (char)pdfSource.read() );
                        }
                        if( (char)pdfSource.peek() >= '0' && (char)pdfSource.peek() <= '7' )
                        {
                            octal.append( (char)pdfSource.read() );
                        }
                        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:
                    {
                        retval.append( '\\' );
                        retval.append( (char)next );
                        //another ficken problem with PDF's, sometimes the \ doesn't really
                        //mean escape like the PDF spec says it does, sometimes is should be literal
                        //which is what we will assume here.
                        //throw new IOException( "Unexpected break sequence '" + next + "' " + pdfSource );
                    }
                }
            }
            else
            {
                if( openBrace == '<' )
                {
                    if( c != 0x0d && c != 0x0a )
                    {
                        retval.append( c );
                    }
                }
                else
                {
                    retval.append( c );
                }
            }
        }
        if( openBrace == '<' )
        {
            StringBuffer hexBuffer = new StringBuffer( retval.getString() );
            retval = new COSString();
            //if odd number then the last hex digit is assumed to be 0
            if( hexBuffer.length() % 2 == 1 )
            {
                hexBuffer.append( "0" );
            }
            for( int i=0; i<hexBuffer.length(); )
            {
                String hexChars = "" + hexBuffer.charAt( i++ ) + hexBuffer.charAt( i++ );
                try
                {
                    retval.append( Integer.parseInt( hexChars, 16 ) );
                }
                catch( NumberFormatException e )
                {
                    throw new IOException( "Error: Expected hex number, actual='" + hexChars + "'" );
                }
View Full Code Here

TOP

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