title: Page formating not working for printing a page using Java in Netbeans
body: <p>I am trying to print a page with custom size. But its not working.
  I have made variable for width and height I want my page to be.</p>
  <p>See my code ones and suggest some changes</p>
  <pre><code>    PrinterJob job = PrinterJob.getPrinterJob();
      job.setJobName(&quot;Print Data&quot;);
          
      job.setPrintable(new Printable(){
          public int print(Graphics pg,PageFormat pf, int pageNum){
              //Paper paper = pf.getPaper();
              Paper paper = new Paper();
              double width = 8d * 22d;
              double height = 4d * 22d;
              double margin = 0.2d * 22d;
              paper.setSize(width, height);
              paper.setImageableArea(
                      margin,
                      margin,
                      width - (margin * 2),
                      height - (margin * 2));
              job.setPrintable(this, pf);
              
              if(pageNum &gt; 0){
                  return Printable.NO_SUCH_PAGE;
              }
              
              Graphics2D g2 = (Graphics2D)pg;
  
              g2.translate(pf.getImageableX(), pf.getImageableY());
              
              System.out.println(&quot;width1 = &quot; + pf.getWidth());
              System.out.println(&quot;height1 = &quot; + pf.getHeight());
  
              g2.setColor(Color.BLACK);
              g2.draw(new Rectangle2D.Double(0, 0, pf.getWidth(), pf.getHeight()));
  
              
              jPanel3.printAll(g2);
       
              return Printable.PAGE_EXISTS; 
          }
      });
      
      System.out.println(&quot;1&quot;);
      boolean ok = job.printDialog();
      
      if(ok){
          try{
              System.out.println(&quot;2&quot;);
              job.print();
              System.out.println(&quot;3&quot;);
          }
          catch (PrinterException ex){
              ex.printStackTrace();
          }
      }
  </code></pre>
  <p>I am stuck at this problem. Whatever size I set. I get print in ISO A4 size. I think their's some mistake with my code.</p>