The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

saiyedriyaz (1) [Avatar] Offline
#1
Hi,

I'm trying to print a bag tag pdf on a Zebra TTP2130 air line printer.
Problem here is, it prints only a half of the document.
The paper width is 2.25 inch and height is 16 inch.
I'm using PDFRenderer (https://pdf-renderer.dev.java.net) to render a pdf document.

My code for rendering is:

public int print ( final Graphics graphics, final PageFormat pageFormat, final int index ) throws PrinterException
{
final int pagenum = index + 1;
if ( ( pagenum >= 1 ) && ( pagenum <= pdfFile.getNumPages ( ) ) )
{
final Graphics2D graphics2D = ( Graphics2D ) graphics;
final PDFPage page = pdfFile.getPage ( pagenum );

// fit the PDFPage into the printing area
final Rectangle imageArea =
new Rectangle ( ( int ) pageFormat.getImageableX ( ), ( int ) pageFormat.getImageableY ( ),
( int ) pageFormat.getImageableWidth ( ), ( int ) pageFormat.getImageableHeight ( ) );

graphics2D.translate ( 0, 0 );
final PDFRenderer pgs = new PDFRenderer ( page, graphics2D, imageArea, null, null );
try
{
page.waitForFinish ( );
pgs.run ( );
}
catch ( InterruptedException ie )
{
// nothing to do
}
return PAGE_EXISTS;
}
else
{
return NO_SUCH_PAGE;
}
}

I tried setting paper with,height and printable area but not luck with that.

final Paper paper = new Paper ( );
int width = 153; // ( int ) page.getBBox ( ).getWidth ( );//
int height = 1160;// ( int ) page.getBBox ( ).getHeight ( );//

paper.setImageableArea ( 5.688, 5.688, 141.696, 1138.104 );
paper.setSize ( width, height );
pageFormat.setPaper ( paper );

job.setPrintable ( this, pageFormat );
job.print ( );

If I pop-up a page set up dialog and change page settings (printer->advanced), it prints correctly.
But since this is a background process, I don't need to show any page set up dialog.
These setting has to be done programatically.
Please share your thought on this.

Riyaz