Question

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-

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top