I'm trying to print all pdfs in current dir. When I call this bash script in cmd ( singlepdf.sh ): '"C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe"' /t Gemeinde_348_BioID_842_alt.pdf everything's working fine. When calling multiplepdfs.sh with this content:
declare -a pdfs=(*.pdf) for pdf in $; do echo -e "\nprinting **$pdf** with AcroRd32.exe. \n" '"C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe"' /t $pdf sleep 3 done
The echo shows that files are addressed correctly in the loop - but then I get the error "C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe": No such file or directory Can someone help out with this issue? Edit: BTW, I have msys mingw installed
asked Oct 1, 2013 at 19:59 2,832 6 6 gold badges 34 34 silver badges 49 49 bronze badgesI know this is and old question, but i was faced with the same problem recently and none of the answers worked for me:
It's a simple exe that you call with the filename and it prints to the default printer (or one that you specify). From the site:
PDFtoPrinter is a program for printing PDF files from the Windows command line. The program is designed generally for the Windows command line and also for use with the vDos DOS emulator.
To print a PDF file to the default Windows printer, use this command:
PDFtoPrinter.exe filename.pdf
To print to a specific printer, add the name of the printer in quotation marks:
PDFtoPrinter.exe filename.pdf "Name of Printer"
If you want to print to a network printer, use the name that appears in Windows print dialogs, like this (and be careful to note the two backslashes at the start of the name and the single backslash after the servername):
PDFtoPrinter.exe filename.pdf "\\SERVER\PrinterName"
answered Dec 27, 2017 at 15:30
1,462 1 1 gold badge 19 19 silver badges 24 24 bronze badges
I'm the author of PDFtoPrinter.exe. It's written in AutoIt, and some virus scanners flag any AutoIt executable as a trojan, because script-kiddies use AutoIt. Try submitting it to VirusTotal.com or viruscan.jotti.org for a more up-to-date report.
Commented May 7, 2019 at 15:21@ThorstenSchöning - Yes, PDFtoPrinter uses AutoIt's "RunWait" to run the embedded PDF-Xchange Viewer. You're welcome to get in touch with me at the address at the foot of the page about this program; I'd rather clean up the absurd mess of AutoIt code before going public with it, but if you're willing to look at it privately, please get in touch. Meanwhile, I've posted a command-line-interface version named PDFtoPrinterCLI.exe (same site) which you can try. I have no idea whether it will help; please let me know.
Commented Jul 8, 2020 at 18:38@ThorstenSchöning - also look at the debug option on my web page. If you use this, it shows how to run the print command, and you may not need my program at all.
Commented Jul 8, 2020 at 21:50The original link at columbia.edu is now a 404, but there's a copy of the exe within this C# wrapper: github.com/svishnevsky/PDFtoPrinter
Commented Nov 20, 2023 at 11:39 Updated the link in answer Commented Nov 24, 2023 at 18:09I had two problems with using Acrobat Reader for this task.
I stumbled across this blog, that suggests using Foxit Reader. Foxit Reader is free, the API is almost identical to Acrobat Reader, but crucially is documented and does not load the GUI for print jobs.
A word of warning, don't just click through the install process without paying attention, it tries to install unrelated software as well. Why are software vendors still doing this.
answered Mar 20, 2014 at 7:38 6,426 4 4 gold badges 42 42 silver badges 71 71 bronze badgesI could not get Foxit Reader (v7.0.6) to print silently in the background. It opens a minimized version of the GUI and does not return control until it is manually closed :( So I ended up using SumatraPDF, which has the command line switches -print-to-default (or -print-to myprinter) and -silent that allows for completely silent background printing! And the return code is 0 if it succeeds and 1 if it fails. Ref: http://github.com/sumatrapdfreader/sumatrapdf/wiki/Command-line-arguments
Commented Dec 5, 2014 at 14:59In addition to the issue outlined above in 7.06 and below, the switches have changed. Formerly, there was only /t for printing silently, and the printer name was optional. If the printer name was omitted, Foxit would send the file to the default printer. Now /p has been designated to send to the default printer, and /t requires there be a printer named.
Commented May 26, 2015 at 14:50SumatraPDF is trash if you want to print a landscape PDF on landscape media! Instead it decides to auto-rotate your PDF.
Commented Jul 31, 2015 at 18:39 The issue with v7 has been confirmed as a bug forums.foxitsoftware.com/forum/… Commented Dec 12, 2015 at 22:39Depending what you're doing, Adobe Reader License doesn't permit using it for headless or printing or printing from a server. And SumatraPDF is slow if you're doing a lot of printing in a batch and you need speed. From the SumatraPDF forum: "In general Sumatra is not great at printing so I wouldn't recommend using it in [high volume scenarios]. Currently we print by generating a bitmap for each page and sending those bitmaps to a printer. Adobe is smarter."
Commented May 1, 2017 at 19:30Looks like you are missing the printer name, driver, and port - in that order. Your final command should resemble:
AcroRd32.exe /t"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" /t "C:\Folder\File.pdf" "Brother MFC-7820N USB Printer" "Brother MFC-7820N USB Printer" "IP_192.168.10.110"
Note: To find the printer information, right click your printer and choose properties. In my case shown above, the printer name and driver name matched - but your information may differ.
answered Oct 30, 2013 at 23:31 191 2 2 bronze badgesThe error message is telling you.
"C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe" /t "$pdf"
When you enclose the string in single-quotes, this makes everything inside a valid string, including the " chars. By removing the single-quotes, the shell will process the dbl-quotes as string "wrappers".
I would also wrap the filename variable in dbl-quotes so you can easily process files with spaces in their names, i.e.
"C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe" /t "$pdf"
answered Oct 1, 2013 at 20:38
37k 7 7 gold badges 85 85 silver badges 94 94 bronze badges
I tried every type and variation of qoutes and the one in the op was the only one working outside the loop.. With single quotes adobe opens the file but strangely gives message along the lines "Error when opening file.." and does not send file to printer..
Commented Oct 2, 2013 at 7:16Thanks for the edit, I was just posting to ask how you can run bash on Windows. The best I can recommend is to turn add set -vx near the top of your script so you can see the what is being executed, and how any what values are being used for variables. Also, you might try ANSI strings, with $"c:\program . " or $'c:\. ' instead of just plain dbl or single quotes. Also add to your post the output of bash --version . Good luck.
Commented Oct 2, 2013 at 9:05 or try having your multipdf script call singlepdf with the file argument? Good luck. Commented Oct 2, 2013 at 9:50First response - wanted to finally give back to a helpful community.
Wanted to add this to the responses for people still looking for simple a solution. I'm using a free product by Foxit Software - FoxItReader.
Here is the link to the version that works with the silent print - newer versions the silent print feature is still not working. FoxitReader623.815_Setup
FOR %%f IN (*.pdf) DO ("C:\Program Files (x86)\Foxit Software\Foxit Reader\FoxitReader.exe" /t %%f "SPST-SMPICK" %%f & del %%f)
I simply created a command to loop through the directory and for each pdf file (FOR %%f IN *.pdf) open the reader silently (/t) get the next PDF (%%f) and send it to the print queue (SPST-SMPICK), then delete each PDF after I send it to the print queue (del%%f). Shashank showed an example of moving the files to another directory if that what you need to do
FOR %%X in ("%dir1%*.pdf") DO (move "%%~dpnX.pdf" p/)
answered Oct 18, 2017 at 12:46
Michael Gargan Michael Gargan
39 3 3 bronze badges
The following batch script should achieve what you want. While it will leave an instance of Acrobat Reader running when finished, this will not cause any problems the next time this script is run.
@echo off for %%f in (*.pdf) do ( echo Printing %cd%\%%f with Adobe Acrobat Reader. start /b "Printing %%f" "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /p /h "%cd%\%%f" )
While you could separately kill the Acrobat Reader process afterwards there is the possibility this will close other PDF documents that are open that you didn't want closed.
answered Mar 25, 2021 at 14:04 richhallstoke richhallstoke 1,591 2 2 gold badges 16 16 silver badges 31 31 bronze badges Using options /p and /h does the trick nicely--if using Acrobat to print. Commented Oct 21, 2022 at 1:25I had the similar problem with printing multiple PDF files in a row and found only workaround by using 2Printer software. Command line example to print PDF files:
2Printer.exe -s "C:\In\*.PDF" -prn "HP LasetJet 1100"
It is free for non-commercial use at http://doc2prn.com/
answered Aug 14, 2014 at 20:34 37 1 1 bronze badgeThe free version adds a report page to each page so is kind of useless for me as 50% of my printing would be a waste.
Commented Dec 5, 2015 at 3:52As long as it works, we can buy it. But please make sure after buying it works. Can you please confirm its reliable and standard. we have to use it in Enterprises.
– user285594 Commented Feb 19, 2016 at 9:37Using Acrobat reader is not a good solution, especially command line attributes are not documented. Additionally Acrobat reader's window stays open after printing process. PDF files are well known by printer drivers, so you may find better tools, like 2Printer.exe or RawFilePrinter.exe. In my opinion RawFilePrinter has better support and clear licencing process (you pay donation once and you can redistribute RawFilePrinter in many project you like - even new versions work with previously purchased license)
RawFilePrinter.exe -p "c:\Users\Me\Desktop\mypdffile.pdf" "Canon Printer" IF %ERRORLEVEL% 1( echo "Error!" )
2,090 1 1 gold badge 15 15 silver badges 24 24 bronze badges
answered Jun 15, 2016 at 8:10
470 1 1 gold badge 8 8 silver badges 16 16 bronze badges
Here is another solution:
2) Create a class library project and unzip the SumatraPDF.exe to the project directory root and unblock it.
3) Inside the project Properties, go to the Resoruces tab and add the exe as a file.
4) Add the following class to your library:
public class SumatraWrapper : IDisposable < private readonly FileInfo _tempFileForExe = null; private readonly FileInfo _exe = null; public SumatraWrapper() < _exe = ExtractExe(); >public SumatraWrapper(FileInfo tempFileForExe) : this() < _tempFileForExe = tempFileForExe ?? throw new ArgumentNullException(nameof(tempFileForExe)); >private FileInfo ExtractExe() < string tempfile = _tempFileForExe != null ? _tempFileForExe.FullName : Path.GetTempFileName() + ".exe"; FileInfo exe = new FileInfo(tempfile); byte[] bytes = Properties.Resources.SumatraPDF; using (FileStream fs = exe.OpenWrite()) < fs.Write(bytes, 0, bytes.Length); >return exe; > public bool Print(FileInfo file, string printerName) < string arguments = $"-print-to \"\" \"\""; ProcessStartInfo processStartInfo = new ProcessStartInfo(_exe.FullName, arguments) < CreateNoWindow = true >; using (Process process = Process.Start(processStartInfo)) < process.WaitForExit(); return process.ExitCode == 0; >> #region IDisposable Support private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) < if (!disposedValue) < if (disposing) < // TODO: dispose managed state (managed objects). >// TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. try < File.Delete(_exe.FullName); >catch < >disposedValue = true; > > // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. // ~PdfToPrinterWrapper() < // // Do not change this code. Put cleanup code in Dispose(bool disposing) above. // Dispose(false); // >// This code added to correctly implement the disposable pattern. public void Dispose() < // Do not change this code. Put cleanup code in Dispose(bool disposing) above. Dispose(true); // TODO: uncomment the following line if the finalizer is overridden above. // GC.SuppressFinalize(this); >#endregion >
5) Enjoy printing pdf files from your code.
FileInfo file = new FileInfo(@"c:\Sandbox\dummy file.pdf"); SumatraWrapper pdfToPrinter = new SumatraWrapper(); pdfToPrinter.Print(file, "My Printer");