Klasse PdfBoxGraphics2D

java.lang.Object
java.awt.Graphics
java.awt.Graphics2D
de.rototor.pdfbox.graphics2d.PdfBoxGraphics2D

public class PdfBoxGraphics2D extends Graphics2D
Graphics 2D Adapter for PDFBox.
  • Felddetails

    • ENABLE_CHILD_CREATING_DEBUG

      public static boolean ENABLE_CHILD_CREATING_DEBUG
      Global Flag: If set to true the Callstack when creating a context is recorded.

      Note: Setting this to true will slow down the library. Use this only for debugging.

  • Konstruktordetails

    • PdfBoxGraphics2D

      public PdfBoxGraphics2D(org.apache.pdfbox.pdmodel.PDDocument document, int pixelWidth, int pixelHeight) throws IOException
      Create a PDfBox Graphics2D. This size is used for the BBox of the XForm. So everything drawn outside the rectangle (0x0)-(pixelWidth,pixelHeight) will be clipped.

      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.

      Parameter:
      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.
      Löst aus:
      IOException - if something goes wrong with writing into the content stream of the PDDocument.
    • PdfBoxGraphics2D

      public PdfBoxGraphics2D(org.apache.pdfbox.pdmodel.PDDocument document, float pixelWidth, float pixelHeight) throws IOException
      Create a PDfBox Graphics2D. This size is used for the BBox of the XForm. So everything drawn outside the rectangle (0x0)-(pixelWidth,pixelHeight) will be clipped.

      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.

      Parameter:
      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.
      Löst aus:
      IOException - if something goes wrong with writing into the content stream of the PDDocument.
    • PdfBoxGraphics2D

      public PdfBoxGraphics2D(org.apache.pdfbox.pdmodel.PDDocument document, org.apache.pdfbox.pdmodel.common.PDRectangle bbox) throws IOException
      Parameter:
      document - The document the graphics should be used to create a XForm in.
      bbox - Bounding Box of the graphics
      Löst aus:
      IOException - when something goes wrong with writing into the content stream of the PDDocument.
  • Methodendetails

    • setColorMapper

      public void setColorMapper(IPdfBoxGraphics2DColorMapper colorMapper)
      Set a new color mapper.
      Parameter:
      colorMapper - the color mapper which maps Color to PDColor.
    • setImageEncoder

      public void setImageEncoder(IPdfBoxGraphics2DImageEncoder imageEncoder)
      Set a new image encoder
      Parameter:
      imageEncoder - the image encoder, which encodes an image as PDImageXForm.
    • setPaintApplier

      public void setPaintApplier(IPdfBoxGraphics2DPaintApplier paintApplier)
      Set a new paint applier. You should always derive your custom paint applier from the 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.

      Parameter:
      paintApplier - the paint applier responsible for mapping the paint correctly
    • setDrawControl

      public void setDrawControl(IPdfBoxGraphics2DDrawControl drawControl)
      Set a new draw control. This allows you to influence fill() and draw() operations. drawString() is only influence if the text is drawn as vector shape.
      Parameter:
      drawControl - the draw control
    • setFontTextDrawer

      public void setFontTextDrawer(IPdfBoxGraphics2DFontTextDrawer fontTextDrawer)
      Set an optional text drawer. By default, all text is vectorized and drawn using vector shapes. To embed fonts into a PDF file it is necessary to have the underlying TTF file. The java.awt.Font class does not provide that. The FontTextDrawer must perform the java.awt.Font <=> PDFont mapping and also must perform the text layout. If it can not map the text or font correctly, the font drawing falls back to vectoring the text.
      Parameter:
      fontTextDrawer - The text drawer, which can draw text using fonts
    • getResources

      public 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). For that you need the PDResources associated with the XForm.

      It's identlical with getXFormObject().getResources(), with the difference beeing that you can access it while the Graphics2D is not yet disposed.

      Gibt zurück:
      the PDResources of the resulting XForm
    • getXFormObject

      public org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject getXFormObject()
      *AFTER* you have disposed() this Graphics2D you can access the XForm
      Gibt zurück:
      the PDFormXObject which resulted in this graphics
    • disposeDanglingChildGraphics

      public void disposeDanglingChildGraphics()
      Sometimes the users of 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()

    • dispose

      public void dispose()
      Angegeben von:
      dispose in Klasse Graphics
    • draw

      public void draw(Shape s)
      Angegeben von:
      draw in Klasse Graphics2D
    • drawImage

      public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y)
      Angegeben von:
      drawImage in Klasse Graphics2D
    • drawRenderedImage

      public void drawRenderedImage(RenderedImage img, AffineTransform xform)
      Angegeben von:
      drawRenderedImage in Klasse Graphics2D
    • drawRenderableImage

      public void drawRenderableImage(RenderableImage img, AffineTransform xform)
      Angegeben von:
      drawRenderableImage in Klasse Graphics2D
    • drawString

      public void drawString(String str, int x, int y)
      Angegeben von:
      drawString in Klasse Graphics2D
    • drawString

      public void drawString(String str, float x, float y)
      Angegeben von:
      drawString in Klasse Graphics2D
    • drawString

      public void drawString(AttributedCharacterIterator iterator, int x, int y)
      Angegeben von:
      drawString in Klasse Graphics2D
    • drawImage

      public boolean drawImage(Image img, int x, int y, ImageObserver observer)
      Angegeben von:
      drawImage in Klasse Graphics
    • drawImage

      public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
      Angegeben von:
      drawImage in Klasse Graphics
    • drawImage

      public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)
      Angegeben von:
      drawImage in Klasse Graphics
    • drawImage

      public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)
      Angegeben von:
      drawImage in Klasse Graphics
    • drawImage

      public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
      Angegeben von:
      drawImage in Klasse Graphics
    • drawImage

      public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs)
      Angegeben von:
      drawImage in Klasse Graphics2D
    • drawImage

      public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)
      Angegeben von:
      drawImage in Klasse Graphics
    • drawString

      public void drawString(AttributedCharacterIterator iterator, float x, float y)
      Angegeben von:
      drawString in Klasse Graphics2D
    • drawGlyphVector

      public void drawGlyphVector(GlyphVector g, float x, float y)
      Angegeben von:
      drawGlyphVector in Klasse Graphics2D
    • fill

      public void fill(Shape s)
      Angegeben von:
      fill in Klasse Graphics2D
    • hit

      public boolean hit(Rectangle rect, Shape s, boolean onStroke)
      Angegeben von:
      hit in Klasse Graphics2D
    • getDeviceConfiguration

      public GraphicsConfiguration getDeviceConfiguration()
      Angegeben von:
      getDeviceConfiguration in Klasse Graphics2D
    • setComposite

      public void setComposite(Composite comp)
      Angegeben von:
      setComposite in Klasse Graphics2D
    • setPaint

      public void setPaint(Paint paint)
      Angegeben von:
      setPaint in Klasse Graphics2D
    • setStroke

      public void setStroke(Stroke stroke)
      Angegeben von:
      setStroke in Klasse Graphics2D
    • setRenderingHint

      public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue)
      Angegeben von:
      setRenderingHint in Klasse Graphics2D
    • getRenderingHint

      public Object getRenderingHint(RenderingHints.Key hintKey)
      Angegeben von:
      getRenderingHint in Klasse Graphics2D
    • setRenderingHints

      public void setRenderingHints(Map<?,?> hints)
      Angegeben von:
      setRenderingHints in Klasse Graphics2D
    • addRenderingHints

      public void addRenderingHints(Map<?,?> hints)
      Angegeben von:
      addRenderingHints in Klasse Graphics2D
    • getRenderingHints

      public RenderingHints getRenderingHints()
      Angegeben von:
      getRenderingHints in Klasse Graphics2D
    • create

      public PdfBoxGraphics2D create()
      Creates a copy of this graphics object. Please call dispose() always on the copy after you have finished drawing with it.

      Never draw both in this copy and its parent graphics at the same time, as they all write to the same content stream. This will create a broken PDF content stream. You should get an IllegalStateException if you do so, but better just don't try.

      The copy allows you to have different transforms, paints, etc. than the parent graphics context without affecting the parent. You may also call create() on a copy, but always remember to call dispose() in reverse order.
      Angegeben von:
      create in Klasse Graphics
      Gibt zurück:
      a copy of this Graphics.
    • drawInMarkedContentSequence

      public 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. See the PDF Spec about "Marked Content" for details.
      Parameter:
      tagName - A COSName for to tag the marked content
      drawer - 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 finished
    • drawInMarkedContentSequence

      public 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. See the PDF Spec about "Marked Content" for details.
      Parameter:
      tagName - A COSName for to tag the marked content
      properties - The properties to put by the marked sequence
      drawer - 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 finished
    • create

      public PdfBoxGraphics2D create(int x, int y, int width, int height)
      Setzt außer Kraft:
      create in Klasse Graphics
    • translate

      public void translate(int x, int y)
      Angegeben von:
      translate in Klasse Graphics2D
    • getColor

      public Color getColor()
      Angegeben von:
      getColor in Klasse Graphics
    • setColor

      public void setColor(Color color)
      Angegeben von:
      setColor in Klasse Graphics
    • setPaintMode

      public void setPaintMode()
      Angegeben von:
      setPaintMode in Klasse Graphics
    • setXORMode

      public void setXORMode(Color c1)
      XOR Mode is currently not implemented as it's not possible in PDF. This mode is ignored.
      Angegeben von:
      setXORMode in Klasse Graphics
      Parameter:
      c1 - the XORMode Color
    • getFont

      public Font getFont()
      Angegeben von:
      getFont in Klasse Graphics
    • setFont

      public void setFont(Font font)
      Angegeben von:
      setFont in Klasse Graphics
    • getFontMetrics

      public FontMetrics getFontMetrics(Font f)
      Angegeben von:
      getFontMetrics in Klasse Graphics
    • getClipBounds

      public Rectangle getClipBounds()
      Angegeben von:
      getClipBounds in Klasse Graphics
    • clipRect

      public void clipRect(int x, int y, int width, int height)
      Angegeben von:
      clipRect in Klasse Graphics
    • setClip

      public void setClip(int x, int y, int width, int height)
      Angegeben von:
      setClip in Klasse Graphics
    • getClip

      public Shape getClip()
      Angegeben von:
      getClip in Klasse Graphics
    • setClip

      public void setClip(Shape clip)
      Angegeben von:
      setClip in Klasse Graphics
    • copyArea

      public void copyArea(int x, int y, int width, int height, int dx, int dy)
      Angegeben von:
      copyArea in Klasse Graphics
    • drawLine

      public void drawLine(int x1, int y1, int x2, int y2)
      Angegeben von:
      drawLine in Klasse Graphics
    • fillRect

      public void fillRect(int x, int y, int width, int height)
      Angegeben von:
      fillRect in Klasse Graphics
    • drawRect

      public void drawRect(int x, int y, int width, int height)
      Setzt außer Kraft:
      drawRect in Klasse Graphics
    • clearRect

      public void clearRect(int x, int y, int width, int height)
      Angegeben von:
      clearRect in Klasse Graphics
    • drawRoundRect

      public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
      Angegeben von:
      drawRoundRect in Klasse Graphics
    • fillRoundRect

      public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
      Angegeben von:
      fillRoundRect in Klasse Graphics
    • drawOval

      public void drawOval(int x, int y, int width, int height)
      Angegeben von:
      drawOval in Klasse Graphics
    • fillOval

      public void fillOval(int x, int y, int width, int height)
      Angegeben von:
      fillOval in Klasse Graphics
    • drawArc

      public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
      Angegeben von:
      drawArc in Klasse Graphics
    • fillArc

      public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
      Angegeben von:
      fillArc in Klasse Graphics
    • drawPolyline

      public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
      Angegeben von:
      drawPolyline in Klasse Graphics
    • drawPolygon

      public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
      Angegeben von:
      drawPolygon in Klasse Graphics
    • fillPolygon

      public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
      Angegeben von:
      fillPolygon in Klasse Graphics
    • translate

      public void translate(double tx, double ty)
      Angegeben von:
      translate in Klasse Graphics2D
    • rotate

      public void rotate(double theta)
      Angegeben von:
      rotate in Klasse Graphics2D
    • rotate

      public void rotate(double theta, double x, double y)
      Angegeben von:
      rotate in Klasse Graphics2D
    • scale

      public void scale(double sx, double sy)
      Angegeben von:
      scale in Klasse Graphics2D
    • shear

      public void shear(double shx, double shy)
      Angegeben von:
      shear in Klasse Graphics2D
    • transform

      public void transform(AffineTransform Tx)
      Angegeben von:
      transform in Klasse Graphics2D
    • setTransform

      public void setTransform(AffineTransform Tx)
      Angegeben von:
      setTransform in Klasse Graphics2D
    • getTransform

      public AffineTransform getTransform()
      Angegeben von:
      getTransform in Klasse Graphics2D
    • getPaint

      public Paint getPaint()
      Angegeben von:
      getPaint in Klasse Graphics2D
    • getComposite

      public Composite getComposite()
      Angegeben von:
      getComposite in Klasse Graphics2D
    • setBackground

      public void setBackground(Color color)
      Angegeben von:
      setBackground in Klasse Graphics2D
    • getBackground

      public Color getBackground()
      Angegeben von:
      getBackground in Klasse Graphics2D
    • getStroke

      public Stroke getStroke()
      Angegeben von:
      getStroke in Klasse Graphics2D
    • clip

      public void clip(Shape shape)
      Angegeben von:
      clip in Klasse Graphics2D
    • getFontRenderContext

      public FontRenderContext getFontRenderContext()
      Angegeben von:
      getFontRenderContext in Klasse Graphics2D