Package com.storedobject.pdf
Class PDF
java.lang.Object
com.storedobject.pdf.PDF
- All Implemented Interfaces:
Executable
,ContentProducer
,ContentType
,Closeable
,AutoCloseable
,Runnable
- Direct Known Subclasses:
PDFReport
This class is used to create PDF output. The only abstract method in this class is generateContent()
and is the one where you really print the report content. In most cases, you may use
PDFReport
class instead of this class directly.- Author:
- Syam
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
PDF.ObjectFormTable<T extends StoredObject>
Define a table whereStoredObject
instances can be added in a "form" style (Each attribute is printed in a separate row).class
PDF.ObjectTable<T extends StoredObject>
Define a table whereStoredObject
instances can be added as rows.class
Representation of 'Content' from another PDF.class
Used to define text to include in the PDF document. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPDF()
Constructor.PDF
(boolean letterhead) Constructor.Constructor.Constructor.PDF
(OutputStream out) Constructor.PDF
(OutputStream out, boolean letterhead) Constructor.PDF
(OutputStream out, boolean letterhead, PDFImage logo) Constructor.PDF
(OutputStream out, PDFImage logo) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
aboutToAddExternalContent
(int page, PDFImage pageImage) void
Adds an object to the document.void
Add an object to the document.void
Add an object to the document.void
Add an object to the document.void
addBlankRow
(PDFTable table) Adds a blank row to the table.void
addBlankRow
(PDFTable table, int fromColumn) Adds a blank row to the table.void
addBlankRow
(PDFTable table, int fromColumn, int toColumn) Adds a blank row to the table.void
addCentered
(Object any) Add an object to the document.void
addContent
(ContentProducer externalPDF, float scalePercentage) Add content from another PDF content producer.void
addContent
(ContentProducer externalPDF, float scalePercentage, int startingPage, int endingPage, int... pagesToSkip) Add content from another PDF content producer.void
addContent
(FileData externalPDF, float scalePercentage) Add content from a PDF file.void
addContent
(FileData externalPDF, float scalePercentage, int startingPage, int endingPage, int... pagesToSkip) Add content from a PDF file.void
addContent
(StreamData externalPDF, float scalePercentage) Add content from a PDF stream.void
addContent
(StreamData externalPDF, float scalePercentage, int startingPage, int endingPage, int... pagesToSkip) Add content from a PDF stream.void
addContent
(PDFImage image) Add an image to the next page as the content.void
addContent
(PDFImage image, float scalePercentage) Add an image to the next page as the content.void
addContent
(InputStream externalPDF, float scalePercentage) Add content from a PDF stream.void
addContent
(InputStream externalPDF, float scalePercentage, int startingPage, int endingPage, int... pagesToSkip) Add content from a PDF stream.void
addGap
(int verticalGap) Add some vertical gap (Typically used to add space before adding a table).void
Add HTML content to the rest of the pagevoid
Add HTML content at the current position with the given width and heightvoid
Add HTML content at the given position with the given width and heightvoid
addHTML
(String html, StringFiller filler) Add HTML content to the rest of the pagevoid
addHTML
(String html, StringFiller filler, int width, int height) Add HTML content at the current position with the given width and heightvoid
addHTML
(String html, StringFiller filler, int positionX, int positionY, int width, int height) Add HTML content at the given position with the given width and heightvoid
Add an image at position (0, 0) in the current page.void
Add an image at some absolute position in the current page.void
Add an image at some absolute position in the current page.void
addingExternalContent
(int page, PDFImage content) void
addTitles
(PDFTable table, int pointSize, StringList titles) Add title texts to table.void
Add title texts to table.void
Add title texts to table.void
addTitles
(PDFTable table, StringList titles) Add title texts to table.void
Add title texts to table.void
void
addToTable
(PDFTable table, Object any) Adds an object to the given PDFTable as a PDFCell.void
addToTable
(PDFTable table, Object any, boolean rightAligned) Adds an object to the given PDFTable as a PDFCell.void
addToTable
(PDFTable table, Object any, boolean rightAligned, Function<PDFCell, PDFCell> cellCustomizer) Adds an object to the given PDFTable as a PDFCell.void
addToTable
(PDFTable table, Object any, int horizontalAlignment) Adds an object to the given PDFTable as a PDFCell.void
addToTable
(PDFTable table, Object any, int horizontalAlignment, int verticalAlignment) Adds an object to the given PDFTable as a PDFCell.void
addToTable
(PDFTable table, Object any, int horizontalAlignment, int verticalAlignment, Function<PDFCell, PDFCell> cellCustomizer) Adds an object to the given PDFTable as a PDFCell.void
addToTable
(PDFTable table, Object any, int horizontalAlignment, Function<PDFCell, PDFCell> cellCustomizer) Adds an object to the given PDFTable as a PDFCell.void
Adds an object to the given PDFTable as a PDFCell.void
addToTableCentered
(PDFTable table, Object any) Adds an object to the given PDFTable as a PDFCell.void
Adds an object to the given PDFTable as a PDFCell.void
Chain to another PDF.void
close()
Closes the PDF for content generation process.createCell
(Object object) Creates a cell that can be added to a table.createCell
(Object object, boolean rightAligned) Creates a cell that can be added to a table.createCell
(Object object, boolean rightAligned, Function<PDFCell, PDFCell> cellCustomizer) Creates a cell that can be added to a table.createCell
(Object object, int horizontalAlignment) Creates a cell that can be added to a table.createCell
(Object object, int horizontalAlignment, int verticalAlignment) Creates a cell that can be added to a table.createCell
(Object object, int horizontalAlignment, int verticalAlignment, Function<PDFCell, PDFCell> cellCustomizer) Creates a cell that can be added to a table.createCell
(Object object, int horizontalAlignment, Function<PDFCell, PDFCell> cellCustomizer) Creates a cell that can be added to a table.createCell
(Object object, Function<PDFCell, PDFCell> cellCustomizer) Creates a cell that can be added to a table.createCenteredCell
(Object object) Creates a centered cell that can be added to a table.createCenteredCell
(Object object, Function<PDFCell, PDFCell> cellCustomizer) Creates a centered cell that can be added to a table.Create a graphics object to draw directly to the PDF.createGraphics
(float positionX, float positionY, float width, float height) Create a graphics object to draw directly to the PDF.static PDFImage
createImage
(Barcode barcode) Create image from barcodestatic PDFImage
createImage
(HTMLText html) Create image from HTMLstatic PDFImage
createImage
(HTMLText html, int width, int height) Create image from HTMLstatic PDFImage
createImage
(Signature signature) Create image from a signature instancestatic PDFImage
createImage
(StreamData streamData) Create image from stream datastatic PDFImage
createImage
(Image image) Create image from Java AWT imagestatic PDFImage
createImage
(InputStream stream) Create image from an input stream (stream will be closed)createImage
(Consumer<Graphics2D> painter) Create a PDF image where a painter decides how to paint the image.createImage
(Consumer<Graphics2D> painter, int width, int height) Create a PDF image where a painter decides how to paint the image.static PDFImage
createImageFromHTML
(String html) Create image from HTMLstatic PDFImage
createImageFromHTML
(String html, int width, int height) Create image from HTMLstatic PDFImage
createImageFromHTML
(String html, StringFiller filler) Create image from HTMLstatic PDFImage
createImageFromHTML
(String html, StringFiller filler, int width, int height) Create image from HTMLstatic PDFImage
createImageFromSVG
(String svg) Create image from SVGstatic PDFImage
createImageFromSVG
(String svg, int width, int height) Create image from SVGstatic PDFTable
createTable
(int columnCount) Creates a table that can fit 100% to document's width.static PDFTable
createTable
(int... relativeWidths) Creates a table that can fit 100% to document's width.createText
(String text) Create text Chunk.createText
(String text, int pointSize) Create text Chunk.createText
(String text, int pointSize, PDFColor color) Create text Chunk.createTitleText
(String title) Create title Phrase.createTitleText
(String title, int pointSize) Create title Phrase.createTitleText
(String title, int pointSize, PDFColor color) Create title Phrase.boolean
Draw the table at the current position till the end of the page.boolean
Draw the table at the given position till the end of the page.boolean
Draw the table within the given rectangular area.final void
Dump the error that happened during reporting.abstract void
Generate the content by writing stuff to the PDF.float
Document margin.final InputStream
Gets the content as a stream.final String
Gets the content type for this.Get the entity (If the entity can not be identified from "Transaction Manager" or "Entity", then, null is returned.Get the location of the entity (If the entity can not be identified from "Transaction Manager" or "Entity", then, a blank String is returned.Get the name of the entity (If the entity can not be identified from "Transaction Manager" or "Entity", then, a blank String is returned.final String
Gets the file name extension.Gets the name of the file for this PDFfinal int
Gets default font size.Footer to be displayed on each page.final float
Gets the printable height.float
Document margin.int
Get the current page number.int
Page orientation - Portrait or LandscapePage size.static PDFRectangle
getPageSize
(int paperSizeIndex) int
Get the 'Report Format Definition' for this report.int
Stage of the report.float
Document margin.getTitle()
Title to be displayed on each page.float
Document margin.final TransactionManager
Gets the Transaction ManagergetUser()
Get the user for which this PDF is being generated.Gets the currently set water mark.final float
getWidth()
Gets the printable width.float
getY()
Get the current Y position of the PDFfloat
getY
(boolean ensureNewLine) Get the current Y position of the PDFfinal void
Log something via the logger associated with this report.boolean
newPage()
Create and add a new pagevoid
Starts a new report stage.void
newReportStage
(int reportStage) Starts a new report stage.void
open()
Open the PDF for creating the content.void
This method will be called whenever a page is completed.void
This method will be called whenever a new page is started.boolean
Print audit trail at the bottom of the pageboolean
Print letter head on every page or not.void
printLetterHeadOnEveryPage
(boolean print) Print letter head on every page or not.boolean
Print page number or not.void
printPageNumber
(boolean print) Print page number or not.boolean
Print total page number or not.void
printTotalPageNumber
(boolean print) Print total page number or not.void
produce()
This is the method to be invoked in order to do the content generation.readContent
(InputStream content) Reads and creates a 'Content' object from the stream containing PDF data.void
setDefaultCellCustomizer
(Consumer<PDFCell> defaultCellCustomizer) Set a cell customizer that will be called whenever a table cell is created.final void
Sets the Entity so that the "letter head" can be printed.final void
Set additional error information such that it will be printed in the log when an error happens.final void
setFontSize
(int fontSize) Sets the default font size.void
setLanguage
(PDFFont.Language language) Sets the font language for this PDF.void
setLanguage
(PDFFont.Language language, int fontSize) Sets the font language for this PDF.void
void
void
setPageNumber
(int pageNumber) Set the page number to a new value.void
setPageSizeIndex
(int pageSizeIndex) void
setPassword
(String password) Set a password for the PDF.void
setReportFormat
(ReportFormat reportFormat) Set the 'Report Format Definition' for this report.final void
Sets the Transaction Manager so that the "letter head" can be printed.void
setWaterMark
(String waterMark) Sets the water mark.void
showText
(String text, int x, int y, int alignment, float rotation, PDFFont font, float fontSize, PDFColor color, float opacity) Show text at some specified position.protected final int
toCharCount
(Object any) Return the width in number of characters for drawing the given value.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.storedobject.core.ContentProducer
abort, execute, extractContent, getError, getStreamData, getStreamDataProvider, getSystemEntity, saveTo, saveTo, saveTo, saveTo
Methods inherited from interface com.storedobject.core.ContentType
getLink, getMimeType, isAudio, isHTML, isImage, isLink, isMedia, isPDF, isText, isVideo
Methods inherited from interface com.storedobject.common.Executable
act, run
-
Field Details
-
pageSizes
-
ORIENTATION_PORTRAIT
public static final int ORIENTATION_PORTRAIT- See Also:
-
ORIENTATION_LANDSCAPE
public static final int ORIENTATION_LANDSCAPE- See Also:
-
-
Constructor Details
-
PDF
public PDF()Constructor. This will generate a PDF with letterhead. -
PDF
Constructor. This will generate a PDF with letterhead.- Parameters:
logo
- Logo
-
PDF
public PDF(boolean letterhead) Constructor.- Parameters:
letterhead
- Whether letterhead needs to be printed or not.
-
PDF
Constructor.- Parameters:
letterhead
- Whether letterhead needs to be printed or not.logo
- Logo
-
PDF
Constructor. This will generate a PDF with letterhead.- Parameters:
out
- Output stream to which content should be streamed out. Useful for storing the generated PDF to the backend.
-
PDF
Constructor. This will generate a PDF with letterhead.- Parameters:
out
- Output stream to which content should be streamed out. Useful for storing the generated PDF to the backend.logo
- Logo
-
PDF
Constructor.- Parameters:
out
- Output stream to which content should be streamed out.letterhead
- Whether letterhead needs to be printed or not.
-
PDF
Constructor.- Parameters:
out
- Output stream to which content should be streamed out.letterhead
- Whether letterhead needs to be printed or not.logo
- Logo
-
-
Method Details
-
open
public void open()Open the PDF for creating the content. This is automatically invoked by the framework. -
toCharCount
Return the width in number of characters for drawing the given value.- Parameters:
any
- anything.- Returns:
- Width in number of characters.
-
getPageSize
-
getPageSizeIndex
public int getPageSizeIndex() -
setPageSizeIndex
public void setPageSizeIndex(int pageSizeIndex) -
setPassword
Set a password for the PDF. If set, this password will be required to open the generated PDF. This method should be invoked before the actual content generation starts (so, the password must be set beforegenerateContent()
and that means, the constructor is the ideal place to set the password).- Parameters:
password
- Password to set.
-
setFontSize
public final void setFontSize(int fontSize) Sets the default font size.- Parameters:
fontSize
- Font size
-
getFontSize
public final int getFontSize()Gets default font size.- Returns:
- Default font size.
-
setLanguage
Sets the font language for this PDF.- Parameters:
language
- Font language.
-
setLanguage
Sets the font language for this PDF.- Parameters:
language
- Font language.fontSize
- Font size
-
add
Adds an object to the document. Object can be 'text', a PDFImage, a PDFCell, a PDFTable or anything else.- Parameters:
any
- Any object
-
add
Add an object to the document. Object can be 'text', a PDFImage, a PDFCell, a PDFTable or anything else.- Parameters:
any
- Any objectrightAligned
- Right alignment
-
add
Add an object to the document. Object can be 'text', a PDFImage, a PDFCell, a PDFTable or anything else.- Parameters:
any
- Any objecthorizontalAlignment
- Alignment value from PDFElement.
-
add
Add an object to the document. Object can be 'text', a PDFImage, a PDFCell, a PDFTable or anything else.- Parameters:
any
- Any objecthorizontalAlignment
- Alignment value from PDFElement.verticalAlignment
- Alignment value from PDFElement.
-
addToTable
Adds an object to the given PDFTable as a PDFCell. Object can be 'text', a PDFImage, a PDFCell, a PDFTable or anything else.- Parameters:
table
- Table to which the object needs to be added after converting into a PDFCell.any
- Any object to convert to a PDFCell.
-
addToTable
Adds an object to the given PDFTable as a PDFCell. Object can be 'text', a PDFImage, a PDFCell, a PDFTable or anything else.- Parameters:
table
- Table to which the object needs to be added after converting into a PDFCell.any
- Any object to convert to a PDFCell.cellCustomizer
- Cell customizer. If non-null value is passed, the cell will be passed through this for further customization.
-
addToTable
Adds an object to the given PDFTable as a PDFCell. Object can be 'text', a PDFImage, a PDFCell, a PDFTable or anything else.- Parameters:
table
- Table to which the object needs to be added after converting into a PDFCell.any
- Any object to convert to a PDFCell.rightAligned
- Right alignment.
-
addToTable
public void addToTable(PDFTable table, Object any, boolean rightAligned, Function<PDFCell, PDFCell> cellCustomizer) Adds an object to the given PDFTable as a PDFCell. Object can be 'text', a PDFImage, a PDFCell, a PDFTable or anything else.- Parameters:
table
- Table to which the object needs to be added after converting into a PDFCell.any
- Any object to convert to a PDFCell.rightAligned
- Right alignment.cellCustomizer
- Cell customizer. If non-null value is passed, the cell will be passed through this for further customization.
-
addToTableCentered
Adds an object to the given PDFTable as a PDFCell. Object can be 'text', a PDFImage, a PDFCell, a PDFTable or anything else.- Parameters:
table
- Table to which the object needs to be added after converting into a PDFCell.any
- Any object to convert to a PDFCell.
-
addToTableCentered
public void addToTableCentered(PDFTable table, Object any, Function<PDFCell, PDFCell> cellCustomizer) Adds an object to the given PDFTable as a PDFCell. Object can be 'text', a PDFImage, a PDFCell, a PDFTable or anything else.- Parameters:
table
- Table to which the object needs to be added after converting into a PDFCell.any
- Any object to convert to a PDFCell.cellCustomizer
- Cell customizer. If non-null value is passed, the cell will be passed through this for further customization.
-
addToTable
Adds an object to the given PDFTable as a PDFCell. Object can be 'text', a PDFImage, a PDFCell, a PDFTable or anything else.- Parameters:
table
- Table to which the object needs to be added after converting into a PDFCell.any
- Any object to convert to a PDFCell.horizontalAlignment
- Alignment value from PDFElement.
-
addToTable
public void addToTable(PDFTable table, Object any, int horizontalAlignment, Function<PDFCell, PDFCell> cellCustomizer) Adds an object to the given PDFTable as a PDFCell. Object can be 'text', a PDFImage, a PDFCell, a PDFTable or anything else.- Parameters:
table
- Table to which the object needs to be added after converting into a PDFCell.any
- Any object to convert to a PDFCell.horizontalAlignment
- Alignment value from PDFElement.cellCustomizer
- Cell customizer. If non-null value is passed, the cell will be passed through this for further customization.
-
addToTable
Adds an object to the given PDFTable as a PDFCell. Object can be 'text', a PDFImage, a PDFCell, a PDFTable or anything else.- Parameters:
table
- Table to which the object needs to be added after converting into a PDFCell.any
- Any object to convert to a PDFCell.horizontalAlignment
- Alignment value from PDFElement.verticalAlignment
- Alignment value from PDFElement.
-
addToTable
public void addToTable(PDFTable table, Object any, int horizontalAlignment, int verticalAlignment, Function<PDFCell, PDFCell> cellCustomizer) Adds an object to the given PDFTable as a PDFCell. Object can be 'text', a PDFImage, a PDFCell, a PDFTable or anything else.- Parameters:
table
- Table to which the object needs to be added after converting into a PDFCell.any
- Any object to convert to a PDFCell.horizontalAlignment
- Alignment value from PDFElement.verticalAlignment
- Alignment value from PDFElement.cellCustomizer
- Cell customizer. If non-null value is passed, the cell will be passed through this for further customization.
-
close
public void close()Closes the PDF for content generation process. This method is generally invoked by the framework automatically.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
chainTo
Chain to another PDF. Content from the PDF will be appended to the current one.- Parameters:
pdf
- PDF that needs to be appended to this content.
-
getFileName
Gets the name of the file for this PDF- Specified by:
getFileName
in interfaceContentProducer
- Returns:
- The PDF file name
-
getContent
Gets the content as a stream.- Specified by:
getContent
in interfaceContentProducer
- Returns:
- Content as a stream from the generated file.
- Throws:
Exception
-
getContentType
Gets the content type for this.- Specified by:
getContentType
in interfaceContentType
- Returns:
- "application/pdf"
-
produce
public void produce()This is the method to be invoked in order to do the content generation. This method is generally not overridden but if it is overridden, make sure that the "super" is invoked.- Specified by:
produce
in interfaceContentProducer
-
newReportStage
public void newReportStage()Starts a new report stage. Methods like getTitle(), getFooter(), getPageSize() etc. will be invoked again. A new page will be created with new page size, title and footer. Report Stage will be incremented by one and it can be obtained by calling getReportStage(). -
newReportStage
public void newReportStage(int reportStage) Starts a new report stage. Methods like getTitle(), getFooter(), getPageSize() etc. will be invoked again. A new page will be created with new page size, title and footer. Report Stage will be set to the value passed as parameter so that the next call to getReportStage() returns that value.- Parameters:
reportStage
- Next report stage
-
getReportStage
public int getReportStage()Stage of the report. The first stage is zero and every call to newReportStage() increments the stage.- Returns:
- Report stage.
-
getTitle
Title to be displayed on each page. This method is invoked only once and the same title is drawn on all pages unless newReportStage() is called. This could be a String, a PDFCell or any other object from which a PDFCell can be created, including a PDFTable.- Returns:
- Default return value is null, meaning nothing will be displayed as page title.
-
setEntity
Sets the Entity so that the "letter head" can be printed. If this method or setTransaction() is not invoked in the letter head mode, letter head will not be printed. If both this method and setTransactionManager() are invoked, setTransactionManager() method will be used only for printing water marks and this method will be used for printing letter head.- Parameters:
entity
- Entity to be set.
-
getReportFormat
Get the 'Report Format Definition' for this report. It will be determined by looking at the value of 'Transaction Manager' or 'Entity'.- Returns:
- Report Format Definition for this report.
-
setReportFormat
Set the 'Report Format Definition' for this report. This will override the default one.- Parameters:
reportFormat
- Report Format Definition for this report.
-
getEntityName
Get the name of the entity (If the entity can not be identified from "Transaction Manager" or "Entity", then, a blank String is returned.- Returns:
- Name of the entity.
-
getEntityLocation
Get the location of the entity (If the entity can not be identified from "Transaction Manager" or "Entity", then, a blank String is returned.- Returns:
- Location of the entity.
-
getEntity
Get the entity (If the entity can not be identified from "Transaction Manager" or "Entity", then, null is returned.- Specified by:
getEntity
in interfaceContentProducer
- Returns:
- The entity.
-
generateContent
-
addContent
Add an image to the next page as the content. The image will fill the page 100%.- Parameters:
image
- Image to be added.
-
addContent
Add an image to the next page as the content. The image will be added at the center of the page.- Parameters:
image
- Image to be added.scalePercentage
- Scale percentage within the page. Use 100 for filling 100%.
-
addContent
Add content from another PDF content producer. The method addingExternalContent will be invoked before adding each page image.- Parameters:
externalPDF
- External PDF to add.scalePercentage
- Scale percentage of each page.- Throws:
Exception
- Any exception.
-
addContent
public void addContent(ContentProducer externalPDF, float scalePercentage, int startingPage, int endingPage, int... pagesToSkip) throws Exception Add content from another PDF content producer. The method addingExternalContent will be invoked before adding each page image.- Parameters:
externalPDF
- External PDF to add.scalePercentage
- Scale percentage of each page.startingPage
- Pages will be inserted from the starting page (Page number starts from 1).endingPage
- Pages will be inserted till this page. If 0 is specified, it will be interpreted as the last page of the content. Negative numbers will be subtracted from last page. So, from the content, if last 3 pages to be dropped, just pass -3 as the endingPage.pagesToSkip
- Pages to skip.- Throws:
Exception
- Any exception.
-
addContent
Add content from a PDF file. The method addingExternalContent will be invoked before adding each page image.- Parameters:
externalPDF
- External PDF to add.scalePercentage
- Scale percentage of each page.- Throws:
Exception
- Any exception.
-
addContent
public void addContent(FileData externalPDF, float scalePercentage, int startingPage, int endingPage, int... pagesToSkip) throws Exception Add content from a PDF file. The method addingExternalContent will be invoked before adding each page image.- Parameters:
externalPDF
- External PDF to add.scalePercentage
- Scale percentage of each page.startingPage
- Pages will be inserted from the starting page (Page number starts from 1).endingPage
- Pages will be inserted till this page. If 0 is specified, it will be interpreted as the last page of the content. Negative numbers will be subtracted from last page. So, from the content, if last 3 pages to be dropped, just pass -3 as the endingPage.pagesToSkip
- Pages to skip.- Throws:
Exception
- Any exception.
-
addContent
Add content from a PDF stream. The method addingExternalContent will be invoked before adding each page image.- Parameters:
externalPDF
- External PDF to add.scalePercentage
- Scale percentage of each page.- Throws:
Exception
- Any exception.
-
addContent
public void addContent(StreamData externalPDF, float scalePercentage, int startingPage, int endingPage, int... pagesToSkip) throws Exception Add content from a PDF stream. The method addingExternalContent will be invoked before adding each page image.- Parameters:
externalPDF
- External PDF to add.scalePercentage
- Scale percentage of each page.startingPage
- Pages will be inserted from the starting page (Page number starts from 1).endingPage
- Pages will be inserted till this page. If 0 is specified, it will be interpreted as the last page of the content. Negative numbers will be subtracted from last page. So, from the content, if last 3 pages to be dropped, just pass -3 as the endingPage.pagesToSkip
- Pages to skip.- Throws:
Exception
- Any exception.
-
addContent
Add content from a PDF stream. The method addingExternalContent will be invoked before adding each page image.- Parameters:
externalPDF
- External PDF to add.scalePercentage
- Scale percentage of each page.- Throws:
Exception
- Any exception.
-
addContent
public void addContent(InputStream externalPDF, float scalePercentage, int startingPage, int endingPage, int... pagesToSkip) throws Exception Add content from a PDF stream. The method addingExternalContent will be invoked before adding each page image.- Parameters:
externalPDF
- External PDF to add.scalePercentage
- Scale percentage of each page.startingPage
- Pages will be inserted from the starting page (Page number starts from 1).endingPage
- Pages will be inserted till this page. If 0 is specified, it will be interpreted as the last page of the content. Negative numbers will be subtracted from last page. So, from the content, if last 3 pages to be dropped, just pass -3 as the endingPage.pagesToSkip
- Pages to skip.- Throws:
Exception
- Any exception.
-
aboutToAddExternalContent
-
addingExternalContent
-
createTable
Creates a table that can fit 100% to document's width.- Parameters:
columnCount
- Number of columns in the table.- Returns:
- The table
-
createTable
Creates a table that can fit 100% to document's width.- Parameters:
relativeWidths
- Relative (or percentage) widths of the columns to be created.- Returns:
- The table
-
setDefaultCellCustomizer
Set a cell customizer that will be called whenever a table cell is created. The default customizer draws a border around the cell. So, if you don't want that, set this to null or to your own custom one.- Parameters:
defaultCellCustomizer
- Default cell customizer. Could be null.
-
createCenteredCell
Creates a centered cell that can be added to a table.- Parameters:
object
- Object that provides the content of the cell - object.toString(). Object can also be either a PDFImage, PDFCell, PDFTable, PDFPhrase or PDFChunk.- Returns:
- The cell that is created.
-
createCenteredCell
Creates a centered cell that can be added to a table.- Parameters:
object
- Object that provides the content of the cell - object.toString(). Object can also be either a PDFImage, PDFCell, PDFTable, PDFPhrase, PDFChunk, Image, StreamData or Barcode.cellCustomizer
- Cell customizer. If non-null value is passed, the cell created will be passed through this for further customization.- Returns:
- The cell that is created.
-
createCell
-
createCell
Creates a cell that can be added to a table.- Parameters:
object
- Object that provides the content of the cell - object.toString(). Object can also be either a PDFImage, PDFCell, PDFTable, PDFPhrase, PDFChunk, Image, StreamData or Barcode.cellCustomizer
- Cell customizer. If non-null value is passed, the cell created will be passed through this for further customization.- Returns:
- The cell that is created.
-
createCell
Creates a cell that can be added to a table.- Parameters:
object
- Object that provides the content of the cell - object.toString(). Object can also be either a PDFImage, PDFCell, PDFTable, PDFPhrase or PDFChunk.rightAligned
- Whether the cell is right aligned or not.- Returns:
- The cell that is created.
-
createCell
public PDFCell createCell(Object object, boolean rightAligned, Function<PDFCell, PDFCell> cellCustomizer) Creates a cell that can be added to a table.- Parameters:
object
- Object that provides the content of the cell - object.toString(). Object can also be either a PDFImage, PDFCell, PDFTable, PDFPhrase, PDFChunk, Image, StreamData or Barcode.rightAligned
- Whether the cell is right aligned or not.cellCustomizer
- Cell customizer. If non-null value is passed, the cell created will be passed through this for further customization.- Returns:
- The cell that is created.
-
createCell
Creates a cell that can be added to a table.- Parameters:
object
- Object that provides the content of the cell - object.toString(). Object can also be either a PDFImage, PDFCell, PDFTable, PDFPhrase or PDFChunk.horizontalAlignment
- Alignment value from PDFElement.- Returns:
- The cell that is created.
-
createCell
public PDFCell createCell(Object object, int horizontalAlignment, Function<PDFCell, PDFCell> cellCustomizer) Creates a cell that can be added to a table.- Parameters:
object
- Object that provides the content of the cell - object.toString(). Object can also be either a PDFImage, PDFCell, PDFTable, PDFPhrase, PDFChunk, Image, StreamData or Barcode.horizontalAlignment
- Alignment value from PDFElement.cellCustomizer
- Cell customizer. If non-null value is passed, the cell created will be passed through this for further customization.- Returns:
- The cell that is created.
-
createCell
Creates a cell that can be added to a table.- Parameters:
object
- Object that provides the content of the cell - object.toString(). Object can also be either a PDFImage, PDFCell, PDFTable, PDFPhrase or PDFChunk.horizontalAlignment
- Alignment value from PDFElement.verticalAlignment
- Alignment value from PDFElement.- Returns:
- The cell that is created.
-
createCell
public PDFCell createCell(Object object, int horizontalAlignment, int verticalAlignment, Function<PDFCell, PDFCell> cellCustomizer) Creates a cell that can be added to a table.- Parameters:
object
- Object that provides the content of the cell - object.toString(). Object can also be either a PDFImage, PDFCell, PDFTable, PDFPhrase, PDFChunk, Image, StreamData or Barcode.horizontalAlignment
- Alignment value from PDFElement.verticalAlignment
- Alignment value from PDFElement.cellCustomizer
- Cell customizer. If non-null value is passed, the cell created will be passed through this for further customization.- Returns:
- The cell that is created.
-
printPageNumber
public void printPageNumber(boolean print) Print page number or not.- Parameters:
print
- True or false
-
printPageNumber
public boolean printPageNumber()Print page number or not.- Returns:
- True or false
-
printTotalPageNumber
public void printTotalPageNumber(boolean print) Print total page number or not.- Parameters:
print
- True or false
-
printTotalPageNumber
public boolean printTotalPageNumber()Print total page number or not.- Returns:
- True or false
-
printAuditTrail
public boolean printAuditTrail()Print audit trail at the bottom of the page- Returns:
- True or false
-
setLogo
-
setLogo
-
getLeftMargin
public float getLeftMargin()Document margin. This is invoked only once to create the document unless newReportStage() is called. Override this to set a different margin.- Returns:
- Margin. Default is 36 = 0.5 inch.
-
getRightMargin
public float getRightMargin()Document margin. This is invoked only once to create the document unless newReportStage() is called. Override this to set a different margin.- Returns:
- Margin. Default is 36 = 0.5 inch.
-
getTopMargin
public float getTopMargin()Document margin. This is invoked only once to create the document unless newReportStage() is called. Override this to set a different margin.- Returns:
- Margin. Default is 72 = 1 inch.
-
getBottomMargin
public float getBottomMargin()Document margin. This is invoked only once to create the document unless newReportStage() is called. Override this to set a different margin.- Returns:
- Margin. Default is 72 = 1 inch.
-
getWidth
public final float getWidth()Gets the printable width.- Returns:
- Width
-
getHeight
public final float getHeight()Gets the printable height.- Returns:
- Height
-
getPageSize
Page size. This is invoked only once to create the document unless newReportStage() is called. This is used to control the size of the page. For example, if you want landscape A4 size, simply override this method to return super.getPageSize().rotate().- Returns:
- PDFRectangle representing page size. Default is A4 size.
-
getPageOrientation
public int getPageOrientation()Page orientation - Portrait or Landscape- Returns:
- ORIENTATION_PORTRAIT or ORIENTATION_LANDSCAPE. Default is ORIENTATION_PORTRAIT
-
createTitleText
-
createTitleText
-
createTitleText
-
printLetterHeadOnEveryPage
public void printLetterHeadOnEveryPage(boolean print) Print letter head on every page or not.- Parameters:
print
- True or false
-
printLetterHeadOnEveryPage
public boolean printLetterHeadOnEveryPage()Print letter head on every page or not.- Returns:
- True or false
-
createText
-
createText
-
createText
-
setTransactionManager
Sets the Transaction Manager so that the "letter head" can be printed. If this method or setEntity() is not invoked in the letter head mode, letter head will not be printed. Also, this is needed to print water marks on the generated output.- Specified by:
setTransactionManager
in interfaceContentProducer
- Parameters:
tm
- The Transaction Manager to be set.
-
getTransactionManager
Gets the Transaction Manager- Specified by:
getTransactionManager
in interfaceContentProducer
- Returns:
- Transaction Manager
-
getFileExtension
Gets the file name extension.- Specified by:
getFileExtension
in interfaceContentProducer
- Returns:
- "pdf"
-
setPageNumber
public void setPageNumber(int pageNumber) Set the page number to a new value.- Parameters:
pageNumber
- Page number to be set.
-
getPageNumber
public int getPageNumber()Get the current page number.- Returns:
- Current page number. Returns 0 if nothing started yet.
-
addTitles
-
addTitles
-
addTitles
Add title texts to table.- Parameters:
table
- Table to which title texts to be added.titles
- Titles
-
addTitles
-
addTitles
-
addTitles
Add title texts to table.- Parameters:
table
- Table to which title texts to be added.pointSize
- Point size of the title.titles
- Titles
-
addBlankRow
Adds a blank row to the table.- Parameters:
table
- Table to which row to be added.
-
addBlankRow
Adds a blank row to the table.- Parameters:
table
- Table to which row to be added.fromColumn
- Column from which blank cells to be added.
-
addBlankRow
Adds a blank row to the table.- Parameters:
table
- Table to which row to be added.fromColumn
- Column from which blank cells to be added.toColumn
- Column up to which blank cells to be added.
-
addImage
Add an image at position (0, 0) in the current page.- Parameters:
image
- Image to add.- Throws:
PDFException
- Exception if not successful.
-
addImage
Add an image at some absolute position in the current page.- Parameters:
image
- Image to add.positionX
- X position (from the left).positionY
- Y position (from the bottom).- Throws:
PDFException
- Exception if not successful.
-
addImage
public void addImage(PDFImage image, float positionX, float positionY, float width, float height) throws PDFException Add an image at some absolute position in the current page.- Parameters:
image
- Image to add.positionX
- X position (from the left).positionY
- Y position (from the bottom).width
- Width to which image to be fit.height
- Height to which image to be fit.- Throws:
PDFException
- Exception if not successful.
-
addCentered
Add an object to the document. Object can be 'text', a PDFImage, a PDFCell, a PDFTable or anything else.- Parameters:
any
- Any object
-
addGap
public void addGap(int verticalGap) Add some vertical gap (Typically used to add space before adding a table).- Parameters:
verticalGap
- Amount of space to be added
-
getY
public float getY()Get the current Y position of the PDF- Returns:
- Current Y
-
getY
public float getY(boolean ensureNewLine) Get the current Y position of the PDF- Parameters:
ensureNewLine
- See whether line feed needs to be considered when computing this.- Returns:
- Current Y
-
drawTable
Draw the table at the current position till the end of the page. Table will be shrunk by deleting the rows drawn and the rest of the rows may be drawn again at some other position, may be in another page.- Parameters:
table
- Table to be drawn- Returns:
- True if all rows are drawn in the current page.
-
drawTable
Draw the table at the given position till the end of the page. Table will be shrunk by deleting the rows drawn and the rest of the rows may be drawn again at some other position, may be in another page.- Parameters:
table
- Table to be drawnx
- X positiony
- Y position- Returns:
- True if all rows are drawn in the current page.
-
drawTable
Draw the table within the given rectangular area. Table will be shrunk by deleting the rows drawn and the rest of the rows may be drawn again at some other position, may be in another page.- Parameters:
table
- Table to be drawnx1
- Upper left X positiony1
- Upper left Y positionx2
- Lower right X positiony2
- Lower right Y position- Returns:
- True if all rows are drawn within the area.
-
createGraphics
Create a graphics object to draw directly to the PDF. Once the drawing is completed, invoke the dispose method.- Returns:
- Graphics2D
-
createGraphics
Create a graphics object to draw directly to the PDF. Once the drawing is completed, invoke the dispose method.- Parameters:
positionX
- X position (from the left).positionY
- Y position (from the bottom).width
- Width of the graphics.height
- Height of the graphics.- Returns:
- Graphics2D
-
createImageFromSVG
-
createImageFromSVG
-
createImage
Create a PDF image where a painter decides how to paint the image.- Parameters:
painter
- The painter whose accept method is invoked with aGraphics2D
object do the painting- Returns:
- PDF image that covers the full page.
-
createImage
Create a PDF image where a painter decides how to paint the image.- Parameters:
painter
- The painter whose accept method is invoked with aGraphics2D
object do the paintingwidth
- Width of the imageheight
- Height of the image- Returns:
- PDF image.
-
createImage
-
createImage
-
createImage
Create image from stream data- Parameters:
streamData
- Stream data- Returns:
- Image
-
createImage
Create image from an input stream (stream will be closed)- Parameters:
stream
- Input stream- Returns:
- Image
-
createImage
-
addHTML
Add HTML content to the rest of the page- Parameters:
html
- HTML content
-
addHTML
Add HTML content to the rest of the page- Parameters:
html
- HTML contentfiller
- Filler to fill up the html text
-
addHTML
Add HTML content at the current position with the given width and height- Parameters:
html
- HTML contentwidth
- Widthheight
- Height
-
addHTML
Add HTML content at the given position with the given width and height- Parameters:
html
- HTML contentpositionX
- Position XpositionY
- Position Ywidth
- Widthheight
- Height
-
addHTML
Add HTML content at the current position with the given width and height- Parameters:
html
- HTML contentfiller
- Filler to fill up the html textwidth
- Widthheight
- Height
-
addHTML
public void addHTML(String html, StringFiller filler, int positionX, int positionY, int width, int height) Add HTML content at the given position with the given width and height- Parameters:
html
- HTML contentfiller
- Filler to fill up the html textpositionX
- Position XpositionY
- Position Ywidth
- Widthheight
- Height
-
createImageFromHTML
-
createImageFromHTML
Create image from HTML- Parameters:
html
- HTML contentfiller
- Filler to fill up the html text- Returns:
- Image
-
createImageFromHTML
-
createImageFromHTML
Create image from HTML- Parameters:
html
- HTML contentfiller
- Filler to fill up the html textwidth
- Image widthheight
- Image height- Returns:
- Image
-
createImage
-
createImage
-
newPage
public boolean newPage()Create and add a new page- Returns:
- True if the page is created and added
-
getUser
Get the user for which this PDF is being generated. This information will be used for formatting the money values.- Returns:
- User.
-
pageStarted
public void pageStarted()This method will be called whenever a new page is started. This can be overridden for customizing the page. -
pageCompleted
public void pageCompleted()This method will be called whenever a page is completed. This can be overridden for customizing the page. -
getWaterMark
Gets the currently set water mark.- Returns:
- Current water mark if any, otherwise null will be returned.
-
setWaterMark
Sets the water mark.- Parameters:
waterMark
- Water mark text.
-
showText
public void showText(String text, int x, int y, int alignment, float rotation, PDFFont font, float fontSize, PDFColor color, float opacity) Show text at some specified position.- Parameters:
text
- Text to be shown.x
- X position.y
- Y position.alignment
- Alignment - Use PDFElement.ALIGN_CENTER etc.rotation
- Angle of rotation.font
- Font to be used, pass 'null' if base font to be used.fontSize
- Font size in points.color
- Color to be used for the text.opacity
- Opacity to be used. (A value between 0.0 to 1.0).
-
setError
Set additional error information such that it will be printed in the log when an error happens. Any error thrown when generating reports will be dumped to the report output and system log.- Parameters:
error
- Error information.
-
dumpError
Dump the error that happened during reporting.- Parameters:
error
- Error o dump.
-
log
Log something via the logger associated with this report.- Parameters:
anything
- Anything to log.
-
getDevice
-
readContent
Reads and creates a 'Content' object from the stream containing PDF data.- Parameters:
content
- Stream containing PDF. It could be from a PDF file or database.- Returns:
- This
- Throws:
IOException
- The stream may raise this exception.
-