⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 type3streamparser.java

📁 非常有用的操作pdf文件的java源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        {
            //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" ) )
        {
            graphics.draw( linePath );
        }
        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* graphicsState.getTextState().getLeading()=\"" +
                    graphicsState.getTextState().getLeading() + "\">");
            }
            //move to start of next text line
            if( graphicsState.getTextState().getLeading() == 0 )
            {
                graphicsState.getTextState().setLeading( -.01f );
            }
            Matrix td = new Matrix();
            td.setValue( 2, 1, -1 * graphicsState.getTextState().getLeading() * 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() + "\" />");
            }
            graphicsState.getTextState().setCharacterSpacing( 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() + "\">");
            }
            graphicsState.getTextState().setLeading( -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 );
            graphicsState.getTextState().setFontSize( ((COSNumber)arguments.get( 1 ) ).floatValue() );

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

            //old way
            //graphicsState.getTextState().getFont() = (COSObject)stream.getDictionaryObject( fontName );
            //if( graphicsState.getTextState().getFont() == null )
            //{
            //    graphicsState.getTextState().getFont() = (COSObject)graphicsState.getTextState().getFont()
            //                                           Dictionary.getItem( fontName );
            //}
            graphicsState.getTextState().setFont( (PDFont)fonts.get( fontName.getName() ) );
            if( graphicsState.getTextState().getFont() == null )
            {
                throw new IOException( "Error: Could not find font(" + fontName + ") in map=" + fonts );
            }
            //log.debug( "Font Resource=" + fontResource );
            //log.debug( "Current Font=" + graphicsState.getTextState().getFont() );
            //log.debug( "graphicsState.getTextState().getFontSize()=" + graphicsState.getTextState().getFontSize() );
        }
        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) *
                                  graphicsState.getTextState().getFontSize() *
                                  textMatrix.getValue(1,1);

                    if (log.isDebugEnabled())
                    {
                        log.debug( "<TJ(" + i + ") value=\"" + value +
                                   "\", param=\"" + ((COSNumber)next).floatValue() +
                                   "\", fontsize=\"" + graphicsState.getTextState().getFontSize() + "\">" );
                    }
                    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 );
            graphicsState.getTextState().setLeading( 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() + "\" />");
            }
            graphicsState.getTextState().setWordSpacing( 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 * graphicsState.getTextState().getLeading() * 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() + "\">");
            }

            graphicsState.getTextState().setCharacterSpacing( characterSpacing.floatValue() );
            graphicsState.getTextState().setWordSpacing( wordSpacing.floatValue() );

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

            showString( string.getBytes() );
        }*/
    }


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -