[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

print pdf silently

Posted on 2011-10-20
18
Medium Priority
?
996 Views
Last Modified: 2012-06-27
I wish to print pdf files from my program in a silent fashion without opening Acrobat or
a printer dialog box.  I have tried a product called ppdf, but the Acrobat window still opens.
I have my old versions of Acrobat 5.0 and 3.0 besides my current 9.0 version.  Nothing in the knowledgebase seems useful.  Essentially I need a command line method of printing.
0
Comment
Question by:beach3961
  • 10
  • 5
  • 2
  • +1
18 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 37009438



If you use java then
Use com.lowagie.tools.Executable.printDocumentSilent(fileName);
within iText package
http://itextpdf.com/

It sghould print PDF file silently.


0
 
LVL 47

Expert Comment

by:for_yan
ID: 37009443
Other suggestions which I saw where to print through ghostscript and xpdf
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37009693
No this actually does not work, requires acrord32, so doesn't look it is something usable:
com.lowagie.tools.Executable.printDocumentSilent(fileName);

However what worked for me was java application called PDFBox:
I dwonloaded pdfbox-app-1.6.0.jar  from here:
http://www.apache.org/dyn/closer.cgi/pdfbox/1.6.0/pdfbox-app-1.6.0.jar

and at the dos command prompt :

C:\pdfbox>java -jar pdfbox-app-1.6.0.jar PrintPDF -silentPrint test.pdf

Oct 21, 2011 4:28:01 PM org.apache.pdfbox.util.PDFStreamEngine processOperator
INFO: unsupported/disabled operation: i
Oct 21, 2011 4:28:01 PM org.apache.pdfbox.util.PDFStreamEngine processOperator
INFO: unsupported/disabled operation: i

Open in new window


it nicely and without opening any windows printed for me pdf file
Don't know if it would do it on all printers and perhaps there may be problems with more
sophisticated PDFs (mine was rather simple) but on my default  HP LaserJet 4050 TN printer it had no problems at all.
and I have java version 1.6.0_19
(if you don't have it, you can install it from here
http://javadl.sun.com/webapps/download/AutoDL?BundleId=57240)

 





0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 47

Expert Comment

by:for_yan
ID: 37009704

and this is the whole article about printing PDF silently (maybe you'll find something better there):
https://vineetreynolds.wordpress.com/2005/12/12/silent-print-a-pdf-print-pdf-programmatically/
0
 
LVL 81

Expert Comment

by:arnold
ID: 37010192
You did not specify which OS you have,
http://orion.math.iastate.edu/burkardt/g_src/pdf2ps/pdf2ps.html requires ghostscript which for_yan referenced.
The PS output is then sent to the printer which you would need to have.

You have to know what format the printer supports and then look at a pdf to that format conversion option.
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 2000 total points
ID: 37014509
Do you have the Print option on right click within explorer?

Unless I am missing something in this Q, a PDF can be printed with that, or rather the code that the right click runs, i.e. along these lines;

"C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe" /p /h "%1"

Where %1 is the path and filename to the pdf to print

Obviously you can code the filename in directly or use other batch commands as needed to get it.

Same goes for the Acrobat file, e.g. the batch below searches the program files dir to look for AcroR32 and tells you if not found:


Steve


@echo off

set Acro=
for /f "delims=" %%A in ('dir "%programfiles%\adobe\acrord32.exe" /s /b 2^>NUL') do set Acro=%%A
if "%Acro%"=="" for /f "delims=" %%A in ('dir "%programfiles(x86)%\adobe\acrord32.exe"/s /b 2^>NUL') do set Acro=%%A

if "%Acro%"=="" (
  echo Unable to find Acrobat Reader
  pause
  exit /b
)

if "%~1"=="" (
  cls
  echo Print one or multiple PDF from the command line or dragged onto this as shortcut
  echo Steve Knight [dragon-it] EE question # 27407319
  echo.
  echo No PDF has been specified on the command line
  echo.
  echo Usage: %~nx0 "somefile.pdf" "anotherfile.pdf" etc.
  pause
  exit /b
)

:loop

  REM Shift through each PDF file on command line and print each one by one using found AcroRd32.exe
  echo Printing "%~1"
  START "Printing %~1" "%Acro%" /p /h "%~1"
  shift
if not "%~1"=="" goto loop

echo All completed.  Closing Acrobat reader after short pause
ping 127.0.0.1 -n 5
taskkill /FI "IMAGENAME eq acrord32.exe"
exit /b

Open in new window

0
 

Author Comment

by:beach3961
ID: 37018045
I just tried this in a batch file and it works, therefore I am confident I can integrate it into my program.
I was hoping to avoid having the Acrobat window open but if that is not possible, I can live with it.
Thank you.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37018240
Try it with java like in http://#37009693  - it prints silently without opening the window.

I went through that option when I was investigationg it of course:
AcroRd32.exe /p /h filename
but you  were stressing silently - and it was always opening that acrobat window for me.

Don't know, maybe some sophisticated pdf will not work but try it with your example.
It is really easy to install - and nowadays all folks have java on their PCs.
0
 

Author Comment

by:beach3961
ID: 37018376
I hadn't tried the Java beause I didn't understand it and I am not doing this from a web page.
But I just tried it from the command line and it did everything I needed.
I am going to try it calling it from my program.  My only concern is the warning messages
about "Changing fonts" from the application.  I need to research and see if there is a way to suppress
warning messages or how those warnings will display when the process is ececuted from my program.
Thank you,
Alan
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37018509
Sorry, I didn't understadn form your post, so you did try java method or you were talking about acrobat method?

This java method has nothing to do with any web - it is just form comman line.

So, please explain - were the font message s from java or from the "arboat based " method.
If they were from java - post them we'll think about it.
0
 

Author Comment

by:beach3961
ID: 37018603
With the java method, it outputs messages relating to the processing.  Attached is a jpg of the stream messages I got from a test. java messages
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37019246
One simple way to try is to try to redirect them to NUL


java -jar pdfbox... PrintPdf -silentPrint log.pdf > NUL

I hope they should disappear this way.

another option to try:

java -jar pdfbox... PrintPdf -silentPrint log.pdf  2> NUL

because 2> redirects the error stream



I didn't find how to suppress these warinings altogether, howvere one my guess is that they may be java version dependent
check
java -version
 maybe newer java which you can easily install will not have that.
I think I used to see such waernings a fww years ago when I had java 1.4 or something. Now that I have java 1.6
I dont recall seeing them (though t may of course depend on the task) .

If not let me know what version of java do you have



0
 

Author Comment

by:beach3961
ID: 37019814
2> NULL worked to supress the messages
I have java version 1.6.0_25-b06
Thank you
Alan
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37019872
1.6.0_25 is OK, but if NULL worked that is fine.
Only check if you have different tuypes of PDF's say with pictures, etc
check if they print it OK. After all this is quite different printing not through
Acrobat and not written by Adbe; I would not be surprised if in some special
cases they might do something not exactly as it should be done.
But for motsly conventioanl pdf's I expect it shoul be doing a normal job.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 37019934
BTW using NULL will create a file called NULL.  NUL is what you want :-) or both together

>NUL 2>&1

to redirect std ouput to nul and std error output to stream 1 (std out) and into nul too!


Thanks for the points / answer.  Will give java method a go myself for one I need to look at' have always just called acrobat reader in the past...
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37019948
Yes, it is true - that's what it is called in woindows NUL (for some reason without second L); this analog of /dev/null in Unix.
0
 

Author Comment

by:beach3961
ID: 37027925
You said there might be a problems printing images.  Definitely.
The java method does not handle images at all.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37028090
well, I was expecting it will not handle everything as Adobe
Myabe there is some information on that PdfBox project  site
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Make the most of your online learning experience.
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question