• 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 hardcopy - multiple copies

 
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'm trying to implement print capability in my Java application. I'm implementing printable interface in my program. It works but it prints only one page. If the screen has more than one page to print, it prints only the first page but leaves the other pages.
My print implementation looks like this:
public int
print(Graphics g, PageFormat pf, int pi) throws PrinterException
{
if (pi > 0)
return NO_SUCH_PAGE;
else
{
contentViewer.paint(g);
return Printable.PAGE_EXISTS;
}
}
contentViewer is a JComponent. If i comment
if (pi>0) return NO_SUCH_PAGE part, it prints mulitple copies of the first page. But it doesn't print the second page, third page etc.,
Can anyone suggest me how to print the entire document ?
Thanks,
- Raja.
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if (pi > 0)
return NO_SUCH_PAGE;
will have to be replaced with something more elaborate. I'm not really sure what I'm doing, but maybe you could do something like:
--
int top = pf.getHeight() * (pi - 1);
int bottom = pf.getHeight() * pi;
// is this page number beyond the end?
if (top > documentVerticalSize) return NO_SUCH_PAGE;
// it's not. print this page then
g.translate(0, top);
contentViewer.paint(g);
return Printable.PAGE_EXISTS;
--
I'm not a graphics programmer and don't know the specifics of the Graphics and PageFormat classes, but this might work with some tweaking. You'll probably need to look at the javadocs.
 
Raja Kannappan
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My problem here is finding the document vertical size.
I've a JComponent which is on the right hand side of split pane. I'm trying to print that. It's contents may vary based on what is present in the left hand side of the split pane. It is dynamic. Is there a way to find the size of my JComponent ?
note: getSize().height, getHeight(), getBounds().height won't work because they return only the size of the component which is shown in the screen. If the component is larger than one page, the right pane has a scroll bar in it. In this case these methods return only the size of the component which is visible in the right pane.
Thanks,
- Raja.
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raja,
I found the below mentioned article in DDJ'97 issue for multipage printing. I was not able to find the code listing on the website link, but maybe you can get hold of DDJ'97 and get the code listing.
http://www.ddj.com/print/documentID=13011
 
Raja Kannappan
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi gaurava, Thanks for your response. But unfortunately i was unable to get to that article. The link which you mentioned redirects itself to http://www.ddj.com. Can you tell me how to get to that article?
Thanks,
- Raja.
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you ask getHeight() to your ScrollPane or to your component, which is inside the scrollpane?
I did the same with printing and for me it worked.
I asked the component, which is in the scrollpane.
 
Raja Kannappan
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rene,
In my case, i've a split pane and to the right of the split pane i've a JComponent.
Both JComponent.getHeight() and splitpane.getHeight() returns me only the visible area in the screen.
If the JComponent at the right of the split pane occupies more than one screen size, it gets a scroll bar. Here it just returns the screen size which is visible. It is not returning the whole size of the JComponent.
Is there any way to find the whole size of a JComponent? (not just what is visible in the screen)
Thanks,
- Raja.
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please try this little example:
 
Raja Kannappan
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rene,
Yes. This example works when i've JTextArea inside scroll pane in a split pane.
But if i've JContentViewer inside scroll pane in a split pane, it doesn't work. Mine is a help application and JContentViewer is a JavaHelp API. JContentViewer extends JComponent. So, getSize().getHeight() should work. But it is giving me only the visible area's height. It is not giving me the whole area of the JContentViewer. Do you have any idea on this ?
Thanks,
- Raja.
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Raja,
what happens, if you wrap your JContentViewer with a JPanel? At least in my little example it worked too.
So you would have the structure:
JSplitPane - JScrollPane - JPanel - JContentViewer
Sorry, I don't know anything about JContentViewer but could it be, that this viewer has it's own JScrollPane?
I will keep thinking. Sometimes we are searching the bug at a wrong place (like me yesterday evening).
Bye
Rene
 
Raja Kannappan
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rene,
JSplitPane - JScrollPane - JPanel - JContentViewer doesn't work. It prints the JPanel's height as 0 and screen is blank. I tried this: JSplitPane - JPanel - JContentViewer. It is now giving the height which is visible in the screen. It is not giving the actual height of the JContentViewer.
I think JContentViewer has it's own scroll pane because when i do directly like JSplitPane - JContentViewer, it gets a scroll bar automatically. Here also it gives the height which is visible in the screen and not the actual height.
Any ideas?
Thanks,
- Raja.
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I looked to the JavaHelp API and I was not able to see a JContentViewer, only a JHelpContentViewer. Is this the same or do I have the wrong version of JavaHelp (1.1)?
Anyway, you have to try to ask for the component, which is inside the scrollpane.
Rene
 
Raja Kannappan
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. It is JHelpContentViewer only. That was a typo.
>Anyway, you have to try to ask for the >component, which is inside the scrollpane.
I couldn't understand what you are trying to say here. Can you explain me the nesting and to ask for what inside what?
Thanks,
- Raja.
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mmhh, ok JHelpContentViewer is a JComponent, so it inherits all methods from it. I think that the JHelpContentViewer contains some other components, like a JScrollPane.
If you look to the Sourcecode of JavaHelp API (BasicContentViewerUI) then you will see, what I mean. Maybe you have to create a recursive function to ask for the JScrollPane. The class, which is inside of the JScrollPane has the name JHEditorPane. This is an inner class of BasicContentViewerUI and extends from JEditorPane.
This mehtod for searching recursively for the inner component of JScrollPane is ugly, but this is the only way I see.
 
Raja Kannappan
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'll try that.
Thanks Rene for your help,
- Raja.
 
reply
    Bookmark Topic Watch Topic
  • New Topic