Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

printdialog properties..  RSS feed

 
Venkat Injapury
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can any body suggest the printing Api,examples and tutorials. or any advice is appreciated.
I am able to print the java swing component content, but i am not able to handle the print dialog options...
Here my code is like this........................
public void printPage(){
PrinterJob pj=PrinterJob.getPrinterJob();
pj.setPrintable(this);
pj.printDialog();
try{
pj.print();
}catch (Exception e) {
System.out.println("Error in Printing");
e.printStackTrace();
}
}
//-------------------------
public int print(Graphics pg, PageFormat pageFormat,int pageIndex) throws PrinterException {
Dimension d = editPane.getSize();
double panelWidth = d.width;
double panelHeight = d.height;
double pageHeight = pageFormat.getImageableHeight();
double pageWidth = pageFormat.getImageableWidth();
double scale = pageWidth/panelWidth;
int totalNumPages = (int)Math.ceil(scale * panelHeight / pageHeight);
if(pageIndex >= totalNumPages)
return Printable.NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D)pg;
g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
g2.translate(0f, -pageIndex * pageHeight);
g2.scale(scale, scale);
editPane.print(g2);
return Printable.PAGE_EXISTS;
}
//-----------
Here i have to handle the print dialog properties and cancel button
Thanks is advance.
Venkat Injapury
 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
As far as I know ( from my limited printing experience )the options for the printer seen in the print dialog are handled by the underlying OS.
Cancel can be controlled however as the printDialog() method returns true if the user does not cancel the dialog; false otherwise ( from the API docs )
You could then change your code a little:


Hope that helps,
Terry
 
Venkat Injapury
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
It is working fine cancel button of print dialog.
Still i am looking to handle the properties of print dialog. Intially i need for windows OS. Can you suggest me any thing it is appreciated.
Thanks again,
Venkat
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!