Package org.kissweb
Class PDF
java.lang.Object
org.kissweb.PDF
This class creates PDF files with text, images, and line graphics.
There are two classes in Kiss used to create PDF reports: PDF and Groff. PDF is used when graphics and images are needed. Groff is used when text and tables are needed. It is possible to use both in the same report by creating the PDF with one and appending with the other. Author: Blake McBride Date: 3/5/16
There are two classes in Kiss used to create PDF reports: PDF and Groff. PDF is used when graphics and images are needed. Groff is used when text and tables are needed. It is possible to use both in the same report by creating the PDF with one and appending with the other. Author: Blake McBride Date: 3/5/16
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
drawLine
(float ya, float xa, float yb, float xb, float thickness) Draw a linevoid
drawRect
(float ya, float xa, float yb, float xb, float thickness, int fill) Draw a rectanglevoid
End current page and end documentvoid
End text mode and go into graphics mode.void
endText()
End text mode and go into graphics mode.org.apache.pdfbox.pdmodel.PDPageContentStream
org.apache.pdfbox.pdmodel.PDDocument
getDoc()
org.apache.pdfbox.pdmodel.PDPage
getPage()
void
getPage
(int n) Get an existing page.void
grid()
void
imageOut
(float ypos, float xpos, float scale, byte[] image) Output scaled image to PDF.void
imageOut
(float ypos, float xpos, float ypos2, float xpos2, byte[] image) Output image to defined square on the page.void
Output image file to PDF
Positioning starts at upper left corner of paper.void
imageOutHeight
(float ypos, float xpos, float height, String filename) Outputs an image with a specific height to the PDF document retaining the image aspect ratio.void
imageOutWidth
(float ypos, float xpos, float width, String filename) Outputs an image with a specific width to the PDF document retaining the image aspect ratio.void
static void
void
newPage()
End current page and start a new pagevoid
portrait()
void
setFont
(org.apache.pdfbox.pdmodel.font.PDFont fnt, float fs) Set font style and sizeorg.apache.pdfbox.pdmodel.common.PDRectangle
setPageSize
(org.apache.pdfbox.pdmodel.common.PDRectangle ps) void
End text mode and go into graphics mode.void
Start output of text.void
Output txt at line y, column x Lines and column numbers take font into account so, for example, typically letter paper would give 66 lines and 80 columns.void
Output txt at dot position y, dot position x
-
Constructor Details
-
PDF
Begin a new PDF file- Parameters:
fname
- the file name to be saved to (include the .pdf)
-
PDF
Begin a new PDF file with an existing PDF file as its starting point.- Parameters:
infile
- the name of the input PDF template fileoutfile
- the file name to be saved to (include the .pdf)- Throws:
IOException
-
-
Method Details
-
setFont
public void setFont(org.apache.pdfbox.pdmodel.font.PDFont fnt, float fs) Set font style and size- Parameters:
fnt
- font stylefs
- font size in points
-
landscape
public void landscape() -
portrait
public void portrait() -
setPageSize
public org.apache.pdfbox.pdmodel.common.PDRectangle setPageSize(org.apache.pdfbox.pdmodel.common.PDRectangle ps) -
textOut
Output txt at line y, column x Lines and column numbers take font into account so, for example, typically letter paper would give 66 lines and 80 columns.- Parameters:
y
- absolute line position top to bottom, line 1 to line ...x
- absolute column position left to right, column 1 to ...txt
- the text to be written
-
startText
public void startText()Start output of text.
You cannot intermix graphics with text output (although both can be on the same page). Text must be surrounded with startText() end endText(). However, when you start a new page, the system automatically starts in text mode. -
endGraphics
public void endGraphics()End text mode and go into graphics mode.
Text and graphics cannot be output at the same time without switching between text and graphics mode. -
textOutpx
Output txt at dot position y, dot position x- Parameters:
absy
- absolute dot position, top to bottomabsx
- absolute dot position, left to righttxt
- the text to be written
-
newPage
public void newPage()End current page and start a new page -
getPage
public void getPage(int n) Get an existing page.- Parameters:
n
- the page number to get (starting at 0)
-
drawLine
public void drawLine(float ya, float xa, float yb, float xb, float thickness) Draw a line- Parameters:
ya
- upper left y pointxa
- upper left x pointyb
- lower right y pointxb
- lower right x pointthickness
- line thickness (-1 == no outside line)
-
drawRect
public void drawRect(float ya, float xa, float yb, float xb, float thickness, int fill) Draw a rectangle- Parameters:
ya
- upper left y pointxa
- upper left x pointyb
- lower right y pointxb
- lower right x pointthickness
- line thickness (-1 == no outside line)fill
- fill percent, -1=no fill, otherwise 0-255 where 0 is black and 255 is white
-
imageOut
Output image file to PDF
Positioning starts at upper left corner of paper.- Parameters:
ypos
- place lower left corner of image at vertical positionxpos
- place lower left corner of image at horizontal positionscale
- scale image (1.0f means no scaling)filename
- name of file holding image
-
imageOut
public void imageOut(float ypos, float xpos, float scale, byte[] image) Output scaled image to PDF.
Positioning starts at upper left corner of paper.- Parameters:
ypos
- place lower left corner of image at vertical positionxpos
- place lower left corner of image at horizontal positionscale
- scale image (1.0f means no scaling)image
- the image
-
imageOutWidth
Outputs an image with a specific width to the PDF document retaining the image aspect ratio.- Parameters:
ypos
- place lower left corner of image at vertical positionxpos
- place lower left corner of image at horizontal positionwidth
- the width of the imagefilename
- the filename of the image
-
imageOutHeight
Outputs an image with a specific height to the PDF document retaining the image aspect ratio.- Parameters:
ypos
- place lower left corner of image at vertical positionxpos
- place lower left corner of image at horizontal positionheight
- the height of the imagefilename
- the filename of the image
-
imageOut
public void imageOut(float ypos, float xpos, float ypos2, float xpos2, byte[] image) Output image to defined square on the page.- Parameters:
ypos
- place lower left corner of image at vertical positionxpos
- place lower left corner of image at horizontal positionypos2
- place upper right corner of image at vertical positionxpos2
- place upper right corner of image at horizontal positionimage
- the image
-
endText
public void endText()End text mode and go into graphics mode. Text and graphics cannot be output at the same time without switching between text and graphics mode. -
startGraphics
public void startGraphics()End text mode and go into graphics mode. Text and graphics cannot be output at the same time without switching between text and graphics mode. -
endDocument
public void endDocument()End current page and end document -
getDoc
public org.apache.pdfbox.pdmodel.PDDocument getDoc() -
getPage
public org.apache.pdfbox.pdmodel.PDPage getPage() -
getContentStream
public org.apache.pdfbox.pdmodel.PDPageContentStream getContentStream() -
grid
public void grid() -
main
- Throws:
IOException
-