Package com.openhtmltopdf.pdfboxout
Class PdfBoxSlowOutputDevice
java.lang.Object
com.openhtmltopdf.render.AbstractOutputDevice
com.openhtmltopdf.pdfboxout.PdfBoxSlowOutputDevice
- All Implemented Interfaces:
OutputDevice
,PdfBoxOutputDevice
public class PdfBoxSlowOutputDevice
extends AbstractOutputDevice
implements OutputDevice, PdfBoxOutputDevice
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
static class
(package private) static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate float
private float
private final List
<PdfBoxSlowOutputDevice.Bookmark> private Area
private FSColor
private PdfContentStreamAdapter
private org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination
private float
private FSColor
private PdfBoxFSFont
private de.rototor.pdfbox.graphics2d.PdfBoxGraphics2DFontTextDrawer
private final PdfBoxPerDocumentFormState
private PdfBoxLinkManager
private final List
<PdfBoxSlowOutputDevice.Metadata> private Stroke
private Stroke
private org.apache.pdfbox.pdmodel.PDPage
private float
private RenderingContext
private BidiReorderer
private Box
private SharedContext
private int
private Stroke
private FSColor
private final boolean
private AffineTransform
private org.apache.pdfbox.pdmodel.PDDocument
private static final int
private int
private static final int
private static final AffineTransform
private static final boolean
private static final int
private static final BasicStroke
private final Deque
<AffineTransform> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addMetadata
(String name, String value) Appends a name/content metadata pair to this output device.private PagePosition
<Box> calcPDFPagePosition
(CssContext c, String id, Box box) private void
void
void
close()
Perform any internal cleanup neededvoid
void
drawBorderLine
(Shape bounds, int side, int lineWidth, boolean solid) void
protected void
drawLine
(int x1, int y1, int x2, int y2) void
drawOval
(int x, int y, int width, int height) void
drawPdfAsImage
(org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject _src, Rectangle contentBounds, float intrinsicWidth, float intrinsicHeight) void
drawRect
(int x, int y, int width, int height) void
drawSelection
(RenderingContext c, InlineText inlineText) void
drawString
(String s, float x, float y, JustificationInfo info) void
drawStringFast
(String s, float x, float y, JustificationInfo info, PdfBoxFontResolver.FontDescription desc, float fontSize) void
drawWithGraphics
(float x, float y, float width, float height, OutputDeviceGraphicsDrawer renderer) Draw something using a Graphics2D at the given rectangle.void
endStructure
(Object token) private void
private void
void
void
fillOval
(int x, int y, int width, int height) void
fillRect
(int x, int y, int width, int height) findPagePositionsByID
(CssContext c, Pattern pattern) void
finish
(RenderingContext c, Box root) void
private void
followPath
(Shape s, int drawType) float
float
getClip()
float
getDeviceLength
(float length) Given a value in dots units, converts to PDF points.float
getMetadataByName
(String name) Searches the metadata name/content pairs of the current document and returns the content value from the first pair with a matching name.getMetadataListByName
(String name) Searches the metadata name/content pairs of the current document and returns any content values with a matching name in an ArrayList.org.apache.pdfbox.pdmodel.PDPage
getPage()
int
getPageRefY
(Box box) int
private AffineTransform
org.apache.pdfbox.pdmodel.PDDocument
private void
handleBookmarksInParent
(Element element) void
initializePage
(org.apache.pdfbox.pdmodel.PDPageContentStream currentPage, org.apache.pdfbox.pdmodel.PDPage page, float height) Start a page.boolean
The new (2018) fast renderer is in use.boolean
isPDF()
boolean
boolean
private void
loadBookmark
(PdfBoxSlowOutputDevice.Bookmark parent, Element bookmark) private void
loadBookmarks
(Document doc) private void
loadMetadata
(Document doc) Locates and stores all metadata values in the document head that contain name/content pairs.private Object[]
private AffineTransform
normalizeMatrix
(AffineTransform current) This returns a matrix that will convert y values to bottom up coordinate space (as used by PDFs).private AffineTransform
normalizeTransform
(AffineTransform transform) private float
normalizeY
(float y) Converts a top down unit to a bottom up PDF unit for the current page.private void
normalizeY
(float[] coords) float
normalizeY
(float y, float pageHeight) Converts a top down unit to a bottom up PDF unit for the specified page height.void
paintBackground
(RenderingContext c, Box box) We use paintBackground to do extra stuff such as processing links, forms and form controls.void
void
popClip()
Reverts the last clip on the stack.void
Reverts the transform on the stack.void
popTransforms
(List<AffineTransform> inverse) private void
void
Applies a clip on the output device.void
pushTransformLayer
(AffineTransform transform) Applies a transform on the output device.pushTransforms
(List<AffineTransform> transforms) Apply the given transform on top of the current one in the PDF graphics stream.void
realizeImage
(PdfBoxImage img) private void
void
setBidiReorderer
(BidiReorderer reorderer) void
void
void
void
setMetadata
(String name, String value) Replaces all copies of the named metadata with a single value.void
void
setRenderingContext
(RenderingContext result) void
setRenderingHint
(RenderingHints.Key key, Object value) void
void
setSharedContext
(SharedContext sharedContext) void
setStartPageNo
(int startPageNo) void
private void
setStrokeDiff
(Stroke newStroke, Stroke oldStroke) void
setWriter
(org.apache.pdfbox.pdmodel.PDDocument writer) void
startStructure
(StructureType type, Box box) Propagate the structure heirachy to allow for PDF/UA compliance.private Stroke
transformStroke
(Stroke stroke) void
translate
(double tx, double ty) private void
writeBookmark
(RenderingContext c, Box root, org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineNode parent, PdfBoxSlowOutputDevice.Bookmark bookmark) private void
writeBookmarks
(RenderingContext c, Box root, org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineNode parent, List<PdfBoxSlowOutputDevice.Bookmark> bookmarks) private void
writeOutline
(RenderingContext c, Box root) Methods inherited from class com.openhtmltopdf.render.AbstractOutputDevice
drawDebugOutline, drawText, drawTextDecoration, drawTextDecoration, getFontSpecification, paintBackground, paintBorder, paintBorder, paintCollapsedBorder, setFontSpecification
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.openhtmltopdf.extend.OutputDevice
drawDebugOutline, drawLinearGradient, drawText, drawTextDecoration, drawTextDecoration, paintBackground, paintBorder, paintBorder, paintCollapsedBorder
-
Field Details
-
FILL
private static final int FILL- See Also:
-
STROKE
private static final int STROKE- See Also:
-
CLIP
private static final int CLIP- See Also:
-
IDENTITY
-
STROKE_ONE
-
ROUND_RECT_DIMENSIONS_DOWN
private static final boolean ROUND_RECT_DIMENSIONS_DOWN -
_page
private org.apache.pdfbox.pdmodel.PDPage _page -
_cp
-
_pageHeight
private float _pageHeight -
_font
-
_transform
-
transformStack
-
clipTransformIndex
private int clipTransformIndex -
_absoluteTransformOriginX
private float _absoluteTransformOriginX -
_absoluteTransformOriginY
private float _absoluteTransformOriginY -
_color
-
_fillColor
-
_strokeColor
-
_stroke
-
_originalStroke
-
_oldStroke
-
_clip
-
_dotsPerPoint
private float _dotsPerPoint -
_writer
private org.apache.pdfbox.pdmodel.PDDocument _writer -
_defaultDestination
private org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination _defaultDestination -
_bookmarks
-
_metadata
-
_formState
-
_root
-
_startPageNo
private int _startPageNo -
_testMode
private final boolean _testMode -
_linkManager
-
_renderingContext
-
_reorderer
-
_fontTextDrawer
private de.rototor.pdfbox.graphics2d.PdfBoxGraphics2DFontTextDrawer _fontTextDrawer
-
-
Constructor Details
-
PdfBoxSlowOutputDevice
public PdfBoxSlowOutputDevice(float dotsPerPoint, boolean testMode)
-
-
Method Details
-
setWriter
public void setWriter(org.apache.pdfbox.pdmodel.PDDocument writer) - Specified by:
setWriter
in interfacePdfBoxOutputDevice
-
getWriter
public org.apache.pdfbox.pdmodel.PDDocument getWriter()- Specified by:
getWriter
in interfacePdfBoxOutputDevice
-
initializePage
public void initializePage(org.apache.pdfbox.pdmodel.PDPageContentStream currentPage, org.apache.pdfbox.pdmodel.PDPage page, float height) Start a page. A new PDF page starts a new content stream so all graphics state has to be set back to default.- Specified by:
initializePage
in interfacePdfBoxOutputDevice
-
finishPage
public void finishPage()- Specified by:
finishPage
in interfacePdfBoxOutputDevice
-
paintReplacedElement
- Specified by:
paintReplacedElement
in interfaceOutputDevice
- Specified by:
paintReplacedElement
in interfacePdfBoxOutputDevice
-
paintBackground
We use paintBackground to do extra stuff such as processing links, forms and form controls.- Specified by:
paintBackground
in interfaceOutputDevice
- Specified by:
paintBackground
in interfacePdfBoxOutputDevice
- Overrides:
paintBackground
in classAbstractOutputDevice
-
processControls
private void processControls() -
getDeviceLength
public float getDeviceLength(float length) Given a value in dots units, converts to PDF points.- Specified by:
getDeviceLength
in interfacePdfBoxOutputDevice
-
drawBorderLine
- Specified by:
drawBorderLine
in interfaceOutputDevice
- Specified by:
drawBorderLine
in interfacePdfBoxOutputDevice
-
setColor
- Specified by:
setColor
in interfaceOutputDevice
- Specified by:
setColor
in interfacePdfBoxOutputDevice
-
draw
- Specified by:
draw
in interfaceOutputDevice
- Specified by:
draw
in interfacePdfBoxOutputDevice
-
drawLine
protected void drawLine(int x1, int y1, int x2, int y2) - Specified by:
drawLine
in classAbstractOutputDevice
-
drawRect
public void drawRect(int x, int y, int width, int height) - Specified by:
drawRect
in interfaceOutputDevice
- Specified by:
drawRect
in interfacePdfBoxOutputDevice
-
drawOval
public void drawOval(int x, int y, int width, int height) - Specified by:
drawOval
in interfaceOutputDevice
- Specified by:
drawOval
in interfacePdfBoxOutputDevice
-
fill
- Specified by:
fill
in interfaceOutputDevice
- Specified by:
fill
in interfacePdfBoxOutputDevice
-
fillRect
public void fillRect(int x, int y, int width, int height) - Specified by:
fillRect
in interfaceOutputDevice
- Specified by:
fillRect
in interfacePdfBoxOutputDevice
-
fillOval
public void fillOval(int x, int y, int width, int height) - Specified by:
fillOval
in interfaceOutputDevice
- Specified by:
fillOval
in interfacePdfBoxOutputDevice
-
translate
public void translate(double tx, double ty) - Specified by:
translate
in interfaceOutputDevice
- Specified by:
translate
in interfacePdfBoxOutputDevice
-
getRenderingHint
- Specified by:
getRenderingHint
in interfaceOutputDevice
- Specified by:
getRenderingHint
in interfacePdfBoxOutputDevice
-
setRenderingHint
- Specified by:
setRenderingHint
in interfaceOutputDevice
- Specified by:
setRenderingHint
in interfacePdfBoxOutputDevice
-
setFont
- Specified by:
setFont
in interfaceOutputDevice
- Specified by:
setFont
in interfacePdfBoxOutputDevice
-
normalizeMatrix
This returns a matrix that will convert y values to bottom up coordinate space (as used by PDFs). -
drawString
- Specified by:
drawString
in interfacePdfBoxOutputDevice
-
drawStringFast
public void drawStringFast(String s, float x, float y, JustificationInfo info, PdfBoxFontResolver.FontDescription desc, float fontSize) - Specified by:
drawStringFast
in interfacePdfBoxOutputDevice
-
makeJustificationArray
-
getTransform
-
ensureFillColor
private void ensureFillColor() -
ensureStrokeColor
private void ensureStrokeColor() -
getCurrentPage
- Specified by:
getCurrentPage
in interfacePdfBoxOutputDevice
-
getPage
public org.apache.pdfbox.pdmodel.PDPage getPage()- Specified by:
getPage
in interfacePdfBoxOutputDevice
-
followPath
-
normalizeY
private float normalizeY(float y) Converts a top down unit to a bottom up PDF unit for the current page. -
normalizeY
public float normalizeY(float y, float pageHeight) Converts a top down unit to a bottom up PDF unit for the specified page height.- Specified by:
normalizeY
in interfacePdfBoxOutputDevice
-
normalizeY
private void normalizeY(float[] coords) -
setStrokeDiff
-
setStroke
- Specified by:
setStroke
in interfaceOutputDevice
- Specified by:
setStroke
in interfacePdfBoxOutputDevice
-
transformStroke
-
clip
- Specified by:
clip
in interfaceOutputDevice
- Specified by:
clip
in interfacePdfBoxOutputDevice
-
getClip
- Specified by:
getClip
in interfaceOutputDevice
- Specified by:
getClip
in interfacePdfBoxOutputDevice
-
popClip
public void popClip()Description copied from interface:OutputDevice
Reverts the last clip on the stack. The fast renderer MUST usepushClip
andpopClip
in preference toclip
andsetClip
. NOTE: The current implementation shares a stack between transforms and clips, so calls toOutputDevice.pushTransformLayer(AffineTransform)
,OutputDevice.popTransformLayer()
,OutputDevice.pushClip(Shape)
andOutputDevice.popClip()
MUST be nested correctly.- Specified by:
popClip
in interfaceOutputDevice
- Specified by:
popClip
in interfacePdfBoxOutputDevice
-
pushClip
Description copied from interface:OutputDevice
Applies a clip on the output device. This is a cumulative operation. The fast renderer MUST usepushClip
andpopClip
in preference toclip
andsetClip
. NOTE: The current implementation shares a stack between transforms and clips, so calls toOutputDevice.pushTransformLayer(AffineTransform)
,OutputDevice.popTransformLayer()
,OutputDevice.pushClip(Shape)
andOutputDevice.popClip()
MUST be nested correctly.- Specified by:
pushClip
in interfaceOutputDevice
- Specified by:
pushClip
in interfacePdfBoxOutputDevice
-
setClip
- Specified by:
setClip
in interfaceOutputDevice
- Specified by:
setClip
in interfacePdfBoxOutputDevice
-
getStroke
- Specified by:
getStroke
in interfaceOutputDevice
- Specified by:
getStroke
in interfacePdfBoxOutputDevice
-
realizeImage
- Specified by:
realizeImage
in interfacePdfBoxOutputDevice
-
drawImage
- Specified by:
drawImage
in interfaceOutputDevice
- Specified by:
drawImage
in interfacePdfBoxOutputDevice
-
drawPdfAsImage
public void drawPdfAsImage(org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject _src, Rectangle contentBounds, float intrinsicWidth, float intrinsicHeight) - Specified by:
drawPdfAsImage
in interfacePdfBoxOutputDevice
-
getDotsPerPoint
public float getDotsPerPoint()- Specified by:
getDotsPerPoint
in interfacePdfBoxOutputDevice
-
start
- Specified by:
start
in interfacePdfBoxOutputDevice
-
finish
- Specified by:
finish
in interfacePdfBoxOutputDevice
-
writeOutline
-
getPageRefY
- Specified by:
getPageRefY
in interfacePdfBoxOutputDevice
-
loadBookmarks
-
handleBookmarksInParent
-
loadBookmark
-
addMetadata
Appends a name/content metadata pair to this output device. A name or content value of null will be ignored.- Specified by:
addMetadata
in interfacePdfBoxOutputDevice
- Parameters:
name
- the name of the metadata element to add.
-
getMetadataByName
Searches the metadata name/content pairs of the current document and returns the content value from the first pair with a matching name. The search is case insensitive.- Specified by:
getMetadataByName
in interfacePdfBoxOutputDevice
- Parameters:
name
- the metadata element name to locate.- Returns:
- the content value of the first found metadata element; otherwise null.
-
getMetadataListByName
Searches the metadata name/content pairs of the current document and returns any content values with a matching name in an ArrayList. The search is case insensitive.- Specified by:
getMetadataListByName
in interfacePdfBoxOutputDevice
- Parameters:
name
- the metadata element name to locate.- Returns:
- an ArrayList with matching content values; otherwise an empty list.
-
loadMetadata
Locates and stores all metadata values in the document head that contain name/content pairs. If there is no pair with a name of "title", any content in the title element is saved as a "title" metadata item.- Parameters:
doc
- the Document level node of the parsed xhtml file.
-
setMetadata
Replaces all copies of the named metadata with a single value. A a new value of null will result in the removal of all copies of the named metadata. UseaddMetadata
to append additional values with the same name.- Specified by:
setMetadata
in interfacePdfBoxOutputDevice
- Parameters:
name
- the metadata element name to locate.
-
getMetadata
- Specified by:
getMetadata
in interfacePdfBoxOutputDevice
- Returns:
- All metadata entries
-
setRoot
- Specified by:
setRoot
in interfacePdfBoxOutputDevice
-
getStartPageNo
public int getStartPageNo()- Specified by:
getStartPageNo
in interfacePdfBoxOutputDevice
-
setStartPageNo
public void setStartPageNo(int startPageNo) - Specified by:
setStartPageNo
in interfacePdfBoxOutputDevice
-
drawSelection
- Specified by:
drawSelection
in interfaceOutputDevice
- Specified by:
drawSelection
in interfacePdfBoxOutputDevice
-
isSupportsSelection
public boolean isSupportsSelection()- Specified by:
isSupportsSelection
in interfaceOutputDevice
- Specified by:
isSupportsSelection
in interfacePdfBoxOutputDevice
-
isSupportsCMYKColors
public boolean isSupportsCMYKColors()- Specified by:
isSupportsCMYKColors
in interfaceOutputDevice
- Specified by:
isSupportsCMYKColors
in interfacePdfBoxOutputDevice
-
drawWithGraphics
public void drawWithGraphics(float x, float y, float width, float height, OutputDeviceGraphicsDrawer renderer) Description copied from interface:OutputDevice
Draw something using a Graphics2D at the given rectangle.- Specified by:
drawWithGraphics
in interfaceOutputDevice
- Specified by:
drawWithGraphics
in interfacePdfBoxOutputDevice
-
findPagePositionsByID
- Specified by:
findPagePositionsByID
in interfacePdfBoxOutputDevice
-
calcPDFPagePosition
-
setRenderingContext
- Specified by:
setRenderingContext
in interfacePdfBoxOutputDevice
-
setBidiReorderer
- Specified by:
setBidiReorderer
in interfacePdfBoxOutputDevice
-
popTransforms
- Specified by:
popTransforms
in interfaceOutputDevice
- Specified by:
popTransforms
in interfacePdfBoxOutputDevice
-
pushTransforms
Description copied from interface:OutputDevice
Apply the given transform on top of the current one in the PDF graphics stream. This is a cumulative operation. You should popTransform after the box and children are painted.- Specified by:
pushTransforms
in interfaceOutputDevice
- Specified by:
pushTransforms
in interfacePdfBoxOutputDevice
- Returns:
- the list of inverse transforms to undo the effect of this transform
-
reapplyTransforms
private void reapplyTransforms() -
getAbsoluteTransformOriginX
public float getAbsoluteTransformOriginX()- Specified by:
getAbsoluteTransformOriginX
in interfaceOutputDevice
- Specified by:
getAbsoluteTransformOriginX
in interfacePdfBoxOutputDevice
-
getAbsoluteTransformOriginY
public float getAbsoluteTransformOriginY()- Specified by:
getAbsoluteTransformOriginY
in interfaceOutputDevice
- Specified by:
getAbsoluteTransformOriginY
in interfacePdfBoxOutputDevice
-
setPaint
- Specified by:
setPaint
in interfaceOutputDevice
- Specified by:
setPaint
in interfacePdfBoxOutputDevice
-
isPDF
public boolean isPDF()- Specified by:
isPDF
in interfaceOutputDevice
- Specified by:
isPDF
in interfacePdfBoxOutputDevice
- Overrides:
isPDF
in classAbstractOutputDevice
-
close
public void close()Perform any internal cleanup needed- Specified by:
close
in interfacePdfBoxOutputDevice
-
normalizeTransform
-
pushTransformLayer
Description copied from interface:OutputDevice
Applies a transform on the output device. This is a cumulativew operation. NOTE: The current implementation shares a stack between transforms and clips, so calls toOutputDevice.pushTransformLayer(AffineTransform)
,OutputDevice.popTransformLayer()
,OutputDevice.pushClip(Shape)
andOutputDevice.popClip()
MUST be nested correctly.- Specified by:
pushTransformLayer
in interfaceOutputDevice
- Specified by:
pushTransformLayer
in interfacePdfBoxOutputDevice
-
popTransformLayer
public void popTransformLayer()Description copied from interface:OutputDevice
Reverts the transform on the stack. NOTE: The current implementation shares a stack between transforms and clips, so calls toOutputDevice.pushTransformLayer(AffineTransform)
,OutputDevice.popTransformLayer()
,OutputDevice.pushClip(Shape)
andOutputDevice.popClip()
MUST be nested correctly.- Specified by:
popTransformLayer
in interfaceOutputDevice
- Specified by:
popTransformLayer
in interfacePdfBoxOutputDevice
-
isFastRenderer
public boolean isFastRenderer()Description copied from interface:OutputDevice
The new (2018) fast renderer is in use.- Specified by:
isFastRenderer
in interfaceOutputDevice
- Specified by:
isFastRenderer
in interfacePdfBoxOutputDevice
-
clearPageState
private void clearPageState() -
startStructure
Description copied from interface:OutputDevice
Propagate the structure heirachy to allow for PDF/UA compliance.- Specified by:
startStructure
in interfaceOutputDevice
-
endStructure
- Specified by:
endStructure
in interfaceOutputDevice
-