Here is a list of general questions along with links to example source code. Please contact us if you have an additional question.
How do I find out what printers are accessible?
The PrinterJob class provides access to the printing system, allowing the user to list and select a printer using the code snippet here.
The PDF printout does not fit correctly onto the page
Java Printing allows the user to set page size and a visible page size which JPedal will use for printing. This can be read using:
PrinterJob printJob = PrinterJob.getPrinterJob();
PageFormat pf = printJob.defaultPage();
The user can also define their own page sizes to give the best fit:
//Create default Page format A4
Paper paper = new Paper();
//A4 borderless (setting may need adjustment)
//will make part of page disappear
//paper.setImageableArea(0, 0, 595, 842);
//works on our printers
paper.setImageableArea(5, 5, 565, 812);
These values will be ignored if inappropriate for a specific printer, resulting in the image being clipped. So either, use the defaults or test for a range of printers.
How do I select a PDF printer?
This code will select the printer if it is available.
The printer can be set using JVM flags, the list of JVM flags can be found here.
PDF Print Dialog Options
The JPedal Viewer has a feature-packed print panel allowing you detailed control over the printing of your PDF documents and displays a preview of the output with your currently selected settings.
How do I print in monochrome?
This code shows how to print to monochrome.
Auto-rotate and centre option
Auto-rotate and centre option is off as a default but can be set as in this example.
Auto-rotate or centre options can also be set independently of each other using the following methods.
//Set auto rotate
//Set print centering
PDF Print view
JPedal can print only the part of the page currently displayed as in this example.
Use PDF size for Printer paper size
Paper size is used as the default but the PDF size can be set as in this example.
Setting PDF page size
PDF Page size in normally part of the Paper object and can be read from the PrinterJob object and altered. Values will not over-ride any hard-coded limits on the printer. The org.jpedal.examples.viewer.paper.PaperSizes class contains multiple settings for different page layouts. Always use setImageableArea() as well as the size. It can be set for printing as in this example.
The paper size can be set using JVM flags, more information can be found here.
PDF Page Orientation
JPedal automatically calculates the LANDSCAPE/PORTRAIT setting to use based on the PDF page size. We recommend you do not set this manually.
Printing a range of pages
JPedal can print only the part of the PDF page currently displayed as well as just odd or even page. This is shown in example code.
Reducing PDF printing size and speed
To improve this we have added some modes which speed up the process using Java’s font renderer wherever possible. This is enabled using the method org/jpedal/PdfDecoder.html#setPrintPageMode(int) with one of the following values.
- PdfDecoder.NOTEXTPRINT (Default mode)
- PdfDecoder.TEXTGLYPHPRINT (Lets Java create Glyphs if font matches)
- PdfDecoder.TEXTSTRINGPRINT (Try and get Java to do all the work)
- PdfDecoder.STANDARDTEXTSTRINGPRINT (Try to print all 14 standard fonts (ie Arial, Courier, Times New Roman) using standard Java fonts even if embedded. This may not work if the font has custom encoding.)
We have found PCL printing especially can be very slow and benefits from these modes, but it will work on all printers.
Over-Printing (also works for screen display)
Draw additional objects explains how to draw your own objects on top of the PDF printout (ie special Annotations, copyright notice).
Writing your own custom PDF print code
If you are writing your own custom code and try to print some pages before the PDF, the whole PDF will not print out. You may need to tell JPedal you have already printed some pages using the PdfDecoder method useLogicalPrintOffset(int pagesPrinted)
Printing PDF forms using custom code
The CustomFormPrint interface allows you to totally control the printing of the PDF form widgets, over-riding any or all. If you pass an instance of a custom interface into JPedal, it will be called when printing occurs.
PDF Printing tutorials
The tutorials show you how to easily add Print PDF capabilities to your Java software and customise it with JPedal.
PDF Printing In Java. A simple tutorial to show how you can print PDF files with JPedal.