Package org.pdfbox.cos

Examples of org.pdfbox.cos.COSString


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


     */
    public void updateLastModified()
    {
        DateConverter converter = new DateConverter();
        GregorianCalendar today = new GregorianCalendar();
        page.setItem( COSName.getPDFName( "LastModified" ), new COSString( converter.toString( today ) ) );
    }
View Full Code Here

     * @throws IOException If there is an error accessing the date information.
     */
    public Calendar getLastModified() throws IOException
    {
        Calendar retval = null;
        COSString date = (COSString)page.getDictionaryObject( COSName.getPDFName( "LastModified" ) );
        if( date != null )
        {
            DateConverter converter = new DateConverter();
            retval = converter.toCalendar( date.getString() );
        }
        return retval;
    }
View Full Code Here

        {
            COSArray fields = (COSArray)fdf.getDictionaryObject( COSName.getPDFName( "Fields" ) );
            for( int i=0; i<fields.size(); i++ )
            {
                COSDictionary fdfField = (COSDictionary)fields.getObject( i );
                COSString fieldName = (COSString)fdfField.getDictionaryObject( COSName.getPDFName( "T" ) );
                System.out.println( "Processing " + fieldName );
                PDField docField = acroForm.getField( fieldName.getString() );
                if( docField != null )
                {
                    docField.importFDF( fdfField );
                }
            }
View Full Code Here

        long length = 5;
        if( cosLength != null )
        {
            length = cosLength.intValue() / 8;
        }
        COSString id = (COSString)document.getDocumentID().get( 0 );
        COSString userPassword = (COSString)encryptedDictionary.getDictionaryObject( COSName.getPDFName( "U" ) );
        COSString ownerPassword = (COSString)encryptedDictionary.getDictionaryObject( COSName.getPDFName( "O" ) );

        boolean isUserPassword =
            encryption.isUserPassword( password.getBytes(), userPassword.getBytes(),
                ownerPassword.getBytes(),
                permissions, id.getBytes(), revision, length );
        boolean isOwnerPassword =
            encryption.isOwnerPassword( password.getBytes(), userPassword.getBytes(),
                ownerPassword.getBytes(), permissions, id.getBytes(), revision, length );

        if( isUserPassword )
        {
            encryptionKey =
                encryption.computeEncryptedKey(
                    password.getBytes(), ownerPassword.getBytes(),
                    permissions, id.getBytes(), revision, length );
        }
        else if( isOwnerPassword )
        {
            byte[] computedUserPassword =
                encryption.getUserPassword(
                    password.getBytes(),
                    ownerPassword.getBytes(),
                    revision,
                    length );
            encryptionKey =
                encryption.computeEncryptedKey(
                    computedUserPassword, ownerPassword.getBytes(),
                    permissions, id.getBytes(), revision, length );
        }
        else
        {
            throw new InvalidPasswordException( "Error: The supplied password does not match " +
View Full Code Here

            //log.debug( "Current Font=" + currentFont );
            //log.debug( "currentFontSize=" + currentFontSize );
        }
        else if( operation.equals( "Tj" ) )
        {
            COSString string = (COSString)arguments.get( 0 );
            TextPosition pos = showString( string.getBytes() );
            if (log.isDebugEnabled())
            {
                log.debug("<Tj string=\"" + string.getString() + "\">");
            }
        }
        else if( operation.equals( "TJ" ) )
        {
            Matrix td = new Matrix();

            COSArray array = (COSArray)arguments.get( 0 );
            for( int i=0; i<array.size(); i++ )
            {
                COSBase next = array.get( i );
                if( next instanceof COSNumber )
                {
                    float value = -1*
                                  (((COSNumber)next).floatValue()/1000) *
                                  currentFontSize.floatValue() *
                                  textMatrix.getValue(1,1);

                    if (log.isDebugEnabled())
                    {
                        log.debug( "<TJ(" + i + ") value=\"" + value +
                                   "\", param=\"" + ((COSNumber)next).floatValue() +
                                   "\", fontsize=\"" + currentFontSize.floatValue() + "\">" );
                    }
                    td.setValue( 2, 0, value );
                    textMatrix = textMatrix.multiply( td );
                }
                else if( next instanceof COSString )
                {
                    TextPosition pos = showString( ((COSString)next).getBytes() );
                    if (log.isDebugEnabled())
                    {
                        log.debug("<TJ(" + i + ") string=\"" + pos.getString() + "\">");
                    }
                }
                else
                {
                    throw new IOException( "Unknown type in array for TJ operation:" + next );
                }
            }
        }
        else if( operation.equals( "TL" ) )
        {
            COSNumber leading = (COSNumber)arguments.get( 0 );
            currentLeading = leading.floatValue();
            if (log.isDebugEnabled())
            {
                log.debug("<TL leading=\"" + leading.floatValue() + "\" >");
            }
        }
        else if( operation.equals( "Tm" ) )
        {
            //Set text matrix and text line matrix
            COSNumber a = (COSNumber)arguments.get( 0 );
            COSNumber b = (COSNumber)arguments.get( 1 );
            COSNumber c = (COSNumber)arguments.get( 2 );
            COSNumber d = (COSNumber)arguments.get( 3 );
            COSNumber e = (COSNumber)arguments.get( 4 );
            COSNumber f = (COSNumber)arguments.get( 5 );

            if (log.isDebugEnabled())
            {
                log.debug("<Tm " +
                          "a=\"" + a.floatValue() + "\" " +
                          "b=\"" + b.floatValue() + "\" " +
                          "c=\"" + c.floatValue() + "\" " +
                          "d=\"" + d.floatValue() + "\" " +
                          "e=\"" + e.floatValue() + "\" " +
                          "f=\"" + f.floatValue() + "\" >");
            }

            textMatrix = new Matrix();
            textMatrix.setValue( 0, 0, a.floatValue() );
            textMatrix.setValue( 0, 1, b.floatValue() );
            textMatrix.setValue( 1, 0, c.floatValue() );
            textMatrix.setValue( 1, 1, d.floatValue() );
            textMatrix.setValue( 2, 0, e.floatValue() );
            textMatrix.setValue( 2, 1, f.floatValue() );
            textLineMatrix = textMatrix.copy();
        }/**
        else if( operation.equals( "Tr" ) )
        {
            //Set text rendering mode
            //System.out.println( "<Tr>" );
        }
        else if( operation.equals( "Ts" ) )
        {
            //Set text rise
            //System.out.println( "<Ts>" );
        }**/
        else if( operation.equals( "Tw" ) )
        {
            //set word spacing
            COSNumber wordSpacing = (COSNumber)arguments.get( 0 );
            if (log.isDebugEnabled())
            {
                log.debug("<Tw wordSpacing=\"" + wordSpacing.floatValue() + "\" />");
            }
            currentWordSpacing = wordSpacing.floatValue();
        }/**
        else if( operation.equals( "Tz" ) )
        {
            //Set horizontal text scaling
        }
        else if( operation.equals( "v" ) )
        {
            //Append curved segment to path (initial point replicated)
        }
        else if( operation.equals( "w" ) )
        {
            //Set the line width in the graphics state
            //System.out.println( "<w>" );
        }
        else if( operation.equals( "W" ) )
        {
            //Set clipping path using nonzero winding number rule
            //System.out.println( "<W>" );
        }
        else if( operation.equals( "W*" ) )
        {
            //Set clipping path using even-odd rule
        }
        else if( operation.equals( "y" ) )
        {
            //Append curved segment to path (final point replicated)
        }*/
        else if( operation.equals( "'" ) )
        {
            // Move to start of next text line, and show text
            //
            COSString string = (COSString)arguments.get( 0 );
            if (log.isDebugEnabled())
            {
                log.debug("<' string=\"" + string.getString() + "\">");
            }

            Matrix td = new Matrix();
            td.setValue( 2, 1, -1 * currentLeading * textMatrix.getValue(1,1));
            textLineMatrix = textLineMatrix.multiply( td );
            textMatrix = textLineMatrix.copy();

            showString( string.getBytes() );
        }
        else if( operation.equals( "\"" ) )
        {
            //Set word and character spacing, move to next line, and show text
            //
            COSNumber wordSpacing = (COSNumber)arguments.get( 0 );
            COSNumber characterSpacing = (COSNumber)arguments.get( 1 );
            COSString string = (COSString)arguments.get( 2 );

            if (log.isDebugEnabled())
            {
                log.debug("<\" wordSpacing=\"" + wordSpacing +
                          "\", characterSpacing=\"" + characterSpacing +
                          "\", string=\"" + string.getString() + "\">");
            }

            currentCharacterSpacing = characterSpacing.floatValue();
            currentWordSpacing = wordSpacing.floatValue();

            Matrix td = new Matrix();
            td.setValue( 2, 1, -1 * currentLeading * textMatrix.getValue(1,1));
            textLineMatrix = textLineMatrix.multiply( td );
            textMatrix = textLineMatrix.copy();

            showString( string.getBytes() );
        }
    }
View Full Code Here

     * @return The value if it exists or null.
     */
    private String getStringItem( COSName key )
    {
        String retval = null;
        COSString value = (COSString)info.getDictionaryObject( key );
        if( value != null )
        {
            retval = value.getString();
        }
        return retval;
    }
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.