我们正在尝试在点阵打印机上通过 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)
{
}