pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonathan Ominsky <jomin...@opentext.com>
Subject Issue printing with shrink to fit
Date Thu, 04 May 2017 17:04:43 GMT
I have a PDF in A4 page format that I'm trying to print to a printer that only has Letter size
paper. In working through other issues, I was using PDFPageable specifying a dpi. However,
I noticed that class uses the original size of the document and I need to be able to shrink
the document to fit the printer if necessary. I wasn't sure how to combine both the PDFPageable
and PDFPrintable, so I basically copied the PDFPageable class and created a PDFPageableWithScaling
class. In the constructor, I pass in Scaling.SHRINK_TO_FIT and then pass this into the constructor
of PDFPrintable. However, the document still prints A4 on my Letter paper. I'm relatively
new to all of this, so I'm sure I'm missing something. Any help is appreciated.

Calling code:

    String sourcePDF = "C:\\temp\\CPTest\\CMC-MBOM-001_PATTARO Roberto.pdf";
    PrinterJob job = PrinterJob.getPrinterJob();
    try (PDDocument document = PDDocument.load(new File(sourcePDF))) {
      job.setPageable(new PDFPageableWithScaling(document, Orientation.AUTO, false, 600, Scaling.SHRINK_TO_FIT));
      job.print();
    } catch (IOException | PrinterException e) {
      throw new RuntumeException("Unable to print file " + sourcePDF + ".", e);
    }


The only code in PDFPageable that I changed was this:

  public Printable getPrintable(int i) {
    if (i >= getNumberOfPages()) {
      throw new IndexOutOfBoundsException(i + " >= " + getNumberOfPages());
    }
    return new PDFPrintable(document, scaling, showPageBorder, dpi);
  }

Original PDFPageable code:

  public Printable getPrintable(int i) {
    if (i >= getNumberOfPages()) {
      throw new IndexOutOfBoundsException(i + " >= " + getNumberOfPages());
    }
    return new PDFPrintable(document, Scaling.ACTUAL_SIZE, showPageBorder, dpi);
  }

I'm using pdfbox 2.0.1.

Jon

Jon Ominsky
Consultant Software Engineer, Life Sciences
OpenText | Enterprise Content Division
Mobile +1 610.322.0558
jominsky@opentext.com<mailto:jominsky@opentext.com>

[cid:image001.png@01D2C4D3.1D1848C0]<http://www.opentext.com/>


Mime
  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message