• Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing multiple pages from a textarea  RSS feed

 
garrett sudicky
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone, i am having extreme difficulty trying to print my data from a jtextarea. i tried the regular print(); method but i couldnt figure out how to preset the margins so i dont have to change them everytime. So now i am attempting to use printer job and graphics to print my pages. i figured out how to set my margins after a lot of frustration, but now when its more than one page long it prints the first page again and again instead of printing the second half of the text area. here is my code. i will greatly appreciate any help you might have for me.



 
Maxim Karvonen
Ranch Hand
Posts: 121
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Garrett.

You should use pageIndex to adjust graphics to the proper portion of the textarea (similar to already existing translations with g2.translate). Point (0, 0) in graphics is a corner of a page on each call, not a "corner of stripe of all pages". You shifts your textarea into a same position each page and this leads to a same result.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
garrett sudicky, please BeForthrightWhenCrossPostingToOtherSites
http://www.java-forums.org/new-java/79757-printing-setup.html
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
crossposted on stackoverflow too
 
garrett sudicky
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi maxim, thanks for the help. im just not sure where i would write that in at? the printer job part or inside the print()? and not quite sure how i would do that either? could you give me an example please? thanks again for your reply
 
Maxim Karvonen
Ranch Hand
Posts: 121
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should do that in a printer job where you setup graphics. Add something like that in an appropriate place

 
garrett sudicky
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot i really appreciate it but is there a reason you wrote -792 instead of 792?
 
garrett sudicky
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maxim would you want me to post the main class as well so you can try it out? normally data gets generated and appended there from a different part of the total program but its easy enough to just type in a bunch of lines to get over the one page mark.
 
Maxim Karvonen
Ranch Hand
Posts: 121
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
garrett sudicky wrote:thanks a lot i really appreciate it but is there a reason you wrote -792 instead of 792?

Yes, there is a reason. I want to move all component "up" to adjust graphics "vieport" to a correct component portion. You should draw page, page's graphics and component layouts on a sheet of paper. Mark origin points (0, 0) on both graphics and component. First draw it without any translations. Then draw with one translation only. Then with two translations and so on. Compare shifts with -792 and 792. This should make a difference.

I may take the sign wrong but that means that your existing code (provided in the first post) is also incorrect because it shifts graphics in a wrong direction.
 
garrett sudicky
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im having trouble following what you think i should do. is there a drawPage(); method like the drawstring? when i do this
it prints two blank pages out.
would you mind showing me where i could put it at, i think im trying the wrong spot.

 
Maxim Karvonen
Ranch Hand
Posts: 121
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you ever tried to paint your shift on a paper? Both "print page" and component on a same paper page? Did you tried to draw dimensions/gaps on that paper between component bounds?

According to your code.

Place is correct. Code is not. You "shift out" component out of printable area. If you paint layout on paper, you will clearly see that. Can you see a difference between my code and your code? How do you expect to print "different" pages if you perform exactly the same operations on each call to a print method?

You can directly draw string on a graphics. But you have problems with a basic page layout. You must know exact place on a graphics to output string. This also requires to correctly use/understand pageIndex. Without understanding page/printing layout you will end outputting same strings at a same (wrong) place.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!