Package net.sf.paperclips
Class PaperClips
java.lang.Object
net.sf.paperclips.PaperClips
This class contains static constants and methods for preparing and printing
documents. Methods in this class supersede those in PrintUtil.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Indicates that the printer's default page orientation should be used.static final int
Indicates landscape page orientation.static final int
Indicates portrait page orientation. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
endDummyJob
(org.eclipse.swt.printing.Printer printer) Ends a dummy job on the given Printer if the platform requires a dummy job.static void
error
(int code) Triggers an appropriate exception based on the passed in error code.static void
Triggers an appropriate exception based on the passed in error code.static void
Triggers an unspecified exception with the passed in detail.static boolean
getDebug()
EXPERIMENTAL: Returns whether debug mode is enabled.static org.eclipse.swt.printing.PrinterData
Returns a PrinterData for the system-default printer, or the first printer if no default printer is configured.static org.eclipse.swt.graphics.Rectangle
getMarginBounds
(Margins margins, org.eclipse.swt.printing.Printer printer) Returns the bounding rectangle of the printable area which is inside the given margins on the paper.static PageEnumeration
getPageEnumeration
(PrintJob printJob, org.eclipse.swt.printing.Printer printer, org.eclipse.swt.graphics.GC gc) Returns aPageEnumeration
for the passed in PrintJob on the given Printer, using the given GC.static PrintPiece[]
Processes the print job and returns an array of pages for the given printer device.static org.eclipse.swt.graphics.Rectangle
getPaperBounds
(org.eclipse.swt.printing.Printer printer) Returns the bounding rectangle of the paper, including non-printable margins.static org.eclipse.swt.graphics.Rectangle
getPrintableBounds
(org.eclipse.swt.printing.Printer printer) Returns the bounding rectangle of the printable area on the paper.static PrintPiece
next
(PrintIterator iterator, int width, int height) Calls iterator.next(width, height) and returns the result.static void
Prints the print job to the given printer.static void
Prints the print job to the given printer.static void
setDebug
(boolean debug) EXPERIMENTAL: Sets whether debug mode is enabled.static void
startDummyJob
(org.eclipse.swt.printing.Printer printer, String name) Starts a dummy job on the given Printer if the platform requires it.
-
Field Details
-
ORIENTATION_DEFAULT
public static final int ORIENTATION_DEFAULTIndicates that the printer's default page orientation should be used.- See Also:
-
ORIENTATION_PORTRAIT
public static final int ORIENTATION_PORTRAITIndicates portrait page orientation.- See Also:
-
ORIENTATION_LANDSCAPE
public static final int ORIENTATION_LANDSCAPEIndicates landscape page orientation.- See Also:
-
-
Method Details
-
error
public static void error(int code) Triggers an appropriate exception based on the passed in error code.- Parameters:
code
- the SWT error code.
-
error
Triggers an unspecified exception with the passed in detail.- Parameters:
detail
- more information about error.
-
error
Triggers an appropriate exception based on the passed in error code.- Parameters:
code
- the SWT error code.detail
- more information about error.
-
setDebug
public static void setDebug(boolean debug) EXPERIMENTAL: Sets whether debug mode is enabled. This mode may be used for troubleshooting documents that cannot be laid out for some reason (e.g. "Cannot layout page x" error occurs).THIS API IS EXPERIMENTAL AND MAY BE REMOVED OR CHANGED IN THE FUTURE.
- Parameters:
debug
- true to enable debug mode, false to disable it.
-
getDebug
public static boolean getDebug()EXPERIMENTAL: Returns whether debug mode is enabled.THIS API IS EXPERIMENTAL AND MAY BE REMOVED OR CHANGED IN THE FUTURE.
- Returns:
- whether debug mode is enabled.
-
getDefaultPrinterData
public static org.eclipse.swt.printing.PrinterData getDefaultPrinterData()Returns a PrinterData for the system-default printer, or the first printer if no default printer is configured.- Returns:
- a PrinterData for the system-default printer, or the first printer if no default printer is configured.
-
next
Calls iterator.next(width, height) and returns the result. This method checks multiple conditions to ensure proper usage and behavior of PrintIterators.This method is intended to be used by PrintIterator classes, as a results-checking alternative to calling next(int, int) directly on the target iterator. All PrintIterator classes in the PaperClips library use this method instead of directly calling the
PrintIterator.next(int, int)
method.- Parameters:
iterator
- the PrintIteratorwidth
- the available width.height
- the available height.- Returns:
- the next portion of the Print, or null if the width and height are not enough to display any of the iterator's contents.
-
print
Prints the print job to the given printer. This method constructs a Printer, forwards toprint(PrintJob, Printer)
, and disposes the printer before returning.- Parameters:
printJob
- the print job.printerData
- the PrinterData of the selected printer.
-
print
Prints the print job to the given printer.- Parameters:
printJob
- the print job.printer
- the printer device.
-
getPages
Processes the print job and returns an array of pages for the given printer device. Each element in the returned array has already had the page orientation and page margins applied. Therefore, when calling the paint(GC, int, int) method on each page, the printer's trim should be provided as the x and y arguments. In other words, the trim is taken as a minimum margin while applying calculating margins, but the position where the page's content is drawn is determined solely by the margin, and is not offset by the trim. This behavior is helpful for screen display, and is already compensated for in theprint(PrintJob, Printer)
method.- Parameters:
printJob
- the print job.printer
- the printing device.- Returns:
- an array of all pages of the print job. Each element of the returned array represents one page in the printed document.
-
startDummyJob
Starts a dummy job on the given Printer if the platform requires it. Dummy jobs allow the various Print components of PaperClips to perform measurements required for document layout, without actually sending a job to the printer. Only Mac OS X Carbon and Linux GTK+ are known to require dummy jobs.- Parameters:
printer
- the Printer hosting the dummy print job.name
- the name of the dummy print job.
-
endDummyJob
public static void endDummyJob(org.eclipse.swt.printing.Printer printer) Ends a dummy job on the given Printer if the platform requires a dummy job.- Parameters:
printer
- the Printer hosting the dummy print job.
-
getPageEnumeration
public static PageEnumeration getPageEnumeration(PrintJob printJob, org.eclipse.swt.printing.Printer printer, org.eclipse.swt.graphics.GC gc) Returns aPageEnumeration
for the passed in PrintJob on the given Printer, using the given GC. The Printer and GC must not be disposed while the enumeration is in use.- Parameters:
printJob
- the print jobprinter
- the Printer device, which must not be disposed while the PageEnumeration is in use.gc
- the GC, which must not be disposed while the PageEnumeration is in use.- Returns:
- a
PageEnumeration
for the passed in PrintJob.
-
getPaperBounds
public static org.eclipse.swt.graphics.Rectangle getPaperBounds(org.eclipse.swt.printing.Printer printer) Returns the bounding rectangle of the paper, including non-printable margins.- Parameters:
printer
- the printer device.- Returns:
- a rectangle whose edges correspond to the edges of the paper.
-
getPrintableBounds
public static org.eclipse.swt.graphics.Rectangle getPrintableBounds(org.eclipse.swt.printing.Printer printer) Returns the bounding rectangle of the printable area on the paper.- Parameters:
printer
- the printer device.- Returns:
- the bounding rectangle of the printable area on the paper.
-
getMarginBounds
public static org.eclipse.swt.graphics.Rectangle getMarginBounds(Margins margins, org.eclipse.swt.printing.Printer printer) Returns the bounding rectangle of the printable area which is inside the given margins on the paper. The printer's minimum margins are reflected in the returned rectangle.- Parameters:
margins
- the desired page margins.printer
- the printer device.- Returns:
- the bounding rectangle on the printable area which is within the margins.
-