Examples of PageDrawer


Examples of org.apache.pdfbox.pdfviewer.PageDrawer

    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
        throws PrinterException
    {
        try
        {
            PageDrawer drawer = new PageDrawer();
            PDRectangle cropBox = findCropBox();
            drawer.drawPage( graphics, this, cropBox.createDimension() );
            return PAGE_EXISTS;
        }
        catch( IOException io )
        {
            throw new PrinterIOException( io );
View Full Code Here

Examples of org.apache.pdfbox.pdfviewer.PageDrawer

    @Override
    public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
    {
        super.process( operator, arguments );
        float lineWidth = (float)context.getGraphicsState().getLineWidth();
        PageDrawer drawer = (PageDrawer)context;
        BasicStroke stroke = (BasicStroke)drawer.getStroke();
        if (stroke == null)
        {
            drawer.setStroke( new BasicStroke( lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER ) );
        }
        else
        {
            drawer.setStroke( new BasicStroke(lineWidth, stroke.getEndCap(), stroke.getLineJoin(),
                    stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase()) );
        }
    }
View Full Code Here

Examples of org.apache.pdfbox.pdfviewer.PageDrawer

     * @param operator The operator that is being executed.
     * @param arguments List
     */
    public void process(PDFOperator operator, List<COSBase> arguments)
    {
        PageDrawer drawer = (PageDrawer) context;

        COSNumber x = (COSNumber) arguments.get(0);
        COSNumber y = (COSNumber) arguments.get(1);
        COSNumber w = (COSNumber) arguments.get(2);
        COSNumber h = (COSNumber) arguments.get(3);

        double x1 = x.doubleValue();
        double y1 = y.doubleValue();

        // create a pair of coordinates for the transformation
        double x2 = w.doubleValue() + x1;
        double y2 = h.doubleValue() + y1;

        Point2D p0 = drawer.transformedPoint(x1, y1);
        Point2D p1 = drawer.transformedPoint(x2, y1);
        Point2D p2 = drawer.transformedPoint(x2, y2);
        Point2D p3 = drawer.transformedPoint(x1, y2);

        // to ensure that the path is created in the right direction, we have to create
        // it by combining single lines instead of creating a simple rectangle
        GeneralPath path = drawer.getLinePath();
        path.moveTo((float) p0.getX(), (float) p0.getY());
        path.lineTo((float) p1.getX(), (float) p1.getY());
        path.lineTo((float) p2.getX(), (float) p2.getY());
        path.lineTo((float) p3.getX(), (float) p3.getY());

View Full Code Here

Examples of org.apache.pdfbox.pdfviewer.PageDrawer

     * @param arguments List
     * @throws IOException If there is an error displaying the inline image.
     */
    public void process(PDFOperator operator, List<COSBase> argumentsthrows IOException
    {
        PageDrawer drawer = (PageDrawer)context;
        PDPage page = drawer.getPage();
        //begin inline image object
        ImageParameters params = operator.getImageParameters();
        PDInlinedImage image = new PDInlinedImage();
        image.setImageParameters( params );
        image.setImageData( operator.getImageData() );
        if (params.isStencil())
        {
            //TODO implement inline image stencil masks
            LOG.warn("Stencil masks are not implemented, background may be incorrect");
        }
        BufferedImage awtImage = image.createImage( context.getColorSpaces() );

        if (awtImage == null)
        {
            LOG.warn("BeginInlineImage.process(): createImage returned NULL");
            return;
        }
        int imageWidth = awtImage.getWidth();
        int imageHeight = awtImage.getHeight();
        double pageHeight = drawer.getPageSize().getHeight();
       
        Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix();
        int pageRotation = page.findRotation();

        AffineTransform ctmAT = ctm.createAffineTransform();
        ctmAT.scale(1f/imageWidth, 1f/imageHeight);
        Matrix rotationMatrix = new Matrix();
        rotationMatrix.setFromAffineTransform( ctmAT );
        // calculate the inverse rotation angle
        // scaleX = m00 = cos
        // shearX = m01 = -sin
        // tan = sin/cos
        double angle = Math.atan(ctmAT.getShearX()/ctmAT.getScaleX());
        Matrix translationMatrix = null;
        if (pageRotation == 0 || pageRotation == 180)
        {
            translationMatrix = Matrix.getTranslatingInstance((float)(Math.sin(angle)*ctm.getXScale()), (float)(pageHeight-2*ctm.getYPosition()-Math.cos(angle)*ctm.getYScale()));
        }
        else if (pageRotation == 90 || pageRotation == 270)
        {
            translationMatrix = Matrix.getTranslatingInstance((float)(Math.sin(angle)*ctm.getYScale()), (float)(pageHeight-2*ctm.getYPosition()));
        }
        rotationMatrix = rotationMatrix.multiply(translationMatrix);
        rotationMatrix.setValue(0, 1, (-1)*rotationMatrix.getValue(0, 1));
        rotationMatrix.setValue(1, 0, (-1)*rotationMatrix.getValue(1, 0));
        AffineTransform at = new AffineTransform(
                rotationMatrix.getValue(0,0),rotationMatrix.getValue(0,1),
                rotationMatrix.getValue(1,0), rotationMatrix.getValue( 1, 1),
                rotationMatrix.getValue(2,0),rotationMatrix.getValue(2,1)
                );
        drawer.drawImage(awtImage, at);
    }
View Full Code Here

Examples of org.apache.pdfbox.pdfviewer.PageDrawer

     * @param arguments List
     * @throws IOException If there is an error invoking the sub object.
     */
    public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
    {
        PageDrawer drawer = (PageDrawer)context;
        PDPage page = drawer.getPage();
        COSName objectName = (COSName)arguments.get( 0 );
        Map<String, PDXObject> xobjects = drawer.getResources().getXObjects();
        PDXObject xobject = (PDXObject)xobjects.get( objectName.getName() );
        if ( xobject == null )
        {
            LOG.warn("Can't find the XObject for '"+objectName.getName()+"'");
        }
        else if( xobject instanceof PDXObjectImage )
        {
            PDXObjectImage image = (PDXObjectImage)xobject;
            try
            {
                if (image.getImageMask())
                {
                    // set the current non stroking colorstate, so that it can
                    // be used to create a stencil masked image
                    image.setStencilColor(drawer.getGraphicsState().getNonStrokingColor());
                }
                BufferedImage awtImage = image.getRGBImage();
                if (awtImage == null)
                {
                    LOG.warn("getRGBImage returned NULL");
                    return;//TODO PKOCH
                }
                int imageWidth = awtImage.getWidth();
                int imageHeight = awtImage.getHeight();
                double pageHeight = drawer.getPageSize().getHeight();

                LOG.debug("imageWidth: " + imageWidth + "\t\timageHeight: " + imageHeight);
       
                Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix();
                float yScaling = ctm.getYScale();
                float angle = (float)Math.acos(ctm.getValue(0, 0)/ctm.getXScale());
                if (ctm.getValue(0, 1) < 0 && ctm.getValue(1, 0) > 0)
                {
                    angle = (-1)*angle;
                }
                ctm.setValue(2, 1, (float)(pageHeight - ctm.getYPosition() - Math.cos(angle)*yScaling));
                ctm.setValue(2, 0, (float)(ctm.getXPosition() - Math.sin(angle)*yScaling));
                // because of the moved 0,0-reference, we have to shear in the opposite direction
                ctm.setValue(0, 1, (-1)*ctm.getValue(0, 1));
                ctm.setValue(1, 0, (-1)*ctm.getValue(1, 0));
                AffineTransform ctmAT = ctm.createAffineTransform();
                ctmAT.scale(1f/imageWidth, 1f/imageHeight);
                drawer.drawImage( awtImage, ctmAT );
            }
            catch( Exception e )
            {
                LOG.error(e, e);
            }
        }
        else if(xobject instanceof PDXObjectForm)
        {
            // save the graphics state
            context.getGraphicsStack().push( (PDGraphicsState)context.getGraphicsState().clone() );
           
            PDXObjectForm form = (PDXObjectForm)xobject;
            COSStream formContentstream = form.getCOSStream();
            // find some optional resources, instead of using the current resources
            PDResources pdResources = form.getResources();
            // if there is an optional form matrix, we have to map the form space to the user space
            Matrix matrix = form.getMatrix();
            if (matrix != null)
            {
                Matrix xobjectCTM = matrix.multiply( context.getGraphicsState().getCurrentTransformationMatrix());
                context.getGraphicsState().setCurrentTransformationMatrix(xobjectCTM);
            }
            if (form.getBBox() != null)
            {
                PDGraphicsState graphicsState = context.getGraphicsState();
                PDRectangle bBox = form.getBBox();

                float x1 = bBox.getLowerLeftX();
                float y1 = bBox.getLowerLeftY();
                float x2 = bBox.getUpperRightX();
                float y2 = bBox.getUpperRightY();

                Point2D p0 = drawer.transformedPoint(x1, y1);
                Point2D p1 = drawer.transformedPoint(x2, y1);
                Point2D p2 = drawer.transformedPoint(x2, y2);
                Point2D p3 = drawer.transformedPoint(x1, y2);

                GeneralPath bboxPath = new GeneralPath();
                bboxPath.moveTo((float) p0.getX(), (float) p0.getY());
                bboxPath.lineTo((float) p1.getX(), (float) p1.getY());
                bboxPath.lineTo((float) p2.getX(), (float) p2.getY());
View Full Code Here

Examples of org.apache.pdfbox.pdfviewer.PageDrawer

     * @param arguments List
     * @throws IOException If there is an error invoking the sub object.
     */
    public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
    {
        PageDrawer drawer = (PageDrawer)context;
        PDPage page = drawer.getPage();
        COSName objectName = (COSName)arguments.get( 0 );
        Map<String, PDXObject> xobjects = drawer.getResources().getXObjects();
        PDXObject xobject = (PDXObject)xobjects.get( objectName.getName() );
        if ( xobject == null )
        {
            LOG.warn("Can't find the XObject for '"+objectName.getName()+"'");
        }
        else if( xobject instanceof PDXObjectImage )
        {
            PDXObjectImage image = (PDXObjectImage)xobject;
            try
            {
                if (image.getImageMask())
                {
                    // set the current non stroking colorstate, so that it can
                    // be used to create a stencil masked image
                    image.setStencilColor(drawer.getGraphicsState().getNonStrokingColor());
                }
                BufferedImage awtImage = image.getRGBImage();
                if (awtImage == null)
                {
                    LOG.warn("getRGBImage returned NULL");
                    return;//TODO PKOCH
                }
                int imageWidth = awtImage.getWidth();
                int imageHeight = awtImage.getHeight();
                double pageHeight = drawer.getPageSize().getHeight();

                LOG.debug("imageWidth: " + imageWidth + "\t\timageHeight: " + imageHeight);
       
                Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix();
                float yScaling = ctm.getYScale();
                float angle = (float)Math.acos(ctm.getValue(0, 0)/ctm.getXScale());
                if (ctm.getValue(0, 1) < 0 && ctm.getValue(1, 0) > 0)
                {
                    angle = (-1)*angle;
                }
                ctm.setValue(2, 1, (float)(pageHeight - ctm.getYPosition() - Math.cos(angle)*yScaling));
                ctm.setValue(2, 0, (float)(ctm.getXPosition() - Math.sin(angle)*yScaling));
                // because of the moved 0,0-reference, we have to shear in the opposite direction
                ctm.setValue(0, 1, (-1)*ctm.getValue(0, 1));
                ctm.setValue(1, 0, (-1)*ctm.getValue(1, 0));
                AffineTransform ctmAT = ctm.createAffineTransform();
                ctmAT.scale(1f/imageWidth, 1f/imageHeight);
                drawer.drawImage( awtImage, ctmAT );
            }
            catch( Exception e )
            {
                LOG.error(e, e);
            }
View Full Code Here

Examples of org.apache.pdfbox.pdfviewer.PageDrawer

            }
            graphics.translate(translateX,translateY);
            graphics.rotate((float)Math.toRadians(rotationAngle));
        }
        graphics.scale( scaling, scaling );
        PageDrawer drawer = new PageDrawer();
        drawer.drawPage( graphics, this, pageDimension );
        drawer.dispose();
        graphics.dispose();
        return retval;
    }
View Full Code Here

Examples of org.apache.pdfbox.pdfviewer.PageDrawer

    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
        throws PrinterException
    {
        try
        {
            PageDrawer drawer = new PageDrawer();
            PDRectangle cropBox = findCropBox();
            drawer.drawPage( graphics, this, cropBox.createDimension() );
            drawer.dispose();
            return PAGE_EXISTS;
        }
        catch( IOException io )
        {
            throw new PrinterIOException( io );
View Full Code Here

Examples of org.apache.pdfbox.pdfviewer.PageDrawer

     */
    public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
    {
        super.process( operator, arguments );
        float lineWidth = (float)context.getGraphicsState().getLineWidth();
        PageDrawer drawer = (PageDrawer)context;
        BasicStroke stroke = (BasicStroke)drawer.getStroke();
        if (stroke == null)
        {
            drawer.setStroke( new BasicStroke( lineWidth ) );
        }
        else
        {
            drawer.setStroke( new BasicStroke(lineWidth, stroke.getEndCap(), stroke.getLineJoin(),
                    stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase()) );
        }
    }
View Full Code Here

Examples of org.apache.pdfbox.pdfviewer.PageDrawer

     * @param operator The operator that is being executed.
     * @param arguments List
     */
    public void process(PDFOperator operator, List<COSBase> arguments)
    {
        PageDrawer drawer = (PageDrawer)context;

        COSNumber x = (COSNumber)arguments.get( 0 );
        COSNumber y = (COSNumber)arguments.get( 1 );
        COSNumber w = (COSNumber)arguments.get( 2 );
        COSNumber h = (COSNumber)arguments.get( 3 );

        double x1 = x.doubleValue();
        double y1 = y.doubleValue();
        // create a pair of coordinates for the transformation
        double x2 = w.doubleValue()+x1;
        double y2 = h.doubleValue()+y1;

        Point2D startCoords = drawer.transformedPoint(x1,y1);
        Point2D endCoords = drawer.transformedPoint(x2,y2);

        float width = (float)(endCoords.getX()-startCoords.getX());
        float height = (float)(endCoords.getY()-startCoords.getY());
        float xStart = (float)startCoords.getX();
        float yStart = (float)startCoords.getY();

        // To ensure that the path is created in the right direction,
        // we have to create it by combining single lines instead of
        // creating a simple rectangle
        GeneralPath path = drawer.getLinePath();
        path.moveTo(xStart, yStart);
        path.lineTo(xStart+width, yStart);
        path.lineTo(xStart+width, yStart+height);
        path.lineTo(xStart, yStart+height);
        // close the subpath instead of adding the last line
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.