Skip to main content

PDFRenderer wrong printing size

2 replies [Last post]
rodrigo_correa
Offline
Joined: 2010-02-08
Points: 0

Hello,

I'm trying to print pdf files with PDFRenderer but I get smaller image on the letter page. When I modify the page size settings the document prints ok in some printers but in others I got this error "pcl XL error: warning: illegalMediaSize".
any idea??

I also run the demo viewer (java -jar PDFRenderer.jar) with de same small image.

Thaks in advance.

This is the code...

if(initializedOK) try {
PDFFile pdfFile = new PDFFile(pdfByteBuffer); // Create PDF Print Page
PDFPrintPage pages = new PDFPrintPage(pdfFile);

// Create Print Job
PrinterJob pjob = PrinterJob.getPrinterJob();
AttributeSet aset3 = new HashAttributeSet();
aset3.add(new PrinterName(printerName, null));
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, aset3);

// Si no estuvo la impresora no hacemos nada.
if(services.length < 1) {
System.err.println(printerName + " Impresora no definida, Thread no. " + this.getId());
return;
}

// Si hay mas de dos con el mismo nombre puede haber problemas
if(services.length > 1) {
System.err.println(printerName + " CUIDADO Impresora DUPLICADA, Thread no. " + this.getId());
return;
}

System.out.println(" Thread " + this.getId() + ": PdfFile: " + jobName +
", Impresora: " + services[0] +
", Copias: " + copies );

// Se setea la impresora, el numero de copias, y el nombre del job de impresion.
pjob.setPrintService(services[0]);
pjob.setCopies(copies);
pjob.setJobName(jobName);

// Asigno el tamaño del papel
Paper paper = new Paper();
paper.setSize(612, 792);
paper.setImageableArea(0, 0, 612, 792);
PageFormat pf = PrinterJob.getPrinterJob().defaultPage();
pf.setPaper(paper);

Book book = new Book();
book.append(pages, pf, pdfFile.getNumPages());
pjob.setPageable(book);

// Se envia a la impresora
pjob.print();
System.out.println(" Thread " + this.getId() + ": Envío de impresión OK");
} catch (IOException e) {
e.printStackTrace();
} catch (PrinterException e) {
e.printStackTrace();
if(intento < MAXINTENTOS) reIntento();
}
System.out.println(" Thread " + this.getId() + ": Fin de hilo");

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bperchma2
Offline
Joined: 2010-09-23
Points: 0

Try the source code referred to in this article: http://webmoli.com/2008/11/03/java-print-pdf/ . This uses the AWT Print service, which works corectly with PDFRenderer.

kschaefe
Offline
Joined: 2006-06-08
Points: 0

You are best sending PDFRenderer questions to the PDFRenderer mailing list.

Karl