# Print JPG file from Processing (printer)

**URL:** <https://discourse.processing.org/t/print-jpg-file-from-processing-printer/44461>\
**Category:** Coding Questions\
**Created:** [May 21, 2024, 2:31am UTC](https://discourse.processing.org/t/print-jpg-file-from-processing-printer/44461 "2024-05-21T02:31:07Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![dada](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@dada](https://discourse.processing.org/u/dada)\
**Post date:** [May 21, 2024, 2:31am UTC](https://discourse.processing.org/t/print-jpg-file-from-processing-printer/44461/1 "2024-05-21T02:31:07Z")

</div>

Hi 🙂  
I try to print with usb printer from processing.  
I think this project’s process is simple. if i tap enter key, image file is printed. printing is fine.  
but I have problem, printer print image like this photo.

 ![IMG_7881](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/b/8/b82b864603689e9df39db7b42acf5f7d3d0b6520.jpeg)

it is too small… how can i fix it?

I use peripage mini printer(via USB) and window 10.

```auto
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import java.io.*;

void setup() {
  size(400, 400);
  println("Press Enter to print the image.");
}

void draw() {
}

void keyPressed() {
  if (keyCode == ENTER) {
    printPDF("C:/Users/user/Documents/Processing/receipt/receipt_1.jpg", "PeriPage A6+"); // 여기에 PDF 파일 경로와 프린터 이름을 넣으세요
  }
}

void printPDF(String filePath, String printerName) {
  PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
  PrintService printService = null;

  for (int i = 0; i < printServices.length; i++) {
    if (printServices[i].getName().equals(printerName)) {
      printService = printServices[i];
      break;
    }
  }

  if (printService != null) {
    FileInputStream fis = null;
    try {
      fis = new FileInputStream(filePath);
      DocFlavor flavor = DocFlavor.INPUT_STREAM.PNG;
      Doc pdfDoc = new SimpleDoc(fis, flavor, null);
      DocPrintJob printJob = printService.createPrintJob();
      printJob.print(pdfDoc, null);
      println("Printing image...");
    } catch (FileNotFoundException | PrintException e) {
      e.printStackTrace();
    } finally {
      if (fis != null) {
        try {
          fis.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  } else {
    println("Printer not found: " + printerName);
  }
}

```

Thank you

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [May 22, 2024, 1:19am UTC](https://discourse.processing.org/t/print-jpg-file-from-processing-printer/44461/2 "2024-05-22T01:19:29Z")

</div>

Not sure it will make a difference, but have you tried DocFlavor.INPUT\_STREAM.JPEG? Reference is here: [https://docs.oracle.com/javase%2F7%2Fdocs%2Fapi%2F%2F/javax/print/DocFlavor.INPUT\_STREAM.html](https://docs.oracle.com/javase%2F7%2Fdocs%2Fapi%2F%2F/javax/print/DocFlavor.INPUT_STREAM.html)

A6 paper is a lot smaller than standard 8.5" x 11" typing paper and it may be scaling your image down in size to fit the paper. I tried to run your code and just now realized that you are using a special label printer, which I don’t have, and therefore will be unable to reproduce your problem. So it doesn’t look like I’m going to be much help. Perhaps someone else has this printer and could test your code and image.

---

<div class="post-metadata">

**Author:** ![dada](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@dada](https://discourse.processing.org/u/dada)\
**Post date:** [May 22, 2024, 1:47am UTC](https://discourse.processing.org/t/print-jpg-file-from-processing-printer/44461/3 "2024-05-22T01:47:38Z")

</div>

is it right? I post the image I want to print…  
sorry English is not my first language

 ![대지 1 사본 4@2x-100](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/6/a/6a910aaebf989221b19c6a75cf1ef0a8b132fb59.jpeg)

this picture is the image that I want to print.  
I think your guess is right. but there are no ways(like code things…) to adjust printing image size?

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [May 22, 2024, 2:04am UTC](https://discourse.processing.org/t/print-jpg-file-from-processing-printer/44461/4 "2024-05-22T02:04:05Z")

</div>

`there are no ways(like code things…) to adjust printing image size?`

I agree that is a valid point in trying to solve your problem. So far I’ve had no luck with Google searches.

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [May 22, 2024, 2:24am UTC](https://discourse.processing.org/t/print-jpg-file-from-processing-printer/44461/5 "2024-05-22T02:24:37Z")

</div>

1. Do you see a print dialog when you use DocFlavor? On a Mac it allows you to manually set the scale.

2. There is a Printer Resolution Class referenced here: [https://javadoc.scijava.org/Java6/javax/print/attribute/standard/PrinterResolution.html](https://javadoc.scijava.org/Java6/javax/print/attribute/standard/PrinterResolution.html)

I have no experience using it.

**Addendum:**  
Your receipt image measures 301 x 605 which is fairly small for an image. When printed on 8.5" x 11" paper it measures approximately 2" x 4" (width by length) which is about what I would expect for a receipt. Have you tried printing it out on another printer? Is there a setup dialog for your PeriPage label printer?

---

<div class="post-metadata">

**Author:** ![LangdonS](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@LangdonS](https://discourse.processing.org/u/LangdonS)\
**Post date:** [May 24, 2024, 12:41pm UTC](https://discourse.processing.org/t/print-jpg-file-from-processing-printer/44461/6 "2024-05-24T12:41:42Z")

</div>

Why not just export PNG and print that using Preview or Krita or something.

Windows also has a tendency to have issues.

Try it on Mac or Linux, try a different file type, or try a different image.

Processing may not be the best option for this; Java may work better.

---

<div class="post-metadata">

**Author:** ![LangdonS](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@LangdonS](https://discourse.processing.org/u/LangdonS)\
**Post date:** [May 24, 2024, 12:43pm UTC](https://discourse.processing.org/t/print-jpg-file-from-processing-printer/44461/7 "2024-05-24T12:43:07Z")

</div>

This may be helpful:

> <https://stackoverflow.com/questions/10479621/how-to-print-image-in-java>

---

<div class="post-metadata">

**Author:** ![dada](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@dada](https://discourse.processing.org/u/dada)\
**Post date:** [May 24, 2024, 1:11pm UTC](https://discourse.processing.org/t/print-jpg-file-from-processing-printer/44461/8 "2024-05-24T13:11:59Z")

</div>

Because It has that the driver of this printer on only window version …  
and I’m just a design student who learn about interactive art… i’m not developer. So I’m used to proseccing rather than java. also I have never use java before… 😢

I already tried to use another jpg file and png file, it doesn’t work

But i will try what you wrote

really thank you !

---

<div class="post-metadata">

**Author:** ![dada](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@dada](https://discourse.processing.org/u/dada)\
**Post date:** [May 24, 2024, 1:20pm UTC](https://discourse.processing.org/t/print-jpg-file-from-processing-printer/44461/9 "2024-05-24T13:20:18Z")

</div>

My printer have setup dialog, but it has only one option width 2" paper. That’s why I set the size of image small.  
Than if I try to adjust the size of image to fit in 8.5" 11" paper, could it be work well?..

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [May 24, 2024, 1:44pm UTC](https://discourse.processing.org/t/print-jpg-file-from-processing-printer/44461/10 "2024-05-24T13:44:08Z")

</div>

> [@dada](#):
>
> Than if I try to adjust the size of image to fit in 8.5" 11" paper, could it be work well?..

You’ll have to try it. I don’t have the printer hardware to test what you’re doing.

---

<div class="post-metadata">

**Author:** ![LangdonS](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@LangdonS](https://discourse.processing.org/u/LangdonS)\
**Post date:** [May 24, 2024, 3:35pm UTC](https://discourse.processing.org/t/print-jpg-file-from-processing-printer/44461/11 "2024-05-24T15:35:54Z")

</div>

Linux often works without a driver.

Mac drivers are small because most of the dependencies (like CUPS) are already installed.

Update your system and reinstall the driver if needed.
