Java Code Examples for org.apache.pdfbox.pdmodel.common.PDRectangle#getUpperRightY()

The following examples show how to use org.apache.pdfbox.pdmodel.common.PDRectangle#getUpperRightY() . 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: CompatibilityHelper.java    From pdfbox-layout with MIT License 6 votes vote down vote up
/**
    * Transform the rectangle in order to match the page rotation
    * @param rect the rectangle.
    * @param page the page.
    * @return the transformed rectangle.
    */
   public static PDRectangle transformToPageRotation(
    final PDRectangle rect, final PDPage page) {
AffineTransform transform = transformToPageRotation(page);
if (transform == null) {
    return rect;
}
float[] points = new float[] {rect.getLowerLeftX(), rect.getLowerLeftY(), rect.getUpperRightX(), rect.getUpperRightY()};
float[] rotatedPoints = new float[4]; 
transform.transform(points, 0, rotatedPoints, 0, 2);
PDRectangle rotated = new PDRectangle();
rotated.setLowerLeftX(rotatedPoints[0]);
rotated.setLowerLeftY(rotatedPoints[1]);
rotated.setUpperRightX(rotatedPoints[2]);
rotated.setUpperRightY(rotatedPoints[3]);
return rotated;
   }
 
Example 2
Source File: PDCIDFontType2.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private BoundingBox generateBoundingBox() throws IOException
{
    if (getFontDescriptor() != null)
    {
        PDRectangle bbox = getFontDescriptor().getFontBoundingBox();
        if (bbox != null &&
                (Float.compare(bbox.getLowerLeftX(), 0) != 0 || 
                 Float.compare(bbox.getLowerLeftY(), 0) != 0 ||
                 Float.compare(bbox.getUpperRightX(), 0) != 0 ||
                 Float.compare(bbox.getUpperRightY(), 0) != 0))
        {
            return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(),
                                   bbox.getUpperRightX(), bbox.getUpperRightY());
        }
    }
    return ttf.getFontBBox();
}
 
Example 3
Source File: CompatibilityHelper.java    From pdfbox-layout with MIT License 6 votes vote down vote up
/**
    * Transform the rectangle in order to match the page rotation
    * @param rect the rectangle.
    * @param page the page.
    * @return the transformed rectangle.
    */
   public static PDRectangle transformToPageRotation(
    final PDRectangle rect, final PDPage page) {
AffineTransform transform = transformToPageRotation(page);
if (transform == null) {
    return rect;
}
float[] points = new float[] {rect.getLowerLeftX(), rect.getLowerLeftY(), rect.getUpperRightX(), rect.getUpperRightY()};
float[] rotatedPoints = new float[4]; 
transform.transform(points, 0, rotatedPoints, 0, 2);
PDRectangle rotated = new PDRectangle();
rotated.setLowerLeftX(rotatedPoints[0]);
rotated.setLowerLeftY(rotatedPoints[1]);
rotated.setUpperRightX(rotatedPoints[2]);
rotated.setUpperRightY(rotatedPoints[3]);
return rotated;
   }
 
Example 4
Source File: PDCIDFontType0.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private BoundingBox generateBoundingBox()
{
    if (getFontDescriptor() != null) {
        PDRectangle bbox = getFontDescriptor().getFontBoundingBox();
        if (bbox.getLowerLeftX() != 0 || bbox.getLowerLeftY() != 0 ||
            bbox.getUpperRightX() != 0 || bbox.getUpperRightY() != 0) {
            return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(),
                                   bbox.getUpperRightX(), bbox.getUpperRightY());
        }
    }
    if (cidFont != null)
    {
        return cidFont.getFontBBox();
    }
    else
    {
        try
        {
            return t1Font.getFontBBox();
        }
        catch (IOException e)
        {
            return new BoundingBox();
        }
    }
}
 
Example 5
Source File: RotatePageContent.java    From testarea-pdfbox2 with Apache License 2.0 6 votes vote down vote up
/**
 * <a href="http://stackoverflow.com/questions/40611736/rotate-pdf-around-its-center-using-pdfbox-in-java">
 * Rotate PDF around its center using PDFBox in java
 * </a>
 * <p>
 * This test shows how to rotate the page content and then move its crop box and
 * media box accordingly to make it appear as if the content was rotated around
 * the center of the crop box.
 * </p>
 */
@Test
public void testRotateMoveBox() throws IOException
{
    try (   InputStream resource = getClass().getResourceAsStream("IRJET_Copy_Right_form.pdf")  )
    {
        PDDocument document = Loader.loadPDF(resource);
        PDPage page = document.getDocumentCatalog().getPages().get(0);
        PDPageContentStream cs = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false, false);
        Matrix matrix = Matrix.getRotateInstance(Math.toRadians(45), 0, 0);
        cs.transform(matrix);
        cs.close();

        PDRectangle cropBox = page.getCropBox();
        float cx = (cropBox.getLowerLeftX() + cropBox.getUpperRightX()) / 2;
        float cy = (cropBox.getLowerLeftY() + cropBox.getUpperRightY()) / 2;
        Point2D.Float newC = matrix.transformPoint(cx, cy);
        float tx = (float)newC.getX() - cx;
        float ty = (float)newC.getY() - cy;
        page.setCropBox(new PDRectangle(cropBox.getLowerLeftX() + tx, cropBox.getLowerLeftY() + ty, cropBox.getWidth(), cropBox.getHeight()));
        PDRectangle mediaBox = page.getMediaBox();
        page.setMediaBox(new PDRectangle(mediaBox.getLowerLeftX() + tx, mediaBox.getLowerLeftY() + ty, mediaBox.getWidth(), mediaBox.getHeight()));

        document.save(new File(RESULT_FOLDER, "IRJET_Copy_Right_form-rotated-move-box.pdf"));
    }
}
 
Example 6
Source File: RotatePageContent.java    From testarea-pdfbox2 with Apache License 2.0 6 votes vote down vote up
/**
 * <a href="http://stackoverflow.com/questions/40611736/rotate-pdf-around-its-center-using-pdfbox-in-java">
 * Rotate PDF around its center using PDFBox in java
 * </a>
 * <p>
 * This test shows how to rotate the page content around the center of its crop box
 * and then crop it to make all previously visible content fit.
 * </p>
 */
@Test
public void testRotateCenterScale() throws IOException
{
    try (   InputStream resource = getClass().getResourceAsStream("IRJET_Copy_Right_form.pdf")  )
    {
        PDDocument document = Loader.loadPDF(resource);
        PDPage page = document.getDocumentCatalog().getPages().get(0);
        PDPageContentStream cs = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false, false);

        Matrix matrix = Matrix.getRotateInstance(Math.toRadians(45), 0, 0);
        PDRectangle cropBox = page.getCropBox();
        float tx = (cropBox.getLowerLeftX() + cropBox.getUpperRightX()) / 2;
        float ty = (cropBox.getLowerLeftY() + cropBox.getUpperRightY()) / 2;

        Rectangle rectangle = cropBox.transform(matrix).getBounds();
        float scale = Math.min(cropBox.getWidth() / (float)rectangle.getWidth(), cropBox.getHeight() / (float)rectangle.getHeight());

        cs.transform(Matrix.getTranslateInstance(tx, ty));
        cs.transform(matrix);
        cs.transform(Matrix.getScaleInstance(scale, scale));
        cs.transform(Matrix.getTranslateInstance(-tx, -ty));
        cs.close();
        document.save(new File(RESULT_FOLDER, "IRJET_Copy_Right_form-rotated-center-scale.pdf"));
    }
}
 
Example 7
Source File: AppearanceGeneratorHelper.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private AffineTransform calculateMatrix(PDRectangle bbox, int rotation)
{
    if (rotation == 0)
    {
        return new AffineTransform();
    }
    float tx = 0, ty = 0;
    switch (rotation)
    {
        case 90:
            tx = bbox.getUpperRightY();
            break;
        case 180:
            tx = bbox.getUpperRightY();
            ty = bbox.getUpperRightX();
            break;
        case 270:
            ty = bbox.getUpperRightX();
            break;
        default:
            break;
    }
    Matrix matrix = Matrix.getRotateInstance(Math.toRadians(rotation), tx, ty);
    return matrix.createAffineTransform();

}
 
Example 8
Source File: RotatePageContent.java    From testarea-pdfbox2 with Apache License 2.0 6 votes vote down vote up
/**
 * <a href="http://stackoverflow.com/questions/40611736/rotate-pdf-around-its-center-using-pdfbox-in-java">
 * Rotate PDF around its center using PDFBox in java
 * </a>
 * <p>
 * This test shows how to rotate the page content around the center of its crop box.
 * </p>
 */
@Test
public void testRotateCenter() throws IOException
{
    try (   InputStream resource = getClass().getResourceAsStream("IRJET_Copy_Right_form.pdf")  )
    {
        PDDocument document = Loader.loadPDF(resource);
        PDPage page = document.getDocumentCatalog().getPages().get(0);
        PDPageContentStream cs = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false, false); 
        PDRectangle cropBox = page.getCropBox();
        float tx = (cropBox.getLowerLeftX() + cropBox.getUpperRightX()) / 2;
        float ty = (cropBox.getLowerLeftY() + cropBox.getUpperRightY()) / 2;
        cs.transform(Matrix.getTranslateInstance(tx, ty));
        cs.transform(Matrix.getRotateInstance(Math.toRadians(45), 0, 0));
        cs.transform(Matrix.getTranslateInstance(-tx, -ty));
        cs.close();
        document.save(new File(RESULT_FOLDER, "IRJET_Copy_Right_form-rotated-center.pdf"));
    }
}
 
Example 9
Source File: CloudyBorder.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Returns the updated <code>RD</code> entry for Square and Circle annotations.
 *
 * @return Annotation <code>RD</code> value.
 */
PDRectangle getRectDifference()
{
    if (annotRect == null)
    {
        float d = (float)lineWidth / 2;
        return new PDRectangle(d, d, (float)lineWidth, (float)lineWidth);
    }

    PDRectangle re = (rectWithDiff != null) ? rectWithDiff : annotRect;

    float left = re.getLowerLeftX() - (float)bboxMinX;
    float bottom = re.getLowerLeftY() - (float)bboxMinY;
    float right = (float)bboxMaxX - re.getUpperRightX();
    float top = (float)bboxMaxY - re.getUpperRightY();

    return new PDRectangle(left, bottom, right - left, top - bottom);
}
 
Example 10
Source File: PDFTextStripper.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private void fillBeadRectangles(PDPage page)
{
    beadRectangles = new ArrayList<PDRectangle>();
    for (PDThreadBead bead : page.getThreadBeads())
    {
        if (bead == null)
        {
            // can't skip, because of null entry handling in processTextPosition()
            beadRectangles.add(null);
            continue;
        }
        
        PDRectangle rect = bead.getRectangle();
        
        // bead rectangle is in PDF coordinates (y=0 is bottom),
        // glyphs are in image coordinates (y=0 is top),
        // so we must flip
        PDRectangle mediaBox = page.getMediaBox();
        float upperRightY = mediaBox.getUpperRightY() - rect.getLowerLeftY();
        float lowerLeftY = mediaBox.getUpperRightY() - rect.getUpperRightY();
        rect.setLowerLeftY(lowerLeftY);
        rect.setUpperRightY(upperRightY);
        
        // adjust for cropbox
        PDRectangle cropBox = page.getCropBox();
        if (cropBox.getLowerLeftX() != 0 || cropBox.getLowerLeftY() != 0)
        {
            rect.setLowerLeftX(rect.getLowerLeftX() - cropBox.getLowerLeftX());
            rect.setLowerLeftY(rect.getLowerLeftY() - cropBox.getLowerLeftY());
            rect.setUpperRightX(rect.getUpperRightX() - cropBox.getLowerLeftX());
            rect.setUpperRightY(rect.getUpperRightY() - cropBox.getLowerLeftY());
        }
        
        beadRectangles.add(rect);
    }
}
 
Example 11
Source File: CompatibilityHelper.java    From pdfbox-layout with MIT License 5 votes vote down vote up
/**
    * Return the quad points representation of the given rect.
    * 
    * @param rect
    *            the rectangle.
    * @param xOffset
    *            the offset in x-direction to add.
    * @param yOffset
    *            the offset in y-direction to add.
    * @return the quad points.
    */
   public static float[] toQuadPoints(final PDRectangle rect, float xOffset,
    float yOffset) {
float[] quads = new float[8];
quads[0] = rect.getLowerLeftX() + xOffset; // x1
quads[1] = rect.getUpperRightY() + yOffset; // y1
quads[2] = rect.getUpperRightX() + xOffset; // x2
quads[3] = quads[1]; // y2
quads[4] = quads[0]; // x3
quads[5] = rect.getLowerLeftY() + yOffset; // y3
quads[6] = quads[2]; // x4
quads[7] = quads[5]; // y5
return quads;
   }
 
Example 12
Source File: PdfBoxFinder.java    From testarea-pdfbox2 with Apache License 2.0 5 votes vote down vote up
/**
 * The regions ({@link Rectangle2D} instances with coordinates according
 * to the PDFBox text extraction API, e.g. for initializing the regions of
 * a {@link PDFTextStripperByArea}) the {@link PdfBoxFinder} has recognized
 * on the current page.
 */
public Map<String, Rectangle2D> getRegions() {
    PDRectangle cropBox = getPage().getCropBox();
    float xOffset = cropBox.getLowerLeftX();
    float yOffset = cropBox.getUpperRightY();
    Map<String, Rectangle2D> result = getBoxes();
    for (Map.Entry<String, Rectangle2D> entry : result.entrySet()) {
        Rectangle2D box = entry.getValue();
        Rectangle2D region = new Rectangle2D.Float(xOffset + (float)box.getX(), yOffset - (float)(box.getY() + box.getHeight()), (float)box.getWidth(), (float)box.getHeight());
        entry.setValue(region);
    }
    return result;
}
 
Example 13
Source File: PDType1CFont.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private BoundingBox generateBoundingBox() throws IOException
{
    if (getFontDescriptor() != null) {
        PDRectangle bbox = getFontDescriptor().getFontBoundingBox();
        if (bbox != null
                && (bbox.getLowerLeftX() != 0 || bbox.getLowerLeftY() != 0
                || bbox.getUpperRightX() != 0 || bbox.getUpperRightY() != 0))
        {
            return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(),
                                   bbox.getUpperRightX(), bbox.getUpperRightY());
        }
    }
    return genericFont.getFontBBox();
}
 
Example 14
Source File: PDType3Font.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private BoundingBox generateBoundingBox()
{
    PDRectangle rect = getFontBBox();
    if (rect.getLowerLeftX() == 0 && rect.getLowerLeftY() == 0
            && rect.getUpperRightX() == 0 && rect.getUpperRightY() == 0)
    {
        // Plan B: get the max bounding box of the glyphs
        COSDictionary cp = getCharProcs();
        for (COSName name : cp.keySet())
        {
            COSBase base = cp.getDictionaryObject(name);
            if (base instanceof COSStream)
            {
                PDType3CharProc charProc = new PDType3CharProc(this, (COSStream) base);
                try
                {
                    PDRectangle glyphBBox = charProc.getGlyphBBox();
                    if (glyphBBox == null)
                    {
                        continue;
                    }
                    rect.setLowerLeftX(Math.min(rect.getLowerLeftX(), glyphBBox.getLowerLeftX()));
                    rect.setLowerLeftY(Math.min(rect.getLowerLeftY(), glyphBBox.getLowerLeftY()));
                    rect.setUpperRightX(Math.max(rect.getUpperRightX(), glyphBBox.getUpperRightX()));
                    rect.setUpperRightY(Math.max(rect.getUpperRightY(), glyphBBox.getUpperRightY()));
                }
                catch (IOException ex)
                {
                    // ignore
                }
            }
        }
    }
    return new BoundingBox(rect.getLowerLeftX(), rect.getLowerLeftY(),
            rect.getUpperRightX(), rect.getUpperRightY());
}
 
Example 15
Source File: PDType1Font.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private BoundingBox generateBoundingBox() throws IOException
{
    if (getFontDescriptor() != null) {
        PDRectangle bbox = getFontDescriptor().getFontBoundingBox();
        if (bbox != null &&
                (bbox.getLowerLeftX() != 0 || bbox.getLowerLeftY() != 0 ||
                 bbox.getUpperRightX() != 0 || bbox.getUpperRightY() != 0))
        {
            return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(),
                                   bbox.getUpperRightX(), bbox.getUpperRightY());
        }
    }
    return genericFont.getFontBBox();
}
 
Example 16
Source File: PDTrueTypeFont.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private BoundingBox generateBoundingBox() throws IOException
{
    if (getFontDescriptor() != null) {
        PDRectangle bbox = getFontDescriptor().getFontBoundingBox();
        if (bbox != null)
        {
            return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(),
                    bbox.getUpperRightX(), bbox.getUpperRightY());
        }
    }
    return ttf.getFontBBox();
}
 
Example 17
Source File: PDCircleAppearanceHandler.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void generateNormalAppearance()
{
    float lineWidth = getLineWidth();
    PDAnnotationSquareCircle annotation = (PDAnnotationSquareCircle) getAnnotation();
    PDAppearanceContentStream contentStream  = null;

    try
    {
        contentStream = getNormalAppearanceAsContentStream();
        boolean hasStroke = contentStream.setStrokingColorOnDemand(getColor());
        boolean hasBackground = contentStream
                .setNonStrokingColorOnDemand(annotation.getInteriorColor());

        setOpacity(contentStream, annotation.getConstantOpacity());

        contentStream.setBorderLine(lineWidth, annotation.getBorderStyle(), annotation.getBorder());
        PDBorderEffectDictionary borderEffect = annotation.getBorderEffect();

        if (borderEffect != null && borderEffect.getStyle().equals(PDBorderEffectDictionary.STYLE_CLOUDY))
        {
            CloudyBorder cloudyBorder = new CloudyBorder(contentStream,
                borderEffect.getIntensity(), lineWidth, getRectangle());
            cloudyBorder.createCloudyEllipse(annotation.getRectDifference());
            annotation.setRectangle(cloudyBorder.getRectangle());
            annotation.setRectDifference(cloudyBorder.getRectDifference());
            PDAppearanceStream appearanceStream = annotation.getNormalAppearanceStream();
            appearanceStream.setBBox(cloudyBorder.getBBox());
            appearanceStream.setMatrix(cloudyBorder.getMatrix());
        }
        else
        {
            // Acrobat applies a padding to each side of the bbox so the line is completely within
            // the bbox.

            PDRectangle borderBox = handleBorderBox(annotation, lineWidth);

            // lower left corner
            float x0 = borderBox.getLowerLeftX();
            float y0 = borderBox.getLowerLeftY();
            // upper right corner
            float x1 = borderBox.getUpperRightX();
            float y1 = borderBox.getUpperRightY();
            // mid points
            float xm = x0 + borderBox.getWidth() / 2;
            float ym = y0 + borderBox.getHeight() / 2;
            // see http://spencermortensen.com/articles/bezier-circle/
            // the below number was calculated from sampling content streams
            // generated using Adobe Reader
            float magic = 0.55555417f;
            // control point offsets
            float vOffset = borderBox.getHeight() / 2 * magic;
            float hOffset = borderBox.getWidth() / 2 * magic;

            contentStream.moveTo(xm, y1);
            contentStream.curveTo((xm + hOffset), y1, x1, (ym + vOffset), x1, ym);
            contentStream.curveTo(x1, (ym - vOffset), (xm + hOffset), y0, xm, y0);
            contentStream.curveTo((xm - hOffset), y0, x0, (ym - vOffset), x0, ym);
            contentStream.curveTo(x0, (ym + vOffset), (xm - hOffset), y1, xm, y1);
            contentStream.closePath();
        }

        contentStream.drawShape(lineWidth, hasStroke, hasBackground);
    }
    catch (IOException e)
    {
        LOG.error(e);
    }
    finally{
        IOUtils.closeQuietly(contentStream);
    }
}
 
Example 18
Source File: AppearanceGeneratorHelper.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
private void insertGeneratedListboxAppearance(PDPageContentStream contents, PDAppearanceStream appearanceStream,
        PDRectangle contentRect, PDFont font, float fontSize) throws IOException
{
    contents.setNonStrokingColor(0);
    
    int q = field.getQ();

    if (q == PDVariableText.QUADDING_CENTERED || q == PDVariableText.QUADDING_RIGHT)
    {
        float fieldWidth = appearanceStream.getBBox().getWidth();
        float stringWidth = (font.getStringWidth(value) / FONTSCALE) * fontSize;
        float adjustAmount = fieldWidth - stringWidth - 4;

        if (q == PDVariableText.QUADDING_CENTERED)
        {
            adjustAmount = adjustAmount / 2.0f;
        }

        contents.newLineAtOffset(adjustAmount, 0);
    }
    else if (q != PDVariableText.QUADDING_LEFT)
    {
        throw new IOException("Error: Unknown justification value:" + q);
    }

    List<String> options = ((PDListBox) field).getOptionsDisplayValues();
    int numOptions = options.size();

    float yTextPos = contentRect.getUpperRightY();

    int topIndex = ((PDListBox) field).getTopIndex();
    
    for (int i = topIndex; i < numOptions; i++)
    {
       
        if (i == topIndex)
        {
            yTextPos = yTextPos - font.getFontDescriptor().getAscent() / FONTSCALE * fontSize;
        }
        else
        {
            yTextPos = yTextPos - font.getBoundingBox().getHeight() / FONTSCALE * fontSize;
            contents.beginText();
        }

        contents.newLineAtOffset(contentRect.getLowerLeftX(), yTextPos);
        contents.showText(options.get(i));

        if (i != (numOptions - 1))
        {
            contents.endText();
        }
    }
}
 
Example 19
Source File: GenericSegment.java    From pdfxtk with Apache License 2.0 4 votes vote down vote up
public void setBoundingBox(PDRectangle bBox)
{
	x1 = bBox.getLowerLeftX(); x2 = bBox.getUpperRightX();
	y1 = bBox.getLowerLeftY(); y2 = bBox.getUpperRightY();
}
 
Example 20
Source File: PageDrawer.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void showTransparencyGroup(PDTransparencyGroup form) throws IOException
{
    if (!isContentRendered())
    {
        return;
    }
    TransparencyGroup group =
            new TransparencyGroup(form, false, getGraphicsState().getCurrentTransformationMatrix(), null);
    BufferedImage image = group.getImage();
    if (image == null)
    {
        // image is empty, don't bother
        return;
    }

    graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite());
    setClip();

    // both the DPI xform and the CTM were already applied to the group, so all we do
    // here is draw it directly onto the Graphics2D device at the appropriate position
    PDRectangle bbox = group.getBBox();
    AffineTransform savedTransform = graphics.getTransform();

    Matrix m = new Matrix(xform);
    float xScale = Math.abs(m.getScalingFactorX());
    float yScale = Math.abs(m.getScalingFactorY());
    
    AffineTransform transform = new AffineTransform(xform);
    transform.scale(1.0 / xScale, 1.0 / yScale);
    graphics.setTransform(transform);

    // adjust bbox (x,y) position at the initial scale + cropbox
    float x = bbox.getLowerLeftX() - pageSize.getLowerLeftX();
    float y = pageSize.getUpperRightY() - bbox.getUpperRightY();

    if (flipTG)
    {
        graphics.translate(0, image.getHeight());
        graphics.scale(1, -1);
    }
    else
    {
        graphics.translate(x * xScale, y * yScale);
    }

    PDSoftMask softMask = getGraphicsState().getSoftMask();
    if (softMask != null)
    {
        Paint awtPaint = new TexturePaint(image,
                new Rectangle2D.Float(0, 0, image.getWidth(), image.getHeight()));
        awtPaint = applySoftMaskToPaint(awtPaint, softMask);
        graphics.setPaint(awtPaint);
        if (isContentRendered())
        {
            graphics.fill(
                    new Rectangle2D.Float(0, 0, bbox.getWidth() * xScale, bbox.getHeight() * yScale));
        }
    }
    else
    {
        if (isContentRendered())
        {
            try
            {
                graphics.drawImage(image, null, null);
            }
            catch (InternalError ie)
            {
                LOG.error("Exception drawing image, see JDK-6689349, " +
                          "try rendering into a BufferedImage instead", ie);
            }
        }
    }

    graphics.setTransform(savedTransform);
}