Java Code Examples for org.apache.pdfbox.contentstream.operator.Operator#getImageParameters()

The following examples show how to use org.apache.pdfbox.contentstream.operator.Operator#getImageParameters() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BeginInlineImage.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException
{
    if (operator.getImageData() == null || operator.getImageData().length == 0)
    {
        return;
    }
    PDImage image = new PDInlineImage(operator.getImageParameters(),
                                      operator.getImageData(),
                                      context.getResources());
    context.drawImage(image);
}
 
Example 2
Source File: ContentStreamWriter.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
private void writeObject( Object o ) throws IOException
{
    if( o instanceof COSString )
    {
        COSWriter.writeString((COSString)o, output);
        output.write( SPACE );
    }
    else if( o instanceof COSFloat )
    {
        ((COSFloat)o).writePDF( output );
        output.write( SPACE );
    }
    else if( o instanceof COSInteger )
    {
        ((COSInteger)o).writePDF( output );
        output.write( SPACE );
    }
    else if( o instanceof COSBoolean )
    {
        ((COSBoolean)o).writePDF( output );
        output.write( SPACE );
    }
    else if( o instanceof COSName )
    {
        ((COSName)o).writePDF( output );
        output.write( SPACE );
    }
    else if( o instanceof COSArray )
    {
        COSArray array = (COSArray)o;
        output.write(COSWriter.ARRAY_OPEN);
        for( int i=0; i<array.size(); i++ )
        {
            writeObject( array.get( i ) );
            output.write( SPACE );
        }

        output.write( COSWriter.ARRAY_CLOSE );
    }
    else if( o instanceof COSDictionary )
    {
        COSDictionary obj = (COSDictionary)o;
        output.write( COSWriter.DICT_OPEN );
        for (Map.Entry<COSName, COSBase> entry : obj.entrySet())
        {
            if (entry.getValue() != null)
            {
                writeObject( entry.getKey() );
                output.write( SPACE );
                writeObject( entry.getValue() );
                output.write( SPACE );
            }
        }
        output.write( COSWriter.DICT_CLOSE );
        output.write( SPACE );
    }
    else if( o instanceof Operator)
    {
        Operator op = (Operator)o;
        if (op.getName().equals(OperatorName.BEGIN_INLINE_IMAGE))
        {
            output.write(OperatorName.BEGIN_INLINE_IMAGE.getBytes(Charsets.ISO_8859_1));
            COSDictionary dic = op.getImageParameters();
            for( COSName key : dic.keySet() )
            {
                Object value = dic.getDictionaryObject( key );
                key.writePDF( output );
                output.write( SPACE );
                writeObject( value );
                output.write( EOL );
            }
            output.write(OperatorName.BEGIN_INLINE_IMAGE_DATA.getBytes(Charsets.ISO_8859_1));
            output.write( EOL );
            output.write( op.getImageData() );
            output.write( EOL );
            output.write(OperatorName.END_INLINE_IMAGE.getBytes(Charsets.ISO_8859_1));
            output.write( EOL );
        }
        else
        {
            output.write( op.getName().getBytes(Charsets.ISO_8859_1) );
            output.write( EOL );
        }
    }
    else
    {
        throw new IOException( "Error:Unknown type in content stream:" + o );
    }
}