• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Printing more than one page

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to print the contents of JHelpContentViewer, which is a sub-class of JComponent. I am able to print only the first page (i.e only the portion which is visible in the screen). The contents and length of JHelpContentViewer is dynamic. JHelpContentViewer will have scroll bar if the contents are more than the visible area.
This is the code:
public int
print(Graphics g, PageFormat pf, int pi) throws PrinterException
{
Graphics g2d = (Graphics2D) g.create();
int x = (int)pf.getImageableX();
int y = (int)pf.getImageableY();
int hPage = (int)pf.getImageableHeight();
int wPage = (int)pf.getImageableWidth();
if (pi == 0)
{
g2d.translate(x,y);
g2d.setClip(0,0,wPage,hPage);
}
else
{
g2d.translate(x,-(pi*hPage));
g2d.setClip(0,0,wPage,hPage);
}
if (pi >= 3)
return NO_SUCH_PAGE;
else
{
contentViewer.paint(g2d);
return Printable.PAGE_EXISTS;
}
}
Can someone tell me how to print all the pages?
Any help will be greatly appreciated.
Thanks,
- Raja.
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to Swing.
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
This might help you.
https://coderanch.com/t/335516/GUI/java/print-multiple-pages-printer
regards,
Raj
reply
    Bookmark Topic Watch Topic
  • New Topic