Java Printing to specific page size using label printer

后端 未结 3 929
猫巷女王i
猫巷女王i 2021-02-06 18:29

I am trying to use a label printer (EPSON TM-T88V to be specific), to spit out PNG images.

I can get it to print fine, except when I am printing an image dimensions (220

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-06 19:19

    You can find the available paper sizes via:

    PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
    Media[] res = (Media[]) printService.getSupportedAttributeValues(Media.class, null, null);
    for (Media media : res) {
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName) media;
            MediaSize ms = MediaSize.getMediaSizeForName(msn);
            float width = ms.getX(MediaSize.INCH);
            float height = ms.getY(MediaSize.INCH);
            System.out.println(media + ": width = " + width + "; height = " + height);
        }
    }
    

    Once you've found the available MediaSizeName that most closely fits your paper size, simply add it in place of MediaSizeName.ISO_A7.

提交回复
热议问题