Class PdfBoxFastOutputDevice
java.lang.Object
com.openhtmltopdf.render.AbstractOutputDevice
com.openhtmltopdf.pdfboxout.PdfBoxFastOutputDevice
- All Implemented Interfaces:
OutputDevice, PdfBoxOutputDevice
public class PdfBoxFastOutputDevice
extends AbstractOutputDevice
implements OutputDevice, PdfBoxOutputDevice
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enumprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate PdfBoxBookmarkManagerprivate Areaprivate PdfContentStreamAdapterprivate final PdfBoxFastOutputDevice.PageStateprivate floatprivate PdfBoxFSFontprivate de.rototor.pdfbox.graphics2d.PdfBoxGraphics2DFontTextDrawerprivate final PdfBoxPerDocumentFormStateprivate PdfBoxFastLinkManagerprivate final List<PdfBoxSlowOutputDevice.Metadata> private Strokeprivate Strokeprivate org.apache.pdfbox.pdmodel.PDPageprivate floatprivate final Deque<PdfBoxFastOutputDevice.PageState> private final booleanprivate PdfBoxAccessibilityHelperprivate final booleanprivate RenderingContextprivate BidiReordererprivate Boxprivate SharedContextprivate intprivate Strokeprivate final booleanprivate AffineTransformprivate org.apache.pdfbox.pdmodel.PDDocumentprivate static final AffineTransformprivate static final booleanprivate static final BasicStroke -
Constructor Summary
ConstructorsConstructorDescriptionPdfBoxFastOutputDevice(float dotsPerPoint, boolean testMode, boolean pdfUaConform, boolean pdfAConform) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMetadata(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 voidvoidvoidclose()Perform any internal cleanup neededprivate PdfBoxFastOutputDevice.PageStatevoidvoiddrawBorderLine(Shape bounds, int side, int lineWidth, boolean solid) voidprotected voiddrawLine(int x1, int y1, int x2, int y2) voiddrawLinearGradient(FSLinearGradient backgroundLinearGradient, Shape bounds) voiddrawOval(int x, int y, int width, int height) voiddrawPdfAsImage(org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject _srcObject, Rectangle contentBounds, float intrinsicWidth, float intrinsicHeight) voiddrawRect(int x, int y, int width, int height) voiddrawSelection(RenderingContext c, InlineText inlineText) voiddrawString(String s, float x, float y, JustificationInfo info) voiddrawStringFast(String s, float x, float y, JustificationInfo info, PdfBoxFontResolver.FontDescription desc, float fontSize) voiddrawWithGraphics(float x, float y, float width, float height, OutputDeviceGraphicsDrawer renderer) Draw something using a Graphics2D at the given rectangle.voidendStructure(Object token) private voidprivate voidvoidvoidfillOval(int x, int y, int width, int height) voidfillRect(int x, int y, int width, int height) findPagePositionsByID(CssContext c, Pattern pattern) voidfinish(RenderingContext c, Box root) voidprivate voidfollowPath(Shape s, PdfBoxFastOutputDevice.GraphicsOperation drawType) floatfloatgetClip()floatgetDeviceLength(float length) Given a value in dots units, converts to PDF points.floatgetMetadataByName(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.PDPagegetPage()intgetPageRefY(Box box) intprivate AffineTransformorg.apache.pdfbox.pdmodel.PDDocumentvoidinitializePage(org.apache.pdfbox.pdmodel.PDPageContentStream currentPage, org.apache.pdfbox.pdmodel.PDPage page, float height) Start a page.booleanThe new (2018) fast renderer is in use.booleanisPDF()booleanbooleanprivate voidloadMetadata(Document doc) Locates and stores all metadata values in the document head that contain name/content pairs.private Object[]private AffineTransformnormalizeMatrix(AffineTransform current) This returns a matrix that will convert y values to bottom up coordinate space (as used by PDFs).private AffineTransformnormalizeTransform(AffineTransform transform) floatnormalizeY(float y) Converts a top down unit to a bottom up PDF unit for the current page.private voidnormalizeY(float[] coords) floatnormalizeY(float y, float pageHeight) Converts a top down unit to a bottom up PDF unit for the specified page height.voidpaintBackground(RenderingContext c, Box box) We use paintBackground to do extra stuff such as processing links, forms and form controls.voidvoidpopClip()Reverts the last clip on the stack.private PdfBoxFastOutputDevice.PageStatepopState()voidReverts the transform on the stack.voidpopTransforms(List<AffineTransform> inverse) private voidvoidApplies a clip on the output device.private voidvoidpushTransformLayer(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.voidrealizeImage(PdfBoxImage img) voidsetBidiReorderer(BidiReorderer reorderer) voidvoidvoidvoidsetMetadata(String name, String value) Replaces all copies of the named metadata with a single value.voidvoidsetRenderingContext(RenderingContext result) voidsetRenderingHint(RenderingHints.Key key, Object value) voidvoidsetSharedContext(SharedContext sharedContext) voidsetStartPageNo(int startPageNo) voidprivate voidsetStrokeDiff(Stroke newStroke, Stroke oldStroke) voidsetWriter(org.apache.pdfbox.pdmodel.PDDocument writer) voidstartStructure(StructureType type, Box box) Propagate the structure heirachy to allow for PDF/UA compliance.private StroketransformStroke(Stroke stroke) voidtranslate(double tx, double ty) Methods inherited from class AbstractOutputDevice
drawDebugOutline, drawText, drawTextDecoration, drawTextDecoration, getFontSpecification, paintBackground, paintBorder, paintBorder, paintCollapsedBorder, setFontSpecificationMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface OutputDevice
drawDebugOutline, drawText, drawTextDecoration, drawTextDecoration, paintBackground, paintBorder, paintBorder, paintCollapsedBorder
-
Field Details
-
IDENTITY
-
STROKE_ONE
-
ROUND_RECT_DIMENSIONS_DOWN
private static final boolean ROUND_RECT_DIMENSIONS_DOWN- See Also:
-
_page
private org.apache.pdfbox.pdmodel.PDPage _page -
_cp
-
_pageHeight
private float _pageHeight -
_font
-
_transform
-
_desiredPageState
-
_pageStateStack
-
_stroke
-
_originalStroke
-
_oldStroke
-
_clip
-
_dotsPerPoint
private float _dotsPerPoint -
_writer
private org.apache.pdfbox.pdmodel.PDDocument _writer -
_bmManager
-
_metadata
-
_formState
-
_root
-
_startPageNo
private int _startPageNo -
_testMode
private final boolean _testMode -
_linkManager
-
_renderingContext
-
_reorderer
-
_fontTextDrawer
private de.rototor.pdfbox.graphics2d.PdfBoxGraphics2DFontTextDrawer _fontTextDrawer -
_pdfUa
-
_pdfUaConform
private final boolean _pdfUaConform -
_pdfAConform
private final boolean _pdfAConform
-
-
Constructor Details
-
PdfBoxFastOutputDevice
public PdfBoxFastOutputDevice(float dotsPerPoint, boolean testMode, boolean pdfUaConform, boolean pdfAConform)
-
-
Method Details
-
setWriter
public void setWriter(org.apache.pdfbox.pdmodel.PDDocument writer) - Specified by:
setWriterin interfacePdfBoxOutputDevice
-
getWriter
public org.apache.pdfbox.pdmodel.PDDocument getWriter()- Specified by:
getWriterin 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:
initializePagein interfacePdfBoxOutputDevice
-
currentState
-
pushState
-
popState
-
finishPage
public void finishPage()- Specified by:
finishPagein interfacePdfBoxOutputDevice
-
paintReplacedElement
- Specified by:
paintReplacedElementin interfaceOutputDevice- Specified by:
paintReplacedElementin interfacePdfBoxOutputDevice
-
paintBackground
We use paintBackground to do extra stuff such as processing links, forms and form controls.- Specified by:
paintBackgroundin interfaceOutputDevice- Specified by:
paintBackgroundin interfacePdfBoxOutputDevice- Overrides:
paintBackgroundin classAbstractOutputDevice
-
processControls
private void processControls() -
getDeviceLength
public float getDeviceLength(float length) Given a value in dots units, converts to PDF points.- Specified by:
getDeviceLengthin interfacePdfBoxOutputDevice
-
drawBorderLine
- Specified by:
drawBorderLinein interfaceOutputDevice- Specified by:
drawBorderLinein interfacePdfBoxOutputDevice
-
setColor
- Specified by:
setColorin interfaceOutputDevice- Specified by:
setColorin interfacePdfBoxOutputDevice
-
draw
- Specified by:
drawin interfaceOutputDevice- Specified by:
drawin interfacePdfBoxOutputDevice
-
drawLine
protected void drawLine(int x1, int y1, int x2, int y2) - Specified by:
drawLinein classAbstractOutputDevice
-
drawRect
public void drawRect(int x, int y, int width, int height) - Specified by:
drawRectin interfaceOutputDevice- Specified by:
drawRectin interfacePdfBoxOutputDevice
-
drawOval
public void drawOval(int x, int y, int width, int height) - Specified by:
drawOvalin interfaceOutputDevice- Specified by:
drawOvalin interfacePdfBoxOutputDevice
-
fill
- Specified by:
fillin interfaceOutputDevice- Specified by:
fillin interfacePdfBoxOutputDevice
-
fillRect
public void fillRect(int x, int y, int width, int height) - Specified by:
fillRectin interfaceOutputDevice- Specified by:
fillRectin interfacePdfBoxOutputDevice
-
fillOval
public void fillOval(int x, int y, int width, int height) - Specified by:
fillOvalin interfaceOutputDevice- Specified by:
fillOvalin interfacePdfBoxOutputDevice
-
translate
public void translate(double tx, double ty) - Specified by:
translatein interfaceOutputDevice- Specified by:
translatein interfacePdfBoxOutputDevice
-
getRenderingHint
- Specified by:
getRenderingHintin interfaceOutputDevice- Specified by:
getRenderingHintin interfacePdfBoxOutputDevice
-
setRenderingHint
- Specified by:
setRenderingHintin interfaceOutputDevice- Specified by:
setRenderingHintin interfacePdfBoxOutputDevice
-
setFont
- Specified by:
setFontin interfaceOutputDevice- Specified by:
setFontin interfacePdfBoxOutputDevice
-
normalizeMatrix
This returns a matrix that will convert y values to bottom up coordinate space (as used by PDFs). -
drawString
- Specified by:
drawStringin interfacePdfBoxOutputDevice
-
drawStringFast
public void drawStringFast(String s, float x, float y, JustificationInfo info, PdfBoxFontResolver.FontDescription desc, float fontSize) - Specified by:
drawStringFastin interfacePdfBoxOutputDevice
-
makeJustificationArray
-
getTransform
-
ensureFillColor
private void ensureFillColor() -
ensureStrokeColor
private void ensureStrokeColor() -
getCurrentPage
- Specified by:
getCurrentPagein interfacePdfBoxOutputDevice
-
getPage
public org.apache.pdfbox.pdmodel.PDPage getPage()- Specified by:
getPagein interfacePdfBoxOutputDevice
-
followPath
-
normalizeY
public 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:
normalizeYin interfacePdfBoxOutputDevice
-
normalizeY
private void normalizeY(float[] coords) -
setStrokeDiff
-
setStroke
- Specified by:
setStrokein interfaceOutputDevice- Specified by:
setStrokein interfacePdfBoxOutputDevice
-
transformStroke
-
clip
- Specified by:
clipin interfaceOutputDevice- Specified by:
clipin interfacePdfBoxOutputDevice
-
getClip
- Specified by:
getClipin interfaceOutputDevice- Specified by:
getClipin interfacePdfBoxOutputDevice
-
popClip
public void popClip()Description copied from interface:OutputDeviceReverts the last clip on the stack. The fast renderer MUST usepushClipandpopClipin preference toclipandsetClip. 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:
popClipin interfaceOutputDevice- Specified by:
popClipin interfacePdfBoxOutputDevice
-
pushClip
Description copied from interface:OutputDeviceApplies a clip on the output device. This is a cumulative operation. The fast renderer MUST usepushClipandpopClipin preference toclipandsetClip. 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:
pushClipin interfaceOutputDevice- Specified by:
pushClipin interfacePdfBoxOutputDevice
-
setClip
- Specified by:
setClipin interfaceOutputDevice- Specified by:
setClipin interfacePdfBoxOutputDevice
-
getStroke
- Specified by:
getStrokein interfaceOutputDevice- Specified by:
getStrokein interfacePdfBoxOutputDevice
-
realizeImage
- Specified by:
realizeImagein interfacePdfBoxOutputDevice
-
drawLinearGradient
- Specified by:
drawLinearGradientin interfaceOutputDevice
-
drawImage
- Specified by:
drawImagein interfaceOutputDevice- Specified by:
drawImagein interfacePdfBoxOutputDevice
-
drawPdfAsImage
public void drawPdfAsImage(org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject _srcObject, Rectangle contentBounds, float intrinsicWidth, float intrinsicHeight) - Specified by:
drawPdfAsImagein interfacePdfBoxOutputDevice
-
getDotsPerPoint
public float getDotsPerPoint()- Specified by:
getDotsPerPointin interfacePdfBoxOutputDevice
-
start
- Specified by:
startin interfacePdfBoxOutputDevice
-
finish
- Specified by:
finishin interfacePdfBoxOutputDevice
-
getPageRefY
- Specified by:
getPageRefYin interfacePdfBoxOutputDevice
-
addMetadata
Appends a name/content metadata pair to this output device. A name or content value of null will be ignored.- Specified by:
addMetadatain 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:
getMetadataByNamein 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:
getMetadataListByNamein 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. UseaddMetadatato append additional values with the same name.- Specified by:
setMetadatain interfacePdfBoxOutputDevice- Parameters:
name- the metadata element name to locate.
-
getMetadata
- Specified by:
getMetadatain interfacePdfBoxOutputDevice- Returns:
- All metadata entries
-
setRoot
- Specified by:
setRootin interfacePdfBoxOutputDevice
-
getStartPageNo
public int getStartPageNo()- Specified by:
getStartPageNoin interfacePdfBoxOutputDevice
-
setStartPageNo
public void setStartPageNo(int startPageNo) - Specified by:
setStartPageNoin interfacePdfBoxOutputDevice
-
drawSelection
- Specified by:
drawSelectionin interfaceOutputDevice- Specified by:
drawSelectionin interfacePdfBoxOutputDevice
-
isSupportsSelection
public boolean isSupportsSelection()- Specified by:
isSupportsSelectionin interfaceOutputDevice- Specified by:
isSupportsSelectionin interfacePdfBoxOutputDevice
-
isSupportsCMYKColors
public boolean isSupportsCMYKColors()- Specified by:
isSupportsCMYKColorsin interfaceOutputDevice- Specified by:
isSupportsCMYKColorsin interfacePdfBoxOutputDevice
-
drawWithGraphics
public void drawWithGraphics(float x, float y, float width, float height, OutputDeviceGraphicsDrawer renderer) Description copied from interface:OutputDeviceDraw something using a Graphics2D at the given rectangle.- Specified by:
drawWithGraphicsin interfaceOutputDevice- Specified by:
drawWithGraphicsin interfacePdfBoxOutputDevice
-
findPagePositionsByID
- Specified by:
findPagePositionsByIDin interfacePdfBoxOutputDevice
-
calcPDFPagePosition
-
setRenderingContext
- Specified by:
setRenderingContextin interfacePdfBoxOutputDevice
-
setBidiReorderer
- Specified by:
setBidiReordererin interfacePdfBoxOutputDevice
-
popTransforms
- Specified by:
popTransformsin interfaceOutputDevice- Specified by:
popTransformsin interfacePdfBoxOutputDevice
-
pushTransforms
Description copied from interface:OutputDeviceApply 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:
pushTransformsin interfaceOutputDevice- Specified by:
pushTransformsin interfacePdfBoxOutputDevice- Returns:
- the list of inverse transforms to undo the effect of this transform
-
getAbsoluteTransformOriginX
public float getAbsoluteTransformOriginX()- Specified by:
getAbsoluteTransformOriginXin interfaceOutputDevice- Specified by:
getAbsoluteTransformOriginXin interfacePdfBoxOutputDevice
-
getAbsoluteTransformOriginY
public float getAbsoluteTransformOriginY()- Specified by:
getAbsoluteTransformOriginYin interfaceOutputDevice- Specified by:
getAbsoluteTransformOriginYin interfacePdfBoxOutputDevice
-
setPaint
- Specified by:
setPaintin interfaceOutputDevice- Specified by:
setPaintin interfacePdfBoxOutputDevice
-
isPDF
public boolean isPDF()- Specified by:
isPDFin interfaceOutputDevice- Specified by:
isPDFin interfacePdfBoxOutputDevice- Overrides:
isPDFin classAbstractOutputDevice
-
close
public void close()Perform any internal cleanup needed- Specified by:
closein interfacePdfBoxOutputDevice
-
normalizeTransform
-
pushTransformLayer
Description copied from interface:OutputDeviceApplies 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:
pushTransformLayerin interfaceOutputDevice- Specified by:
pushTransformLayerin interfacePdfBoxOutputDevice
-
popTransformLayer
public void popTransformLayer()Description copied from interface:OutputDeviceReverts 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:
popTransformLayerin interfaceOutputDevice- Specified by:
popTransformLayerin interfacePdfBoxOutputDevice
-
isFastRenderer
public boolean isFastRenderer()Description copied from interface:OutputDeviceThe new (2018) fast renderer is in use.- Specified by:
isFastRendererin interfaceOutputDevice- Specified by:
isFastRendererin interfacePdfBoxOutputDevice
-
clearPageState
private void clearPageState() -
startStructure
Description copied from interface:OutputDevicePropagate the structure heirachy to allow for PDF/UA compliance.- Specified by:
startStructurein interfaceOutputDevice
-
endStructure
- Specified by:
endStructurein interfaceOutputDevice
-