Package org.kissweb

Class PDF

java.lang.Object
org.kissweb.PDF

public class PDF extends Object
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
  • Constructor Summary

    Constructors
    Constructor
    Description
    PDF(String fname)
    Begin a new PDF file
    PDF(String infile, String outfile)
    Begin a new PDF file with an existing PDF file as its starting point.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    drawLine(float ya, float xa, float yb, float xb, float thickness)
    Draw a line
    void
    drawRect(float ya, float xa, float yb, float xb, float thickness, int fill)
    Draw a rectangle
    void
    End current page and end document
    void
    End text mode and go into graphics mode.
    void
    End text mode and go into graphics mode.
    org.apache.pdfbox.pdmodel.PDPageContentStream
     
    org.apache.pdfbox.pdmodel.PDDocument
     
    org.apache.pdfbox.pdmodel.PDPage
     
    void
    getPage(int n)
    Get an existing page.
    void
     
    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
    imageOut(float ypos, float xpos, float scale, String filename)
    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
    main(String[] args)
     
    void
    End current page and start a new page
    void
     
    void
    setFont(org.apache.pdfbox.pdmodel.font.PDFont fnt, float fs)
    Set font style and size
    org.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
    textOut(int y, int x, String txt)
    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
    textOutpx(float absy, float absx, String txt)
    Output txt at dot position y, dot position x

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PDF

      public PDF(String fname)
      Begin a new PDF file
      Parameters:
      fname - the file name to be saved to (include the .pdf)
    • PDF

      public PDF(String infile, String outfile) throws IOException
      Begin a new PDF file with an existing PDF file as its starting point.
      Parameters:
      infile - the name of the input PDF template file
      outfile - 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 style
      fs - 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

      public void textOut(int y, int x, String txt)
      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

      public void textOutpx(float absy, float absx, String txt)
      Output txt at dot position y, dot position x
      Parameters:
      absy - absolute dot position, top to bottom
      absx - absolute dot position, left to right
      txt - 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 point
      xa - upper left x point
      yb - lower right y point
      xb - lower right x point
      thickness - 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 point
      xa - upper left x point
      yb - lower right y point
      xb - lower right x point
      thickness - line thickness (-1 == no outside line)
      fill - fill percent, -1=no fill, otherwise 0-255 where 0 is black and 255 is white
    • imageOut

      public void imageOut(float ypos, float xpos, float scale, String filename)
      Output image file to PDF

      Positioning starts at upper left corner of paper.
      Parameters:
      ypos - place lower left corner of image at vertical position
      xpos - place lower left corner of image at horizontal position
      scale - 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 position
      xpos - place lower left corner of image at horizontal position
      scale - scale image (1.0f means no scaling)
      image - the image
    • imageOutWidth

      public 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.
      Parameters:
      ypos - place lower left corner of image at vertical position
      xpos - place lower left corner of image at horizontal position
      width - the width of the image
      filename - the filename of the image
    • imageOutHeight

      public 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.
      Parameters:
      ypos - place lower left corner of image at vertical position
      xpos - place lower left corner of image at horizontal position
      height - the height of the image
      filename - 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 position
      xpos - place lower left corner of image at horizontal position
      ypos2 - place upper right corner of image at vertical position
      xpos2 - place upper right corner of image at horizontal position
      image - 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

      public static void main(String[] args) throws IOException
      Throws:
      IOException