Package org.apache.pdfbox.tools
Class ExtractImages.ImageGraphicsEngine
- java.lang.Object
-
- org.apache.pdfbox.contentstream.PDFStreamEngine
-
- org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine
-
- org.apache.pdfbox.tools.ExtractImages.ImageGraphicsEngine
-
- Enclosing class:
- ExtractImages
private class ExtractImages.ImageGraphicsEngine extends PDFGraphicsStreamEngine
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ImageGraphicsEngine(PDPage page)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
appendRectangle(java.awt.geom.Point2D p0, java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, java.awt.geom.Point2D p3)
Append a rectangle to the current path.void
clip(int windingRule)
Modify the current clipping path by intersecting it with the current path.void
closePath()
Closes the current path.void
curveTo(float x1, float y1, float x2, float y2, float x3, float y3)
Draws a curve from the current point to (x3,y3) using (x1,y1) and (x2,y2) as control points.void
drawImage(PDImage pdImage)
Draw the image.void
endPath()
Ends the current path without filling or stroking it.void
fillAndStrokePath(int windingRule)
Fills and then strokes the path.void
fillPath(int windingRule)
Fill the path.java.awt.geom.Point2D
getCurrentPoint()
Returns the current point of the current path.private boolean
hasMasks(PDImage pdImage)
void
lineTo(float x, float y)
Draws a line from the current point to (x,y).void
moveTo(float x, float y)
Starts a new path at (x,y).private void
processColor(PDColor color)
void
run()
void
shadingFill(COSName shadingName)
Fill with Shading.protected void
showGlyph(Matrix textRenderingMatrix, PDFont font, int code, Vector displacement)
Called when a glyph is to be processed.void
strokePath()
Stroke the path.private void
write2file(PDImage pdImage, java.lang.String prefix, boolean directJPEG, boolean noColorConvert)
Writes the image to a file with the filename prefix + an appropriate suffix, like "Image.jpg".-
Methods inherited from class org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine
getPage
-
Methods inherited from class org.apache.pdfbox.contentstream.PDFStreamEngine
addOperator, applyTextAdjustment, beginMarkedContentSequence, beginText, decreaseLevel, endMarkedContentSequence, endText, getAppearance, getCurrentPage, getGraphicsStackSize, getGraphicsState, getInitialMatrix, getLevel, getResources, getTextLineMatrix, getTextMatrix, increaseLevel, operatorException, processAnnotation, processChildStream, processOperator, processOperator, processPage, processSoftMask, processTilingPattern, processTilingPattern, processTransparencyGroup, processType3Stream, registerOperatorProcessor, restoreGraphicsStack, restoreGraphicsState, saveGraphicsStack, saveGraphicsState, setLineDashPattern, setTextLineMatrix, setTextMatrix, showAnnotation, showFontGlyph, showFontGlyph, showForm, showGlyph, showText, showTextString, showTextStrings, showTransparencyGroup, showType3Glyph, showType3Glyph, transformedPoint, transformWidth, unsupportedOperator
-
-
-
-
Constructor Detail
-
ImageGraphicsEngine
protected ImageGraphicsEngine(PDPage page)
-
-
Method Detail
-
run
public void run() throws java.io.IOException
- Throws:
java.io.IOException
-
drawImage
public void drawImage(PDImage pdImage) throws java.io.IOException
Description copied from class:PDFGraphicsStreamEngine
Draw the image.- Specified by:
drawImage
in classPDFGraphicsStreamEngine
- Parameters:
pdImage
- The image to draw.- Throws:
java.io.IOException
- if something went wrong.
-
appendRectangle
public void appendRectangle(java.awt.geom.Point2D p0, java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, java.awt.geom.Point2D p3) throws java.io.IOException
Description copied from class:PDFGraphicsStreamEngine
Append a rectangle to the current path.- Specified by:
appendRectangle
in classPDFGraphicsStreamEngine
- Parameters:
p0
- point P0 of the rectangle.p1
- point P1 of the rectangle.p2
- point P2 of the rectangle.p3
- point P3 of the rectangle.- Throws:
java.io.IOException
- if something went wrong.
-
clip
public void clip(int windingRule) throws java.io.IOException
Description copied from class:PDFGraphicsStreamEngine
Modify the current clipping path by intersecting it with the current path. The clipping path will not be updated until the succeeding painting operator is called.- Specified by:
clip
in classPDFGraphicsStreamEngine
- Parameters:
windingRule
- The winding rule which will be used for clipping.- Throws:
java.io.IOException
- if something went wrong.
-
moveTo
public void moveTo(float x, float y) throws java.io.IOException
Description copied from class:PDFGraphicsStreamEngine
Starts a new path at (x,y).- Specified by:
moveTo
in classPDFGraphicsStreamEngine
- Parameters:
x
- x-coordinate of the target point.y
- y-coordinate of the target point.- Throws:
java.io.IOException
- if something went wrong.
-
lineTo
public void lineTo(float x, float y) throws java.io.IOException
Description copied from class:PDFGraphicsStreamEngine
Draws a line from the current point to (x,y).- Specified by:
lineTo
in classPDFGraphicsStreamEngine
- Parameters:
x
- x-coordinate of the end point of the line.y
- y-coordinate of the end point of the line.- Throws:
java.io.IOException
- if something went wrong.
-
curveTo
public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3) throws java.io.IOException
Description copied from class:PDFGraphicsStreamEngine
Draws a curve from the current point to (x3,y3) using (x1,y1) and (x2,y2) as control points.- Specified by:
curveTo
in classPDFGraphicsStreamEngine
- Parameters:
x1
- x-coordinate of the first control point.y1
- y-coordinate of the first control point.x2
- x-coordinate of the second control point.y2
- y-coordinate of the second control point.x3
- x-coordinate of the end point of the curve.y3
- y-coordinate of the end point of the curve.- Throws:
java.io.IOException
- if something went wrong.
-
getCurrentPoint
public java.awt.geom.Point2D getCurrentPoint() throws java.io.IOException
Description copied from class:PDFGraphicsStreamEngine
Returns the current point of the current path.- Specified by:
getCurrentPoint
in classPDFGraphicsStreamEngine
- Returns:
- the current point.
- Throws:
java.io.IOException
- if something went wrong.
-
closePath
public void closePath() throws java.io.IOException
Description copied from class:PDFGraphicsStreamEngine
Closes the current path.- Specified by:
closePath
in classPDFGraphicsStreamEngine
- Throws:
java.io.IOException
- if something went wrong.
-
endPath
public void endPath() throws java.io.IOException
Description copied from class:PDFGraphicsStreamEngine
Ends the current path without filling or stroking it. The clipping path is updated here.- Specified by:
endPath
in classPDFGraphicsStreamEngine
- Throws:
java.io.IOException
- if something went wrong.
-
showGlyph
protected void showGlyph(Matrix textRenderingMatrix, PDFont font, int code, Vector displacement) throws java.io.IOException
Description copied from class:PDFStreamEngine
Called when a glyph is to be processed. This method is intended for overriding in subclasses, the default implementation does nothing.- Overrides:
showGlyph
in classPDFStreamEngine
- Parameters:
textRenderingMatrix
- the current text rendering matrix, Trmfont
- the current fontcode
- internal PDF character code for the glyphdisplacement
- the displacement (i.e. advance) of the glyph in text space- Throws:
java.io.IOException
- if the glyph cannot be processed
-
strokePath
public void strokePath() throws java.io.IOException
Description copied from class:PDFGraphicsStreamEngine
Stroke the path.- Specified by:
strokePath
in classPDFGraphicsStreamEngine
- Throws:
java.io.IOException
- If there is an IO error while stroking the path.
-
fillPath
public void fillPath(int windingRule) throws java.io.IOException
Description copied from class:PDFGraphicsStreamEngine
Fill the path.- Specified by:
fillPath
in classPDFGraphicsStreamEngine
- Parameters:
windingRule
- The winding rule this path will use.- Throws:
java.io.IOException
- if something went wrong.
-
fillAndStrokePath
public void fillAndStrokePath(int windingRule) throws java.io.IOException
Description copied from class:PDFGraphicsStreamEngine
Fills and then strokes the path.- Specified by:
fillAndStrokePath
in classPDFGraphicsStreamEngine
- Parameters:
windingRule
- The winding rule this path will use.- Throws:
java.io.IOException
- if something went wrong.
-
shadingFill
public void shadingFill(COSName shadingName) throws java.io.IOException
Description copied from class:PDFGraphicsStreamEngine
Fill with Shading.- Specified by:
shadingFill
in classPDFGraphicsStreamEngine
- Parameters:
shadingName
- The name of the Shading Dictionary to use for this fill instruction.- Throws:
java.io.IOException
- if something went wrong.
-
processColor
private void processColor(PDColor color) throws java.io.IOException
- Throws:
java.io.IOException
-
write2file
private void write2file(PDImage pdImage, java.lang.String prefix, boolean directJPEG, boolean noColorConvert) throws java.io.IOException
Writes the image to a file with the filename prefix + an appropriate suffix, like "Image.jpg". The suffix is automatically set depending on the image compression in the PDF.- Parameters:
pdImage
- the image.prefix
- the filename prefix.directJPEG
- if true, force saving JPEG/JPX streams as they are in the PDF file.noColorConvert
- if true, images are extracted with their original colorspace if possible.- Throws:
java.io.IOException
- When something is wrong with the corresponding file.
-
hasMasks
private boolean hasMasks(PDImage pdImage) throws java.io.IOException
- Throws:
java.io.IOException
-
-