title: Java Print - How to set paper size and orientation attributes
body: <p>I need to print a PDF and configure the paper size and orientation.
  This is my code, but the attributes are not working.</p>
  
  <pre><code>private void doPrint(){
      try{
  
          PDDocument aImprimir = PDDocument.load(new File("./file.pdf")); //org.apache.pdfbox.pdmodel.PDDocument
          PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
          attributes.add(MediaSizeName.ISO_A8);
          attributes.add(OrientationRequested.PORTRAIT);
  
          PrintService myPrintService = PrintServiceLookup.lookupDefaultPrintService(); //javax.print.PrintService &amp; javax.print.PrintServiceLookup
  
          PrinterJob job = PrinterJob.getPrinterJob(); //java.awt.print.PrinterJob
  
          job.setPageable(new PDFPageable(aImprimir));
          job.setPrintService(myPrintService);
          job.print(attributes);
          aImprimir.close();
      }
      catch(DocumentException | PrinterException | IOException | NullPointerException e){
          System.out.println("Error" + e):
      }
  }
  </code></pre>