You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Aaron Mulder <am...@gmail.com> on 2023/03/11 19:18:08 UTC

PrintPDF CLI with print options

Is there a way to use the PrintPDF command-line tool and force it to use
duplex and a specific paper tray?  These options are available via lpr (I'm
on a Mac).  I have been printing PDFs via lpr but there's a new printer and
maybe 5% of jobs fail to print (the printer says "cancelling job" in the
middle of the print and aborts) but those same PDFs print OK with the
PrintPDF CLI.  I just want to force the paper tray and duplex settings to
be sure it doesn't e.g. pick the wrong tray if the intended one is empty.

lpoptions below if it helps.

Thanks,
      Aaron

ColorModel/Color Mode: *Gray
cupsPrintQuality/Quality: *Normal
Duplex/2-Sided Printing: None *DuplexNoTumble DuplexTumble
PageSize/Media Size: 215x345mm 3x5 A4 A5 A6 Env10 EnvC5 EnvDL EnvMonarch
Executive FanFoldGermanLegal ISOB5 Legal *Letter Oficio Custom.WIDTHxHEIGHT
MediaType/MediaType: stationery stationery-lightweight
stationery-heavyweight envelope envelope-heavyweight envelope-lightweight
labels stationery-bond stationery-colored stationery-letterhead *any
InputSlot/Media Source: auto by-pass-tray tray-1 tray-2

Re: PrintPDF CLI with print options

Posted by Tilman Hausherr <TH...@t-online.de>.
2.0 version now available too

https://repository.apache.org/content/groups/snapshots/org/apache/pdfbox/pdfbox-app/2.0.29-SNAPSHOT/


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


Re: PrintPDF CLI with print options

Posted by Aaron Mulder <am...@gmail.com>.
That's great, thanks!

On a side note, the issue printing PDFs directly to the printer was with a
Brother printer.  For some fraction of PDFs, it just silently canceled the
job with no error message returned to the Mac that issued the job.  This
never used to happen with the HP it replaced.  It seems like I'm not the
only one with this kind of issue:

https://www.reddit.com/r/printers/comments/1039lny/brother_laser_printer_automatically_canceling_the/

The available firmware update didn't help.  I eventually returned the
printer since printing PDFs flawlessly is a key requirement for this
particular printer.

Aaron


On Sun, May 21, 2023 at 3:21 PM Tilman Hausherr <TH...@t-online.de>
wrote:

> I've implemented duplex, tray and media size for the 3.0 version (will
> do 2.0 at a later time), download the latest pdfbox-app at the bottom of
>
>
> https://repository.apache.org/content/groups/snapshots/org/apache/pdfbox/pdfbox-app/3.0.0-SNAPSHOT/
>
> and then enter
>
> java -jar pdfbox-app-3.0.0-XXXX.jar print listPrinters
>
> for the tray and media size capabilities. For duplex, use
> -duplex=duplex  or -duplex=tumble . Use
>
> java -jar pdfbox-app-3.0.0-XXXX.jar print
>
> to see all the options.
>
> Tilman
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>

Re: PrintPDF CLI with print options

Posted by Tilman Hausherr <TH...@t-online.de>.
I've implemented duplex, tray and media size for the 3.0 version (will 
do 2.0 at a later time), download the latest pdfbox-app at the bottom of

https://repository.apache.org/content/groups/snapshots/org/apache/pdfbox/pdfbox-app/3.0.0-SNAPSHOT/

and then enter

java -jar pdfbox-app-3.0.0-XXXX.jar print listPrinters

for the tray and media size capabilities. For duplex, use 
-duplex=duplex  or -duplex=tumble . Use

java -jar pdfbox-app-3.0.0-XXXX.jar print

to see all the options.

Tilman



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


Re: PrintPDF CLI with print options

Posted by Aaron Mulder <am...@gmail.com>.
OK, thanks.

Aaron

On Sat, Mar 11, 2023 at 2:32 PM Tilman Hausherr <TH...@t-online.de>
wrote:

> No it's not supported. Duplex could be implemented easily (it is
> implemented in PDFDebugger), but tray is a lot IMHO.
>
>
> https://docs.oracle.com/javase/7/docs/api/javax/print/attribute/standard/MediaTray.html
>
> the best would be you take the source code and adjust PrintPDF yourself.
> Here's the complete code segment in PDFDebugger:
>
> PrinterJob job = PrinterJob.getPrinterJob();
> job.setPageable(new PDFPageable(document, Orientation.AUTO, false,
> PrintDpiMenu.getDpiSelection()));
> PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
> PDViewerPreferences vp =
> document.getDocumentCatalog().getViewerPreferences();
> if (vp != null && vp.getDuplex() != null)
> {
>      String dp = vp.getDuplex();
>      if
> (PDViewerPreferences.DUPLEX.DuplexFlipLongEdge.toString().equals(dp))
>      {
>          pras.add(Sides.TWO_SIDED_LONG_EDGE);
>      }
>      else if
> (PDViewerPreferences.DUPLEX.DuplexFlipShortEdge.toString().equals(dp))
>      {
>          pras.add(Sides.TWO_SIDED_SHORT_EDGE);
>      }
>      else if (PDViewerPreferences.DUPLEX.Simplex.toString().equals(dp))
>      {
>          pras.add(Sides.ONE_SIDED);
>      }
> }
> //pras.add(new PrinterResolution(300, 300, PrinterResolution.DPI));
> if (job.printDialog(pras))
> {
>      setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
>      try
>      {
>          long t0 = System.nanoTime();
>          job.print(pras);
>          long t1 = System.nanoTime();
>          long ms = TimeUnit.MILLISECONDS.convert(t1 - t0,
> TimeUnit.NANOSECONDS);
>          LOG.info("Printed in " + ms + " ms");
>      }
>      finally
>      {
>          setCursor(Cursor.getDefaultCursor());
>      }
> }
>
>
> Tilman
>
> On 11.03.2023 20:18, Aaron Mulder wrote:
> > Is there a way to use the PrintPDF command-line tool and force it to use
> > duplex and a specific paper tray?  These options are available via lpr
> (I'm
> > on a Mac).  I have been printing PDFs via lpr but there's a new printer
> and
> > maybe 5% of jobs fail to print (the printer says "cancelling job" in the
> > middle of the print and aborts) but those same PDFs print OK with the
> > PrintPDF CLI.  I just want to force the paper tray and duplex settings to
> > be sure it doesn't e.g. pick the wrong tray if the intended one is empty.
> >
> > lpoptions below if it helps.
> >
> > Thanks,
> >        Aaron
> >
> > ColorModel/Color Mode: *Gray
> > cupsPrintQuality/Quality: *Normal
> > Duplex/2-Sided Printing: None *DuplexNoTumble DuplexTumble
> > PageSize/Media Size: 215x345mm 3x5 A4 A5 A6 Env10 EnvC5 EnvDL EnvMonarch
> > Executive FanFoldGermanLegal ISOB5 Legal *Letter Oficio
> Custom.WIDTHxHEIGHT
> > MediaType/MediaType: stationery stationery-lightweight
> > stationery-heavyweight envelope envelope-heavyweight envelope-lightweight
> > labels stationery-bond stationery-colored stationery-letterhead *any
> > InputSlot/Media Source: auto by-pass-tray tray-1 tray-2
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>

Re: PrintPDF CLI with print options

Posted by Tilman Hausherr <TH...@t-online.de>.
No it's not supported. Duplex could be implemented easily (it is 
implemented in PDFDebugger), but tray is a lot IMHO.

https://docs.oracle.com/javase/7/docs/api/javax/print/attribute/standard/MediaTray.html

the best would be you take the source code and adjust PrintPDF yourself. 
Here's the complete code segment in PDFDebugger:

PrinterJob job = PrinterJob.getPrinterJob();
job.setPageable(new PDFPageable(document, Orientation.AUTO, false, 
PrintDpiMenu.getDpiSelection()));
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
PDViewerPreferences vp = 
document.getDocumentCatalog().getViewerPreferences();
if (vp != null && vp.getDuplex() != null)
{
     String dp = vp.getDuplex();
     if 
(PDViewerPreferences.DUPLEX.DuplexFlipLongEdge.toString().equals(dp))
     {
         pras.add(Sides.TWO_SIDED_LONG_EDGE);
     }
     else if 
(PDViewerPreferences.DUPLEX.DuplexFlipShortEdge.toString().equals(dp))
     {
         pras.add(Sides.TWO_SIDED_SHORT_EDGE);
     }
     else if (PDViewerPreferences.DUPLEX.Simplex.toString().equals(dp))
     {
         pras.add(Sides.ONE_SIDED);
     }
}
//pras.add(new PrinterResolution(300, 300, PrinterResolution.DPI));
if (job.printDialog(pras))
{
     setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
     try
     {
         long t0 = System.nanoTime();
         job.print(pras);
         long t1 = System.nanoTime();
         long ms = TimeUnit.MILLISECONDS.convert(t1 - t0, 
TimeUnit.NANOSECONDS);
         LOG.info("Printed in " + ms + " ms");
     }
     finally
     {
         setCursor(Cursor.getDefaultCursor());
     }
}


Tilman

On 11.03.2023 20:18, Aaron Mulder wrote:
> Is there a way to use the PrintPDF command-line tool and force it to use
> duplex and a specific paper tray?  These options are available via lpr (I'm
> on a Mac).  I have been printing PDFs via lpr but there's a new printer and
> maybe 5% of jobs fail to print (the printer says "cancelling job" in the
> middle of the print and aborts) but those same PDFs print OK with the
> PrintPDF CLI.  I just want to force the paper tray and duplex settings to
> be sure it doesn't e.g. pick the wrong tray if the intended one is empty.
>
> lpoptions below if it helps.
>
> Thanks,
>        Aaron
>
> ColorModel/Color Mode: *Gray
> cupsPrintQuality/Quality: *Normal
> Duplex/2-Sided Printing: None *DuplexNoTumble DuplexTumble
> PageSize/Media Size: 215x345mm 3x5 A4 A5 A6 Env10 EnvC5 EnvDL EnvMonarch
> Executive FanFoldGermanLegal ISOB5 Legal *Letter Oficio Custom.WIDTHxHEIGHT
> MediaType/MediaType: stationery stationery-lightweight
> stationery-heavyweight envelope envelope-heavyweight envelope-lightweight
> labels stationery-bond stationery-colored stationery-letterhead *any
> InputSlot/Media Source: auto by-pass-tray tray-1 tray-2
>


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