• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java How to set Printer Margins  RSS feed

 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when trying to print using the Print API - the margins seem to be something not in our control!.. Please help me out to set printer margins or is there any way to set margins at Operating system level.

By default all the four left, right, top and bottom are set to 1.
 
Ankur Talwar
Greenhorn
Posts: 9
C++ Eclipse IDE Flex
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even I am looking for way around this issue.

Did you by any chance got how to set margins?

In case someone else knows please do share.

This is the code I am using to print :-


thanks in advance.

EDIT:- I just tried margins on JTextArea itself like this

Doesnt work for printing on paper though.

On a closer look in the dialog box which pops open for print, the margins are pre-set to 1 inch on all top, bottom, left and right.

If it is possible even zero inch margins will be good.

Thanks again.
 
Ankit Tripathi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this link can help you,people-
webpage
 
Ankur Talwar
Greenhorn
Posts: 9
C++ Eclipse IDE Flex
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks it works.

But there is a problem. I have a JTextArea getting filled with dynamic content. Previously I was just doing JTextAreaName.print(), now when I pass the same string in drawstring function it only prints one line. How to solve this now?
 
Ankit Tripathi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "Dynamic Content"?
About which String you are talking?
 
Ankur Talwar
Greenhorn
Posts: 9
C++ Eclipse IDE Flex
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By dynamic content I mean, I am getting data from a database and making a string which is formatted as and when the data is fetched. Small sample will be something like

Here all the functions used return a string.
Also this is just a sample, actual printing string is comprised of several columns and since one of the column gets cut I had to implement something to reduce the margins. Above code does set the margins perfectly. But prints only single line (it ignores the \n in the string completely)

Now I have got this code working


Got this code here http://java.sun.com/products/java-media/2D/forDevelopers/sdk12print.html

Only problem now is that if some columns are empty, this code kinda stretches them to fit the screen, and hence columns are not perfect. I have tried a lot of trial and error and seems I am pretty close to solving it. Any help on how to print exactly as it shows in JTextArea will be appreciated. Thanks again.
 
Ankit Tripathi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String str = "Date :"+getDate()+"\nReceiptNo \t"+getReceipt()+"\n You paid 500 rs. \n Thanks For coming.";

Instead of putting "\n" and "\t" in your string,You can navigate and divide your whole document in something like that.



try it with different values of i,j, different combinations of loops and with values of INCH
I think it should help you,dude.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!