posted 21 years ago
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.