Package org.apache.pdfbox.pdfviewer

Examples of org.apache.pdfbox.pdfviewer.PageDrawer


    public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
    {
        ///dwilson 3/19/07 refactor
        try
        {
            PageDrawer drawer = (PageDrawer) context;
   
            float lineWidth = (float) context.getGraphicsState().getLineWidth();
            Matrix ctm = context.getGraphicsState().getCurrentTransformationMatrix();
            if (ctm != null && ctm.getXScale() > 0)
            {
                lineWidth = lineWidth * ctm.getXScale();
            }
           
            if (lineWidth < 0.25)
            {
                lineWidth = 0.25f;
            }

            BasicStroke stroke = (BasicStroke) drawer.getStroke();
            if (stroke == null)
            {
                drawer.setStroke(new BasicStroke(lineWidth));
            }
            else
            {
                float phaseStart = stroke.getDashPhase();
                float[] dashArray = stroke.getDashArray();
                if (dashArray != null)
                {
                    if (ctm != null && ctm.getXScale() > 0)
                    {
                        for (int i = 0; i < dashArray.length; ++i)
                        {
                            dashArray[i] *= ctm.getXScale();
                        }
                    }
                    phaseStart *= ctm.getXScale();
                }
                drawer.setStroke(new BasicStroke(lineWidth, stroke.getEndCap(), stroke.getLineJoin(),
                        stroke.getMiterLimit(), dashArray, phaseStart));
            }
            drawer.strokePath();
        }
        catch (Exception exception)
        {
            log.warn(exception, exception);
        }
View Full Code Here


        BufferedImage retval = new BufferedImage( widthPx, heightPx, imageType );
        Graphics2D graphics = (Graphics2D)retval.getGraphics();
        graphics.setBackground( TRANSPARENT_WHITE );
        graphics.clearRect( 0, 0, retval.getWidth(), retval.getHeight() );
        graphics.scale( scaling, scaling );
        PageDrawer drawer = new PageDrawer();
        drawer.drawPage( graphics, this, pageDimension );

        //TODO This could be done directly by manipulating the transformation matrix before painting.
        //That could result in a better image quality.
        try
        {
View Full Code Here

        throws PrinterException
    {
        int retval = Printable.PAGE_EXISTS;
        try
        {
            PageDrawer drawer = new PageDrawer();
            PDRectangle cropBox = findCropBox();
            drawer.drawPage( graphics, this, cropBox.createDimension() );
        }
        catch( IOException io )
        {
            throw new PrinterIOException( io );
        }
View Full Code Here

     * @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() );
        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

    public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
    {
        try
        {
            ///dwilson refactoring
            PageDrawer drawer = (PageDrawer)context;
            drawer.fillPath(GeneralPath.WIND_EVEN_ODD);
        }
        catch (Exception e)
        {
            log.warn(e, e);
        }
View Full Code Here

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

        COSNumber x1 = (COSNumber)arguments.get( 0 );
        COSNumber y1 = (COSNumber)arguments.get( 1 );
        COSNumber x2 = (COSNumber)arguments.get( 2 );
        COSNumber y2 = (COSNumber)arguments.get( 3 );
        COSNumber x3 = (COSNumber)arguments.get( 4 );
        COSNumber y3 = (COSNumber)arguments.get( 5 );

        Point2D point1 = drawer.transformedPoint(x1.doubleValue(), y1.doubleValue());
        Point2D point2 = drawer.transformedPoint(x2.doubleValue(), y2.doubleValue());
        Point2D point3 = drawer.transformedPoint(x3.doubleValue(), y3.doubleValue());

        drawer.getLinePath().curveTo((float)point1.getX(), (float)point1.getY(),
                (float)point2.getX(), (float)point2.getY(), (float)point3.getX(), (float)point3.getY());
    }
View Full Code Here

    public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
    {

        try
        {
            PageDrawer drawer = (PageDrawer)context;
            drawer.setClippingPath(GeneralPath.WIND_NON_ZERO);
        }
        catch (Exception e)
        {
            log.warn(e, e);
        }
View Full Code Here

     */
    public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
    {
        super.process( operator, arguments );
        PDLineDashPattern lineDashPattern = context.getGraphicsState().getLineDashPattern();
        PageDrawer drawer = (PageDrawer)context;
        BasicStroke stroke = (BasicStroke)drawer.getStroke();
        if (stroke == null)
        {
            if (lineDashPattern.isDashPatternEmpty())
            {
                drawer.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f) );
            }
            else
            {
                drawer.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f,
                        lineDashPattern.getCOSDashPattern().toFloatArray(), lineDashPattern.getPhaseStart()) );
            }
        }
        else
        {
            if (lineDashPattern.isDashPatternEmpty())
            {
                drawer.setStroke( new BasicStroke(stroke.getLineWidth(), stroke.getEndCap(),
                        stroke.getLineJoin(), stroke.getMiterLimit()) );
            }
            else
            {
                drawer.setStroke( new BasicStroke(stroke.getLineWidth(), stroke.getEndCap(), stroke.getLineJoin(),
                        stroke.getMiterLimit(), lineDashPattern.getCOSDashPattern().toFloatArray(),
                        lineDashPattern.getPhaseStart()) );
            }
        }
    }
View Full Code Here

     *
     * @throws IOException If an error occurs while processing the font.
     */
    public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
    {
        PageDrawer drawer = (PageDrawer)context;
        GeneralPath currentPath = (GeneralPath)drawer.getLinePath().clone();

        context.processOperator( "f*", arguments );
        drawer.setLinePath( currentPath );

        context.processOperator( "S", arguments );
    }
View Full Code Here

     */
    public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
    {
        try
        {
            PageDrawer drawer = (PageDrawer)context;
            COSNumber x = (COSNumber)arguments.get( 0 );
            COSNumber y = (COSNumber)arguments.get( 1 );
            Point2D pos = drawer.transformedPoint(x.doubleValue(), y.doubleValue());
            drawer.getLinePath().moveTo((float)pos.getX(), (float)pos.getY());
        }
        catch (Exception exception)
        {
            log.warn( exception, exception);
        }
View Full Code Here

TOP

Related Classes of org.apache.pdfbox.pdfviewer.PageDrawer

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.