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 a 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 a best fit (this is what the SilentPrint.java example code does).
//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 of test for 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, list can be found here.
PDF Print Dialog Options
The commercial versions of JPedal include a custom PDF Print Dialog with support for the options as Acrobat. It has lots of bells and whistles to provide scaling, rotation, and lots of other features for the user to select.
How do I print in monochrome?
This code shows how to print to monochrome.
Auto rotate and centre option
Auto rotate and center option is off as a default but can be set as in this example.
Auto rotate or center 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 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 page 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 speedup the process using Java’s font renderer wherever possible. This is enabled using these methods org/jpedal/PdfDecoder.html#setPrintPageMode(int) with values PdfDecoder.NOTEXTPRINT (normal mode – only needed to reset), PdfDecoder.TEXTGLYPHPRINT (intermediate mode – let Java create Glyphs if font matches), PdfDecoder.TEXTSTRINGPRINT (try and get Java to do all the work). We have found PCL printing especially can be very slow any benefits from these modes, but it will work on all printers.
Release 3.79b16 adds PdfDecoder.STANDARDTEXTSTRINGPRINT which will 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.
Over-Printing (also works for screen display)
Draw additional objects explains how to draw your own objects ontop 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 inteface 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.
PDF Print Examples lists the various printing examples available in JPedal.