public class PdfBoxGraphics2D extends Graphics2D
| Modifier and Type | Field and Description |
|---|---|
static boolean |
ENABLE_CHILD_CREATING_DEBUG
Global Flag: If set to true the Callstack when creating a
context is recorded.
|
| Constructor and Description |
|---|
PdfBoxGraphics2D(org.apache.pdfbox.pdmodel.PDDocument document,
float pixelWidth,
float pixelHeight)
Create a PDfBox Graphics2D.
|
PdfBoxGraphics2D(org.apache.pdfbox.pdmodel.PDDocument document,
int pixelWidth,
int pixelHeight)
Create a PDfBox Graphics2D.
|
PdfBoxGraphics2D(org.apache.pdfbox.pdmodel.PDDocument document,
org.apache.pdfbox.pdmodel.common.PDRectangle bbox) |
| Modifier and Type | Method and Description |
|---|---|
void |
addRenderingHints(Map<?,?> hints) |
void |
clearRect(int x,
int y,
int width,
int height) |
void |
clip(Shape shape) |
void |
clipRect(int x,
int y,
int width,
int height) |
void |
copyArea(int x,
int y,
int width,
int height,
int dx,
int dy) |
PdfBoxGraphics2D |
create()
Creates a copy of this graphics object.
|
PdfBoxGraphics2D |
create(int x,
int y,
int width,
int height) |
void |
dispose() |
void |
disposeDanglingChildGraphics()
|
void |
draw(Shape s) |
void |
drawArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle) |
void |
drawGlyphVector(GlyphVector g,
float x,
float y) |
void |
drawImage(BufferedImage img,
BufferedImageOp op,
int x,
int y) |
boolean |
drawImage(Image img,
AffineTransform xform,
ImageObserver obs) |
boolean |
drawImage(Image img,
int x,
int y,
Color bgcolor,
ImageObserver observer) |
boolean |
drawImage(Image img,
int x,
int y,
ImageObserver observer) |
boolean |
drawImage(Image img,
int x,
int y,
int width,
int height,
Color bgcolor,
ImageObserver observer) |
boolean |
drawImage(Image img,
int x,
int y,
int width,
int height,
ImageObserver observer) |
boolean |
drawImage(Image img,
int dx1,
int dy1,
int dx2,
int dy2,
int sx1,
int sy1,
int sx2,
int sy2,
Color bgcolor,
ImageObserver observer) |
boolean |
drawImage(Image img,
int dx1,
int dy1,
int dx2,
int dy2,
int sx1,
int sy1,
int sx2,
int sy2,
ImageObserver observer) |
void |
drawInMarkedContentSequence(org.apache.pdfbox.cos.COSName tagName,
IPdfBoxGraphics2DMarkedContentDrawer drawer)
Draw on the Graphics2D and enclose the drawing command with a BMC/EMC content
marking pair.
|
void |
drawInMarkedContentSequence(org.apache.pdfbox.cos.COSName tagName,
org.apache.pdfbox.pdmodel.documentinterchange.markedcontent.PDPropertyList properties,
IPdfBoxGraphics2DMarkedContentDrawer drawer)
Draw on the Graphics2D and enclose the drawing command with a BDC/EMC content
marking pair.
|
void |
drawLine(int x1,
int y1,
int x2,
int y2) |
void |
drawOval(int x,
int y,
int width,
int height) |
void |
drawPolygon(int[] xPoints,
int[] yPoints,
int nPoints) |
void |
drawPolyline(int[] xPoints,
int[] yPoints,
int nPoints) |
void |
drawRenderableImage(RenderableImage img,
AffineTransform xform) |
void |
drawRenderedImage(RenderedImage img,
AffineTransform xform) |
void |
drawRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight) |
void |
drawString(AttributedCharacterIterator iterator,
float x,
float y) |
void |
drawString(AttributedCharacterIterator iterator,
int x,
int y) |
void |
drawString(String str,
float x,
float y) |
void |
drawString(String str,
int x,
int y) |
void |
fill(Shape s) |
void |
fillArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle) |
void |
fillOval(int x,
int y,
int width,
int height) |
void |
fillPolygon(int[] xPoints,
int[] yPoints,
int nPoints) |
void |
fillRect(int x,
int y,
int width,
int height) |
void |
fillRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight) |
Color |
getBackground() |
Shape |
getClip() |
Rectangle |
getClipBounds() |
Color |
getColor() |
Composite |
getComposite() |
GraphicsConfiguration |
getDeviceConfiguration() |
Font |
getFont() |
FontMetrics |
getFontMetrics(Font f) |
FontRenderContext |
getFontRenderContext() |
Paint |
getPaint() |
Object |
getRenderingHint(RenderingHints.Key hintKey) |
RenderingHints |
getRenderingHints() |
org.apache.pdfbox.pdmodel.PDResources |
getResources()
Sometimes you need to access the PDResources and add special resources to it
for some stuff (e.g. patterns of embedded PDFs or simmilar).
|
Stroke |
getStroke() |
AffineTransform |
getTransform() |
org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject |
getXFormObject()
*AFTER* you have disposed() this Graphics2D you can access the XForm
|
boolean |
hit(Rectangle rect,
Shape s,
boolean onStroke) |
void |
rotate(double theta) |
void |
rotate(double theta,
double x,
double y) |
void |
scale(double sx,
double sy) |
void |
setBackground(Color color) |
void |
setClip(int x,
int y,
int width,
int height) |
void |
setClip(Shape clip) |
void |
setColor(Color color) |
void |
setColorMapper(IPdfBoxGraphics2DColorMapper colorMapper)
Set a new color mapper.
|
void |
setComposite(Composite comp) |
void |
setDrawControl(IPdfBoxGraphics2DDrawControl drawControl)
Set a new draw control.
|
void |
setFont(Font font) |
void |
setFontTextDrawer(IPdfBoxGraphics2DFontTextDrawer fontTextDrawer)
Set an optional text drawer.
|
void |
setImageEncoder(IPdfBoxGraphics2DImageEncoder imageEncoder)
Set a new image encoder
|
void |
setPaint(Paint paint) |
void |
setPaintApplier(IPdfBoxGraphics2DPaintApplier paintApplier)
Set a new paint applier.
|
void |
setPaintMode() |
void |
setRenderingHint(RenderingHints.Key hintKey,
Object hintValue) |
void |
setRenderingHints(Map<?,?> hints) |
void |
setStroke(Stroke stroke) |
void |
setTransform(AffineTransform Tx) |
void |
setXORMode(Color c1)
XOR Mode is currently not implemented as it's not possible in PDF.
|
void |
shear(double shx,
double shy) |
void |
transform(AffineTransform Tx) |
void |
translate(double tx,
double ty) |
void |
translate(int x,
int y) |
draw3DRect, fill3DRectdrawBytes, drawChars, drawPolygon, drawRect, fillPolygon, finalize, getClipBounds, getClipRect, getFontMetrics, hitClip, toStringpublic static boolean ENABLE_CHILD_CREATING_DEBUG
Note: Setting this to true will slow down the library. Use this only for debugging.
public PdfBoxGraphics2D(org.apache.pdfbox.pdmodel.PDDocument document,
int pixelWidth,
int pixelHeight)
throws IOException
Note: pixelWidth and pixelHeight only define the size of the coordinate space within this Graphics2D. They do not affect how big the XForm is finally displayed in the PDF.
document - The document the graphics should be used to create a XForm in.pixelWidth - the width in pixel of the drawing area.pixelHeight - the height in pixel of the drawing area.IOException - if something goes wrong with writing into the content stream of
the PDDocument.public PdfBoxGraphics2D(org.apache.pdfbox.pdmodel.PDDocument document,
float pixelWidth,
float pixelHeight)
throws IOException
Note: pixelWidth and pixelHeight only define the size of the coordinate space within this Graphics2D. They do not affect how big the XForm is finally displayed in the PDF.
document - The document the graphics should be used to create a XForm in.pixelWidth - the width in pixel of the drawing area.pixelHeight - the height in pixel of the drawing area.IOException - if something goes wrong with writing into the content stream of
the PDDocument.public PdfBoxGraphics2D(org.apache.pdfbox.pdmodel.PDDocument document,
org.apache.pdfbox.pdmodel.common.PDRectangle bbox)
throws IOException
document - The document the graphics should be used to create a XForm in.bbox - Bounding Box of the graphicsIOException - when something goes wrong with writing into the content stream of
the PDDocument.public void setColorMapper(IPdfBoxGraphics2DColorMapper colorMapper)
colorMapper - the color mapper which maps Color to PDColor.public void setImageEncoder(IPdfBoxGraphics2DImageEncoder imageEncoder)
imageEncoder - the image encoder, which encodes an image as PDImageXForm.public void setPaintApplier(IPdfBoxGraphics2DPaintApplier paintApplier)
IPdfBoxGraphics2DPaintApplier and just extend the paint
mapping for custom paint.
If the paint you map is a paint from a standard library, and you can implement the mapping using reflection please feel free to send a pull request to extend the default paint mapper.
paintApplier - the paint applier responsible for mapping the paint correctlypublic void setDrawControl(IPdfBoxGraphics2DDrawControl drawControl)
drawControl - the draw controlpublic void setFontTextDrawer(IPdfBoxGraphics2DFontTextDrawer fontTextDrawer)
fontTextDrawer - The text drawer, which can draw text using fontspublic org.apache.pdfbox.pdmodel.PDResources getResources()
public org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject getXFormObject()
public void disposeDanglingChildGraphics()
create() don't correctly dispose()
the child graphics they create. And you may not always be able to fix this
uses, as it may be in some 3rdparty library. In this case this method can
help you. It will cleanup all dangling child graphics. The child graphics can
not be used after that. This method is a workaround for a buggy old code. You
should only use it if you have to.
Note: You can only call this method on the "main" graphics, not on a child
created with create()
public void draw(Shape s)
draw in class Graphics2Dpublic void drawImage(BufferedImage img, BufferedImageOp op, int x, int y)
drawImage in class Graphics2Dpublic void drawRenderedImage(RenderedImage img, AffineTransform xform)
drawRenderedImage in class Graphics2Dpublic void drawRenderableImage(RenderableImage img, AffineTransform xform)
drawRenderableImage in class Graphics2Dpublic void drawString(String str, int x, int y)
drawString in class Graphics2Dpublic void drawString(String str, float x, float y)
drawString in class Graphics2Dpublic void drawString(AttributedCharacterIterator iterator, int x, int y)
drawString in class Graphics2Dpublic boolean drawImage(Image img, int x, int y, ImageObserver observer)
public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)
public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs)
drawImage in class Graphics2Dpublic boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)
public void drawString(AttributedCharacterIterator iterator, float x, float y)
drawString in class Graphics2Dpublic void drawGlyphVector(GlyphVector g, float x, float y)
drawGlyphVector in class Graphics2Dpublic void fill(Shape s)
fill in class Graphics2Dpublic boolean hit(Rectangle rect, Shape s, boolean onStroke)
hit in class Graphics2Dpublic GraphicsConfiguration getDeviceConfiguration()
getDeviceConfiguration in class Graphics2Dpublic void setComposite(Composite comp)
setComposite in class Graphics2Dpublic void setPaint(Paint paint)
setPaint in class Graphics2Dpublic void setStroke(Stroke stroke)
setStroke in class Graphics2Dpublic void setRenderingHint(RenderingHints.Key hintKey, Object hintValue)
setRenderingHint in class Graphics2Dpublic Object getRenderingHint(RenderingHints.Key hintKey)
getRenderingHint in class Graphics2Dpublic void setRenderingHints(Map<?,?> hints)
setRenderingHints in class Graphics2Dpublic void addRenderingHints(Map<?,?> hints)
addRenderingHints in class Graphics2Dpublic RenderingHints getRenderingHints()
getRenderingHints in class Graphics2Dpublic PdfBoxGraphics2D create()
dispose() always
on the copy after you have finished drawing with it. IllegalStateException if
you do so, but better just don't try. dispose() in reverse
order.public void drawInMarkedContentSequence(org.apache.pdfbox.cos.COSName tagName,
IPdfBoxGraphics2DMarkedContentDrawer drawer)
tagName - A COSName for to tag the marked contentdrawer - is called with a (child) graphics to draw on. Please do *not*
dispose() this graphics. Just draw on it. Any state changes on the given graphics will be reset after the
drawing is finishedpublic void drawInMarkedContentSequence(org.apache.pdfbox.cos.COSName tagName,
org.apache.pdfbox.pdmodel.documentinterchange.markedcontent.PDPropertyList properties,
IPdfBoxGraphics2DMarkedContentDrawer drawer)
tagName - A COSName for to tag the marked contentproperties - The properties to put by the marked sequencedrawer - is called with a (child) graphics to draw on. Please do *not*
dispose() this graphics. Just draw on it. Any state changes on the
given graphics will be reset after the drawing is finishedpublic PdfBoxGraphics2D create(int x, int y, int width, int height)
public void translate(int x,
int y)
translate in class Graphics2Dpublic void setPaintMode()
setPaintMode in class Graphicspublic void setXORMode(Color c1)
setXORMode in class Graphicsc1 - the XORMode Colorpublic FontMetrics getFontMetrics(Font f)
getFontMetrics in class Graphicspublic Rectangle getClipBounds()
getClipBounds in class Graphicspublic void clipRect(int x,
int y,
int width,
int height)
public void setClip(int x,
int y,
int width,
int height)
public void copyArea(int x,
int y,
int width,
int height,
int dx,
int dy)
public void drawLine(int x1,
int y1,
int x2,
int y2)
public void fillRect(int x,
int y,
int width,
int height)
public void clearRect(int x,
int y,
int width,
int height)
public void drawRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
drawRoundRect in class Graphicspublic void fillRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
fillRoundRect in class Graphicspublic void drawOval(int x,
int y,
int width,
int height)
public void fillOval(int x,
int y,
int width,
int height)
public void drawArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
public void fillArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
public void drawPolyline(int[] xPoints,
int[] yPoints,
int nPoints)
drawPolyline in class Graphicspublic void drawPolygon(int[] xPoints,
int[] yPoints,
int nPoints)
drawPolygon in class Graphicspublic void fillPolygon(int[] xPoints,
int[] yPoints,
int nPoints)
fillPolygon in class Graphicspublic void translate(double tx,
double ty)
translate in class Graphics2Dpublic void rotate(double theta)
rotate in class Graphics2Dpublic void rotate(double theta,
double x,
double y)
rotate in class Graphics2Dpublic void scale(double sx,
double sy)
scale in class Graphics2Dpublic void shear(double shx,
double shy)
shear in class Graphics2Dpublic void transform(AffineTransform Tx)
transform in class Graphics2Dpublic void setTransform(AffineTransform Tx)
setTransform in class Graphics2Dpublic AffineTransform getTransform()
getTransform in class Graphics2Dpublic Paint getPaint()
getPaint in class Graphics2Dpublic Composite getComposite()
getComposite in class Graphics2Dpublic void setBackground(Color color)
setBackground in class Graphics2Dpublic Color getBackground()
getBackground in class Graphics2Dpublic Stroke getStroke()
getStroke in class Graphics2Dpublic void clip(Shape shape)
clip in class Graphics2Dpublic FontRenderContext getFontRenderContext()
getFontRenderContext in class Graphics2DCopyright © 2022. All rights reserved.