Class PDFJob
- java.lang.Object
-
- java.awt.PrintJob
-
- pdf.PDFJob
-
- All Implemented Interfaces:
java.io.Serializable
public class PDFJob extends java.awt.PrintJob implements java.io.SerializableThis class extends awt's PrintJob, to provide a simple method of writing PDF documents.
You can use this with any code that uses Java's printing mechanism. It does include a few extra methods to provide access to some of PDF's features like annotations, or outlines.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.io.OutputStreamosThis is the OutputStream the PDF file will be written to when complete Note: This is transient, as it's not valid after being Serialized.protected PDFPagepageThis is the current page being constructed by the last getGraphics() callprotected intpagenumThis is the page number of the current pageprotected PDFDocumentpdfDocumentThis is the PDF file being constructed
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PDFAnnotaddNote(java.lang.String note, int x, int y, int w, int h)Convenience method: Adds a text note to the document.PDFOutlineaddOutline(java.lang.String title)This method attaches an outline to the current page being generated.PDFOutlineaddOutline(java.lang.String title, int x, int y, int w, int h)This method attaches an outline to the current page being generated.voidend()This writes the PDF document to the OutputStream, finishing the document.PDFPagegetCurrentPage()Returns the current PDFPage being worked on.intgetCurrentPageNumber()Returns the current page number.java.awt.GraphicsgetGraphics()This returns a graphics object that can be used to draw on a page.java.awt.GraphicsgetGraphics(int orient)This returns a graphics object that can be used to draw on a page.java.awt.GraphicsgetGraphics(java.awt.print.PageFormat pageFormat)This returns a graphics object that can be used to draw on a page.java.awt.DimensiongetPageDimension()Returns the page dimensionintgetPageResolution()This returns the page resolution.PDFDocumentgetPDFDocument()Returns the PDFDocument object for this document.booleanlastPageFirst()In AWT's PrintJob, this would return true if the user requested that the file is printed in reverse order.
-
-
-
Field Detail
-
os
protected transient java.io.OutputStream os
This is the OutputStream the PDF file will be written to when complete Note: This is transient, as it's not valid after being Serialized.
-
pdfDocument
protected PDFDocument pdfDocument
This is the PDF file being constructed
-
page
protected PDFPage page
This is the current page being constructed by the last getGraphics() call
-
pagenum
protected int pagenum
This is the page number of the current page
-
-
Constructor Detail
-
PDFJob
public PDFJob()
This constructs the job. This method must be used when creating a template pdf file, ie one that is Serialised by one application, and then restored by another.
ezb 20011115 - Haven't done anything with templates yet, don't know how/if they are implemented
-
PDFJob
public PDFJob(java.io.OutputStream os)
This constructs the job. This is the primary constructor that will be used for creating pdf documents with this package. The specified output stream is a handle to the .pdf file you wish to create.
- Parameters:
os- -OutputStreamto use for the pdf output
-
PDFJob
public PDFJob(java.io.OutputStream os, java.lang.String title)This constructs the job. This is the primary constructor that will be used for creating pdf documents with this package. The specified output stream is a handle to the .pdf file you wish to create.
Use this constructor if you want to give the pdf document a name other than the default of "PDF Doc"
- Parameters:
os- -OutputStreamto use for the pdf outputtitle- aStringvalue
-
-
Method Detail
-
getGraphics
public java.awt.Graphics getGraphics(int orient)
This returns a graphics object that can be used to draw on a page. In PDF, this will be a new page within the document.
- Parameters:
orient- - theintOrientation of the new page, as defined inPDFPage- Returns:
- Graphics object to draw.
- See Also:
PageFormat.PORTRAIT,PageFormat.LANDSCAPE,PageFormat.REVERSE_LANDSCAPE
-
getGraphics
public java.awt.Graphics getGraphics(java.awt.print.PageFormat pageFormat)
This returns a graphics object that can be used to draw on a page. In PDF, this will be a new page within the document.
- Parameters:
pageFormat- PageFormat describing the page size- Returns:
- Graphics object to draw.
-
end
public void end()
This writes the PDF document to the OutputStream, finishing the document.
- Specified by:
endin classjava.awt.PrintJob
-
getGraphics
public java.awt.Graphics getGraphics()
This returns a graphics object that can be used to draw on a page. In PDF, this will be a new page within the document.
This new page will by default be oriented as a portrait
- Specified by:
getGraphicsin classjava.awt.PrintJob- Returns:
- a
Graphicsobject to draw to.
-
getPageDimension
public java.awt.Dimension getPageDimension()
Returns the page dimension
- Specified by:
getPageDimensionin classjava.awt.PrintJob- Returns:
- a
Dimensioninstance, the size of the page
-
getPageResolution
public int getPageResolution()
This returns the page resolution.This is the PDF (and Postscript) device resolution of 72 dpi (equivalent to 1 point).
- Specified by:
getPageResolutionin classjava.awt.PrintJob- Returns:
- an
int, the resolution in pixels per inch
-
lastPageFirst
public boolean lastPageFirst()
In AWT's PrintJob, this would return true if the user requested that the file is printed in reverse order. For PDF's this is not applicable, so it will always return false.
- Specified by:
lastPageFirstin classjava.awt.PrintJob- Returns:
- false
-
getPDFDocument
public PDFDocument getPDFDocument()
Returns the PDFDocument object for this document. Useful for gaining access to the internals of PDFDocument.- Returns:
- the PDF object
-
getCurrentPage
public PDFPage getCurrentPage()
Returns the current PDFPage being worked on. Useful for working on Annotations (like links), etc.
- Returns:
- the
PDFPagecurrently being constructed
-
getCurrentPageNumber
public int getCurrentPageNumber()
Returns the current page number. Useful if you need to include one in the document
- Returns:
- the
intcurrent page number
-
addOutline
public PDFOutline addOutline(java.lang.String title)
This method attaches an outline to the current page being generated. When selected, the outline displays the top of the page.
- Parameters:
title- aString, the title of the Outline- Returns:
- a
PDFOutlineobject that was created, for adding sub-outline's if required.
-
addOutline
public PDFOutline addOutline(java.lang.String title, int x, int y, int w, int h)
This method attaches an outline to the current page being generated. When selected, the outline displays the specified region.
- Parameters:
title- Outline title to attachx- Left coordinate of regiony- Top coordinate of regionw- width of regionh- height of region- Returns:
- the
PDFOutlineobject created, for adding sub-outline's if required.
-
addNote
public PDFAnnot addNote(java.lang.String note, int x, int y, int w, int h)
Convenience method: Adds a text note to the document.- Parameters:
note- Text of the notex- Coordinate of notey- Coordinate of notew- Width of the noteh- Height of the note- Returns:
- Returns the annotation, so other settings can be changed.
-
-