How to change print params when using new java 1.6 JTextComponent print()

I have a JTextComponent (JTextArea). I am trying to print its contents with using the new 1.6 .print() functionality. This is working well. I am also doing this in a headless/non-interactive mode using the following method signature:

boolean print(MessageFormat headerFormat, MessageFormat footerFormat, boolean showPrintDialog, PrintService service, PrintRequestAttributeSet attributes, boolean interactive);

Again this prints out my content.

HOWEVER... I would like to set my own print parameters (namely Margin size and Paper Size)..Mine are custom/non-standard as this is for a receipt printer -

Is there any way to set/configure this information when using this form of printing ?

The problem I am having now is trying to get my content to fit the printable area - and I would love to have more control - I guess using PrintJob and Document this would be available through the PageFormat object - But I don't know how to do same using the convience print method above.

Thanks in advance -A-


You need to use the PrintRequestAttributeSet attributes to specify the attributes of the print job.

You create a new instance of the PrintRequestAttributeSet

PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();

You then need to add the attributes for your request to that set. Take a look here for all the different attributes that you can use.

I think you will need MediaSize and MediaPrintableArea

Need Your Help

submit form and then show results in an existing div

jquery ajax forms

This don't work for me. The results show in action form page.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.