我们正在尝试通过点阵打印机上的java打印。我们使用自定义大小创建了Paper对象。但是当它进入打印机时,它不需要自定义尺寸。它需要11英寸或12英寸的尺寸。以下是我们正在使用的代码。请建议解决方案。
PrinterJob job = PrinterJob.getPrinterJob(); // Get a PrinterJob.
PageFormat format = job.defaultPage(); // Get the default page format, then ask the user to customize it.
Paper paper = format.getPaper(); // Note: Custom size of paper should be supported by attach Printer.
paper.setSize((PaperWidth*72),
(PaperHeight*72)); // Set Custom size of the Paper.
paper.setImageableArea(MarginLeft*72, MarginTop*72,
paper.getWidth() - MarginRight*72 - MarginLeft*72,
paper.getHeight()- MarginBottom*72 - MarginTop*72);
System.out.println(paper.getHeight());
format.setPaper(paper); // Set the paper.
PageFormat pf = job.validatePage(format);
Book bk = new Book(); // Set up a book, with exact no. of pages to be printable.
bk.append(new TestClass(), pf, numPages);
job.setPageable(bk); // Pass the book to the PrinterJob
////// OR set printable without book.
//// job.setPrintable(new TestClass(),format);
if (job.printDialog()) // Put up the dialog box
{
try
{
job.print(); // Print the job if the user didn't cancel printing.
}
catch (PrinterException ex)
{
}