title: printing in java through barcode printer fit to scale
body: <p>I am trying to print barcode image files using java. I have Label Writer 450 Turbo. The label dimension is 2" X 0.75" inches, When I print the image from Photoshop with scale to fit option every thing works fine. </p>
  
  <p><a href="https://i.stack.imgur.com/K71NM.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K71NM.jpg" alt="The barcode example"></a></p>
  
  <p>But with java code it does not scale the image in right way, so the barcode reader cannot read it anymore.</p>
  
  <pre><code>public class print {
  
      public static void main(String[] str) {
          // Input the file
          FileInputStream textStream = null;
          try {
              textStream = new FileInputStream("barcode.jpg");
          } catch (FileNotFoundException exp) {
              return;
          }
  
          DocFlavor myFormat = DocFlavor.INPUT_STREAM.JPEG;
          PageFormat format = new PageFormat();
          format.setOrientation(PageFormat.PORTRAIT);
  
          Doc myDoc = new SimpleDoc(textStream, myFormat, null);
          // Build a set of attributes
          PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
          // aset.add(new Copies(2));
          aset.add(new MediaPrintableArea(0, 0, 0.75f, 2f,
                  MediaPrintableArea.INCH));
          aset.add(PrintQuality.HIGH);
  
          aset.add(new PrinterResolution(300, 600, PrinterResolution.DPI));
          aset.add(OrientationRequested.LANDSCAPE);
  
          PrintService[] services = PrintServiceLookup.lookupPrintServices(
                  myFormat, null);
  
          if (services.length &gt; 0) {
              DocPrintJob job = services[5].createPrintJob();
  
              for (Attribute temp : services[5].getAttributes().toArray())
                  System.out.println(temp.getName());
  
              try {
                  job.print(myDoc, aset);
              } catch (PrintException pe) {
  
              }
          }
      }
  }
  </code></pre>
  
  <p>The barcode generated using krysalis barcode4j using the following settings </p>
  
  <pre><code>resolution -&gt; 600
  line height -&gt; 15.35mm 
  </code></pre>
  
  <p><strong>Edit One:</strong>  here is example of the two printed labels one using Photoshop with scale to fit option, and the other using java code</p>
  
  <p><a href="https://i.stack.imgur.com/e2Inc.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e2Inc.jpg" alt="enter image description here"></a> </p>