Package org.pdfbox.cos

Examples of org.pdfbox.cos.COSNumber


            long first = firstChar.intValue();
            long last = lastChar.intValue();
            if( code >= first && code <= last && font.getDictionaryObject( COSName.WIDTHS ) != null )
            {
                COSArray widthArray = (COSArray)font.getDictionaryObject( COSName.WIDTHS );
                COSNumber fontWidthObject = (COSNumber)widthArray.get( (int)(code - first) );
                fontWidth = fontWidthObject.floatValue();
            }
            else
            {
                fontWidth = getFontWidthFromAFMFile( code );
            }
View Full Code Here


            if( token instanceof PDFOperator )
            {
                PDFOperator op = (PDFOperator)token;
                if( op.getOperation().equals( BEGIN_CODESPACE_RANGE ) )
                {
                    COSNumber cosCount = (COSNumber)tokens.get( i-1 );
                    for( int j=0; j<cosCount.intValue(); j++ )
                    {
                        i++;
                        COSString startRange = (COSString)tokens.get( i );
                        i++;
                        COSString endRange = (COSString)tokens.get( i );
                        CodespaceRange range = new CodespaceRange();
                        range.setStart( startRange.getBytes() );
                        range.setEnd( endRange.getBytes() );
                        result.addCodespaceRange( range );
                    }
                }
                else if( op.getOperation().equals( BEGIN_BASE_FONT_CHAR ) )
                {
                    COSNumber cosCount = (COSNumber)tokens.get( i-1 );
                    for( int j=0; j<cosCount.intValue(); j++ )
                    {
                        i++;
                        COSString inputCode = (COSString)tokens.get( i );
                        i++;
                        Object nextToken = tokens.get( i );
                        if( nextToken instanceof COSString )
                        {
                            String value = new String( ((COSString)nextToken).getBytes(), "UTF-16BE" );
                            result.addMapping( inputCode.getBytes(), value );
                        }
                        else if( nextToken instanceof COSName )
                        {
                            result.addMapping( inputCode.getBytes(), ((COSName)nextToken).getName() );
                        }
                        else
                        {
                            throw new IOException( "Error parsing CMap beginbfchar, expected{COSString " +
                                                   "or COSName} and not " + nextToken );
                        }
                    }
                }
               else if( op.getOperation().equals( BEGIN_BASE_FONT_RANGE ) )
                {
                    COSNumber cosCount = (COSNumber)tokens.get( i-1 );
                    for( int j=0; j<cosCount.intValue(); j++ )
                    {
                        i++;
                        COSString startCode = (COSString)tokens.get( i );
                        i++;
                        COSString endCode = (COSString)tokens.get( i );
View Full Code Here

     * @return The rotation at this level in the hierarchy.
     */
    public Integer getRotation()
    {
        Integer retval = null;
        COSNumber value = (COSNumber)page.getDictionaryObject( COSName.getPDFName( "Rotate" ) );
        if( value != null )
        {
            retval = new Integer( (int)value.intValue() );
        }
        return retval;
    }
View Full Code Here

     * @return The value for that item.
     */
    private Float getFloatItem( COSName key )
    {
        Float retval = null;
        COSNumber value = (COSNumber)resources.getDictionaryObject( key );
        if( value != null )
        {
            retval = new Float( value.floatValue() );
        }
        return retval;
    }
View Full Code Here

     * @return The value for that item.
     */
    private Long getLongItem( COSName key )
    {
        Long retval = null;
        COSNumber value = (COSNumber)resources.getDictionaryObject( key );
        if( value != null )
        {
            retval = new Long( value.intValue() );
        }
        return retval;
    }
View Full Code Here

            //Append curved segment to path (three control points)
        }*/
        else if( operation.equals( "cm" ) )
        {
            //concatenate matrix to current transformation 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("<cm " +
                          "a=\"" + a.floatValue() + "\" " +
                          "b=\"" + b.floatValue() + "\" " +
                          "c=\"" + c.floatValue() + "\" " +
                          "d=\"" + d.floatValue() + "\" " +
                          "e=\"" + e.floatValue() + "\" " +
                          "f=\"" + f.floatValue() + "\" >");
            }

            Matrix newMatrix = new Matrix();
            newMatrix.setValue( 0, 0, a.floatValue() );
            newMatrix.setValue( 0, 1, b.floatValue() );
            newMatrix.setValue( 1, 0, c.floatValue() );
            newMatrix.setValue( 1, 1, d.floatValue() );
            newMatrix.setValue( 2, 0, e.floatValue() );
            newMatrix.setValue( 2, 1, f.floatValue() );

            currentTransformationMatrix = currentTransformationMatrix.multiply(newMatrix);
        }/*
        else if( operation.equals( "cs" ) )
        {
            //set colorspace for non stroking operations
            COSName name = (COSName)parameterStack.get( parameterStack.size() -2 );
            //System.out.println( "<cs name=\"" + name.getName() + "\" >" );
        }
        else if( operation.equals( "CS" ) )
        {
            //(PDF 1.1) Set color space for stroking operations
            COSName name = (COSName)parameterStack.get( parameterStack.size() -2 );
            //System.out.println( "<CS name=\"" + name.getName() + "\" >" );
        }
        else if( operation.equals( "d" ) )
        {
            //Set the line dash pattern in the graphics state
            //System.out.println( "<d>" );
        }
        else if( operation.equals( "d0" ) )
        {
            COSNumber x = (COSNumber)parameterStack.get( parameterStack.size() -3 );
            COSNumber y = (COSNumber)parameterStack.get( parameterStack.size() -2 );
            //System.out.println( "<d0 x=\"" + x.getValue() + "\" y=\"" + y.getValue() + "\">" );
        }
        else if( operation.equals( "d1" ) )
        {
            //System.out.println( "<d1>" );
        }
        else if( operation.equals( "Do" ) )
        {
            //invoke named object.
        }
        else if( operation.equals( "DP" ) )
        {
            //(PDF 1.2) De.ne marked-content point with property list
        }
        else if( operation.equals( "EI" ) )
        {
            //end inline image object
        }
        else if( operation.equals( "EMC" ) )
        {
            //End inline image object
        }*/
        else if( operation.equals( "ET" ) )
        {
            log.debug( "<ET>" );
            textMatrix = null;
            textLineMatrix = null;
        }/*
        else if( operation.equals( "EX" ) )
        {
            //(PDF 1.1) End compatibility section
        }
        else if( operation.equals( "f" ) )
        {
            //Fill the path, using the nonzero winding number rule to determine the region to .ll
            //System.out.println( "<f>" );
        }
        else if( operation.equals( "F" ) )
        {
            //Equivalent to f; included only for compatibility. Although applications that read
            //PDF files must be able to accept this operator, those that generate PDF files should
            //use f instead.
            //System.out.println( "<F>" );
        }
        else if( operation.equals( "f*" ) )
        {
            //Fill path using even-odd rule
        }
        else if( operation.equals( "g" ) )
        {
            //set gray level for nonstroking operations
            COSNumber grayLevel = (COSNumber)parameterStack.get( parameterStack.size() -2 );
            //System.out.println( "<g gray=\"" + grayLevel.getValue() + "\" />" );
        }
        else if( operation.equals( "G" ) )
        {
            //set gray level for stroking operations
            COSNumber grayLevel = (COSNumber)parameterStack.get( parameterStack.size() -2 );
            //System.out.println( "<G gray=\"" + grayLevel.getValue() + "\" />" );
        }
        else if( operation.equals( "gs" ) )
        {
            //set parameters from graphics state parameter dictionary
        }
        else if( operation.equals( "h" ) )
        {
            //close subpath
        }
        else if( operation.equals( "i" ) )
        {
            //set flatness tolerance, not sure what this does
        }
        else if( operation.equals( "ID" ) )
        {
            //begin inline image data
        }
        else if( operation.equals( "j" ) )
        {
            //Set the line join style in the graphics state
            //System.out.println( "<j>" );
        }
        else if( operation.equals( "J" ) )
        {
            //Set the line cap style in the graphics state
            //System.out.println( "<J>" );
        }
        else if( operation.equals( "k" ) )
        {
            //Set CMYK color for nonstroking operations
        }
        else if( operation.equals( "K" ) )
        {
            //Set CMYK color for stroking operations
        }
        else if( operation.equals( "l" ) )
        {
            //append straight line segment from the current point to the point.
            COSNumber x = (COSNumber)parameterStack.get( parameterStack.size() -3 );
            COSNumber y = (COSNumber)parameterStack.get( parameterStack.size() -2 );
            //System.out.println( "<l x=\"" + x.getValue() + "\" y=\"" + y.getValue() + "\" >" );
        }
        else if( operation.equals( "m" ) )
        {
            COSNumber x = (COSNumber)parameterStack.get( parameterStack.size() -3 );
            COSNumber y = (COSNumber)parameterStack.get( parameterStack.size() -2 );
            //System.out.println( "<m x=\"" + x.getValue() + "\" y=\"" + y.getValue() + "\" >" );
        }
        else if( operation.equals( "M" ) )
        {
            //System.out.println( "<M>" );
        }
        else if( operation.equals( "MP" ) )
        {
            //(PDF 1.2) Define marked-content point
        }
        else if( operation.equals( "n" ) )
        {
            //End path without .lling or stroking
            //System.out.println( "<n>" );
        }*/
        else if( operation.equals( "q" ) )
        {
            //save graphics state
            if( log.isDebugEnabled() )
            {
                log.debug( "<" + operation + "> - save state" );
            }
            ctmStack.push(currentTransformationMatrix);
        }
        else if( operation.equals( "Q" ) )
        {
            //restore graphics state
            if( log.isDebugEnabled() )
            {
                log.debug( "<" + operation + "> - restore state" );
            }
            currentTransformationMatrix = (Matrix)ctmStack.pop();
        }/*
        else if( operation.equals( "re" ) )
        {
            COSNumber x = (COSNumber)parameterStack.get( parameterStack.size() -5 );
            COSNumber y = (COSNumber)parameterStack.get( parameterStack.size() -4 );
            COSNumber width = (COSNumber)parameterStack.get( parameterStack.size() -3 );
            COSNumber height = (COSNumber)parameterStack.get( parameterStack.size() -2 );
            //System.out.println( "<re x=\"" + x.getValue() + "\" y=\"" + y.getValue() + "\" width=\"" +
            //                                 width.getValue() + "\" height=\"" + height.getValue() + "\" >" );
        }
        else if( operation.equals( "rg" ) )
        {
            //Set RGB color for nonstroking operations
        }
        else if( operation.equals( "RG" ) )
        {
            //Set RGB color for stroking operations
        }
        else if( operation.equals( "ri" ) )
        {
            //Set color rendering intent
        }
        else if( operation.equals( "s" ) )
        {
            //Close and stroke path
        }
        else if( operation.equals( "S" ) )
        {
            //System.out.println( "<S>" );
        }
        else if( operation.equals( "sc" ) )
        {
            //set color for nonstroking operations
            //System.out.println( "<sc>" );
        }
        else if( operation.equals( "SC" ) )
        {
            //set color for stroking operations
            //System.out.println( "<SC>" );
        }
        else if( operation.equals( "scn" ) )
        {
            //set color for nonstroking operations special
        }
        else if( operation.equals( "SCN" ) )
        {
            //set color for stroking operations special
        }
        else if( operation.equals( "sh" ) )
        {
            //(PDF 1.3) Paint area de.ned by shading pattern
        }*/
        else if( operation.equals( "T*" ) )
        {
            if (log.isDebugEnabled())
            {
                log.debug("<T* currentLeading=\"" + currentLeading + "\">");
            }
            //move to start of next text line
            if( currentLeading == 0 )
            {
                currentLeading = -.01f;
            }
            Matrix td = new Matrix();
            td.setValue( 2, 1, -1 * currentLeading * textMatrix.getValue(1,1));
            textLineMatrix = textLineMatrix.multiply( td );
            textMatrix = textLineMatrix.copy();
        }
        else if( operation.equals( "Tc" ) )
        {
            //set character spacing
            COSNumber characterSpacing = (COSNumber)arguments.get( 0 );
            if (log.isDebugEnabled())
            {
                log.debug("<Tc characterSpacing=\"" + characterSpacing.floatValue() + "\" />");
            }
            currentCharacterSpacing = characterSpacing.floatValue();
        }
        else if( operation.equals( "Td" ) )
        {
            COSNumber x = (COSNumber)arguments.get( 0 );
            COSNumber y = (COSNumber)arguments.get( 1 );
            if (log.isDebugEnabled())
            {
                log.debug("<Td x=\"" + x.floatValue() + "\" y=\"" + y.floatValue() + "\">");
            }
            Matrix td = new Matrix();
            td.setValue( 2, 0, x.floatValue() * textMatrix.getValue(0,0) );
            td.setValue( 2, 1, y.floatValue() * textMatrix.getValue(1,1) );
            //log.debug( "textLineMatrix before " + textLineMatrix );
            textLineMatrix = textLineMatrix.multiply( td );
            //log.debug( "textLineMatrix after " + textLineMatrix );
            textMatrix = textLineMatrix.copy();
        }
        else if( operation.equals( "TD" ) )
        {
            //move text position and set leading
            COSNumber x = (COSNumber)arguments.get( 0 );
            COSNumber y = (COSNumber)arguments.get( 1 );
            if (log.isDebugEnabled())
            {
                log.debug("<TD x=\"" + x.floatValue() + "\" y=\"" + y.floatValue() + "\">");
            }
            currentLeading = -1 * y.floatValue();
            Matrix td = new Matrix();
            td.setValue( 2, 0, x.floatValue() * textMatrix.getValue(0,0) );
            td.setValue( 2, 1, y.floatValue() * textMatrix.getValue(1,1) );
            //log.debug( "textLineMatrix before " + textLineMatrix );
            textLineMatrix = textLineMatrix.multiply( td );
            //log.debug( "textLineMatrix after " + textLineMatrix );
            textMatrix = textLineMatrix.copy();
        }
        else if( operation.equals( "Tf" ) )
        {
            //set font and size
            COSName fontName = (COSName)arguments.get( 0 );
            currentFontSize = (COSNumber)arguments.get( 1 );

            if (log.isDebugEnabled())
            {
                log.debug("<Tf font=\"" + fontName.getName() + "\" size=\"" + currentFontSize.floatValue() + "\">");
            }

            //old way
            //currentFont = (COSObject)stream.getDictionaryObject( fontName );
            //if( currentFont == null )
            //{
            //    currentFont = (COSObject)currentFontDictionary.getItem( fontName );
            //}
            currentFont = (PDFont)fonts.get( fontName );
            if( currentFont == null )
            {
                throw new IOException( "Current font is null" );
            }
            //log.debug( "Font Resource=" + fontResource );
            //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 );
View Full Code Here

        COSDictionary encryptedDictionary =
            (COSDictionary)trailer.getDictionaryObject( ENCRYPT );

        long permissions = ((COSNumber)encryptedDictionary.getDictionaryObject( COSName.getPDFName( "P" ) )).intValue();
        long revision = ((COSNumber)encryptedDictionary.getDictionaryObject( COSName.getPDFName( "R" ) )).intValue();
        COSNumber cosLength = (COSNumber)encryptedDictionary.getDictionaryObject( COSName.getPDFName( "Length" ) );
        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" ) );
View Full Code Here

TOP

Related Classes of org.pdfbox.cos.COSNumber

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.