Java Printing to specific page size using label printer

后端 未结 3 894
猫巷女王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 18:58

    Add a MediaPrintableArea:

    das.add(new MediaPrintableArea(0.05, 0.05, 0.05, 0.05, MediaPrintableArea.INCH));
    
    0 讨论(0)
  • 2021-02-06 19:00

    This is the settings I use for printing on A4 paper with 10mm margin.

    int width = Math.round(MediaSize.ISO.A4.getX(MediaSize.MM));
    int height = Math.round(MediaSize.ISO.A4.getY(MediaSize.MM));
    das.add(new MediaPrintableArea(10, 10, width-20, height-20, MediaPrintableArea.MM));
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题