java – Problem with the paper size of a printer

Question:

I have a problem about the measurements of the paper that my Brother QL-800 printer with width 62mm has. and height not defined, since the paper is continuous so that the user can put the necessary measures.

I am creating an application in and I cannot set height measures less than 62mm. (corresponding to the width), although it is possible to set more than 62mm.

This is my code:

PrinterJob job = PrinterJob.getPrinterJob();
PageFormat pf = job.defaultPage();

Paper paper = new Paper();
paper.setSize(175.748031496, 175.748031496);
paper.setImageableArea(0, 0, 175.748031496, 175.748031496);

pf.setPaper(paper);

job.setPrintable(new ObjetoDeImpresion(), pf);
job.setJobName("nombre_de_impresion");
try {
    job.print();
} catch (PrinterException e) {
    e.printStackTrace();
}

Measurement 175.748031496 are points and corresponds to 62mm .

This is the object to print:

public class ObjetoDeImpresion implements Printable {

    public ObjetoDeImpresion() {
    }

    @Override
    public int print(Graphics g, PageFormat f, int i) throws PrinterException {
        Graphics2D g2 = (Graphics2D) g;

        switch (i) {
            case 0:
                g2.drawRect(30, 50, 80, 20);
                g2.drawLine(0, 28, 130, 28);

                return PAGE_EXISTS;
            default:
                return NO_SUCH_PAGE;        // No other pages
        } //To change body of generated methods, choose Tools | Templates.
    }

}

I think the printer is detecting as if its height is also 62mm. since the paper at the top is continuous.

What I can do?

Answer:

Try adding PrintRequest to change printer attributes:

PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

you can put it this way:

try {
    job.print(aset);
} catch (PrinterException e) {
    e.printStackTrace();
}
Scroll to Top