This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes Printing multiple pages in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Printing multiple pages in Java" Watch "Printing multiple pages in Java" New topic
Author

Printing multiple pages in Java

Raja Kannappan
Ranch Hand

Joined: May 08, 2002
Posts: 83
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.


SCJP
garrett sudicky
Greenhorn

Joined: Jul 10, 2013
Posts: 7
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Printing multiple pages in Java
 
Similar Threads
can't print Image , Black rectangle is printed ???
Printing more than one page
how to print multiple page text
problem in printing
Printing more than one page