You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by STEPHEN LANNING <sl...@nhbb.com> on 2018/12/12 20:28:47 UTC

Printing PDF save for large printer - java

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.
==============================================================================

Re: Printing PDF save for large printer - java

Posted by Tilman Hausherr <TH...@t-online.de>.
Btw this is the developers mailing list, in the future (next question if 
there is one) please post to the users mailing list. Did you get this 
mailing list from a place where there was no link to the users mailing 
list and if yes, where?

Tilman



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org


Re: Printing PDF save for large printer - java

Posted by Tilman Hausherr <TH...@t-online.de>.
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: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org