• 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 multiple pages in Java

 
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 wrote a help viewer with JavaHelp API's. The html help files are displayed in JHelpContentViewer, which is a sub-class of JComponent. I want to print the contents in JHelpContentViewer. I don't know how many pages they will be, because different html pages will have different lenghts. When I try to print them, I am able to print only the first page. Other pages comes as blank. Here is my source 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);
}
// In this example, I'm putting 3, how can
// I find this value
if (pi >= 3)
return NO_SUCH_PAGE;
else
{
contentViewer.paint(g2d);
return Printable.PAGE_EXISTS;
}
}
public static void
printScreen(Printable printable)
{
PrinterJob printJob = PrinterJob.getPrinterJob();
if (pf == null)
pf = printJob.defaultPage();

printJob.setPrintable(printable,pf);
if (printJob.printDialog())
{
try
{
printJob.print();
}
catch (Exception PrintException)
{
}
}
}
Here only the first page gets printed? The remaining pages are printed blank. Also, I need to know how many pages are there, so that I can return NO_SUCH_PAGE appropriately.
Any help would be greatly appreciated.
Thanks,
- Raja.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im not sure if you will ever see this seeing how this is 10 years later but im doing it now and i found the height of the textarea im using and then compared that to the imageable area in a for statement.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic