A
A
anatoly3142014-03-25 16:19:43
Java
anatoly314, 2014-03-25 16:19:43

How to print from Java with more than 72dpi?

Good afternoon.
It is necessary to print invoices from java to a thermal printer. The maximum printer resolution is 203 dpi. When printing a square with a size of 72x72px, a square with an edge of 1 inch is obtained, from this I conclude that it prints with a resolution of 72dpi. I tried to use the following code in the formation of PrinterJob, but to no avail. If someone came across, please advise what to do?

HashPrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();
    attributeSet.add(PrintQuality.HIGH);
    attributeSet.add(new PrinterResolution(203,203,PrinterResolution.DPI));
job.print(attributeSet);

Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Moseychuk, 2014-03-26
@fshp

Maybe DPI 72 is specified in the properties of the printed image? This is done so that the image has the same size on different printing devices.

D
dokwork, 2015-11-18
@dokwork

if you draw on canvas yourself, you can scale the Graphics:

@Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException, NotFitOnPageException {
   Graphics2D g = (Graphics2D) graphics;
   double s = 72.0 / 203;
   g.scale(s, s);
   ...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question