Try this one from Printing.java:

    private static void printWithPaper(PDDocument document)
            throws IOException, PrinterException
    {
        PrinterJob job = PrinterJob.getPrinterJob();
        job.setPageable(new PDFPageable(document));

        // define custom paper
        Paper paper = new Paper();
        paper.setSize(306, 396); // 1/72 inch
        paper.setImageableArea(0, 0, paper.getWidth(), paper.getHeight()); // no margins

        // custom page format
        PageFormat pageFormat = new PageFormat();
        pageFormat.setPaper(paper);

        // override the page format
        Book book = new Book();
        // append all pages
        book.append(new PDFPrintable(document), pageFormat, document.getNumberOfPages());
        job.setPageable(book);

        job.print();
    }

Tilman

Am 12.12.2018 um 21:28 schrieb STEPHEN LANNING:
Hello, may I ask for some help?

I am having a problem using pdfbox to print PDFs stored for a large
printer onto letter size

When I print it the same way I print normal PDFs it prints just the upper
left edge of the PDF image covering the entire 8X11 page.
On the next page there is a message PCL XL error Warning: illegalMedia
Size.

Java code
PDDocument document = PDDocument.load(new File(s_pathAndFileName));
PrinterJob job = PrinterJob.getPrinterJob();
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(Sides.DUPLEX);
job.setPageable(new PDFPageable(document));
job.setPrintService(myPrintService);
job.print(pras);

I tried using scaling and the image prints portrait(should be landscape)
and the entire image prints in the middle of page making it to small to
read. Two and four inch boarders of white space.
I tried scaling.SCALE_TO_FIT and scaling.SHRINK_TO_FIT. Also attributes
pras.add(MediaSizeName.NA_LETTER) or pras.add(MediaSizeName.ISO_A4). None
had a positive effect.

Java code
PDDocument document = PDDocument.load(new File(s_pathAndFileName));
PDFPrintable printable = new PDFPrintable(document, Scaling.SCALE_TO_FIT,
Orient);
PrinterJob job = PrinterJob.getPrinterJob();
job.setPageable(new PDFPageable(document);
job.setPrintService(myPrintService);
job.setPrintable(printable);

This apprently has to do with how the PDF was saved after it was set to
print on a very large printer for engineering drawing specs.

Is there a solution that I have not gleaned from your web-sites?

Thank you for any help.

                 Steve Lanning
   Programmer NHBB Astro Division
   Phone: (603)524-0004  Ext: 6256




========================= NMB (USA) EMAIL NOTICE
============================
The information contained herein may be confidential and proprietary and
is intended only for
the use of the addressee. Any unauthorized dissemination or disclosure of
this communication
is strictly prohibited.  If you have received this communication in error,
please notify the sender
immediately. The information herein is not warranted to be free of virus
or any other defect.
==============================================================================



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to