aaronqli
aaronqli

Reputation: 809

Java printing API: java.lang.ClassCastException on custom media size

The following code throws java.lang.ClassCastException

PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(new MediaSize(60,80,Size2DSyntax.MM));

I suspect I did line 2 incorrectly, but I cannot find detailed documentation for Java printing services. What is the proper way to define custom media size?

Upvotes: 3

Views: 2461

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347314

MediaSize does not implement PrintRequestAttribute, hence the error.

Instead, I think, you need to use something like

aset.add(new MediaPrintableArea(5, 5, 50, 80, MediaPrintableArea.MM));

instead...

You can check out MediaPrintableArea for me details.

Upvotes: 4

Related Questions