通过与苏门答腊PDF命令行批量打印PDF [英] Batch print pdf through commandline with sumatra pdf
问题描述
由于Adobe发布了Adobe Reader中将新的更新(11.09在2014年9月16日),我们通过命令行遇到打印PDF文件的问题。
since Adobe released a new Update for the Adobe Reader (11.09 on 16.09.2014), we encountered an problem with printing pdf files through the command line.
:job
@for /F "tokens=1,* delims= " %%p in ('dir /b/a-d /s "Y:\*.pdf"') do (
echo Printing file: "%%p" on %date%
::prints the pdf document with adobe reader
"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" /p /h "%%p"
::move file to destination
echo wait 10 seconds
::wait 10 seconds then continue
ping 127.0.0.1 -n 10 > nul
echo move file: "%%p" to "C:\PDF"
::move file to destination
move "%%p" "C:\PDF"
echo moved successfully!
echo proceeding next file
)
echo waiting for files to print...
echo wait 7 seconds
ping 127.0.0.1 -n 7 > nul
::clear console
cls
::repeat with job (endless loop)
goto job
脚本工作作为期待了。由于更新脚本常挂或大型缓慢。
剧本得到了或多或少的也没用。
The script was working as expecting before. Since the update the script often hangs or is mega slow. the script got more or less useless.
原因土坯读者可能不是最小的,我们也可以考虑使用轻量级的像可选择性或sumatrapdf福昕阅读器。这将是一个伟大的一点开始使用这些替代品之一。
Cause the adobe reader is probably not the smallest, we also considered to use an lightweight alternativ like sumatrapdf or foxitreader. This would be a great point to start using one of those alternatives.
所以,我想与sumatrapdf尝试。
他们的文档说: http://blog.kowalczyk.info/software/sumatrapdf/manual.html
So I wanted to try it with sumatrapdf. Their documentation said:http://blog.kowalczyk.info/software/sumatrapdf/manual.html
=> -print到默认$ file.pdf打印在默认打印机PDF文件
=> -print-to-default $file.pdf prints a PDF file on a default printer
:job
@for /F "tokens=1,* delims= " %%p in ('dir /b/a-d /s "Y:\*.pdf"') do (
call "C:\Program Files (x86)\SumatraPDF\SumatraPDF.exe" -print-to-default "%%p"
start "" "C:\Program Files (x86)\SumatraPDF\SumatraPDF.exe" -print-to-default "%%p"
"C:\Program Files (x86)\SumatraPDF\SumatraPDF.exe" -print-to-default "%%p"
... the rest
但没有任何工程。如果还尝试:
C:\\ Program Files文件(x86)的\\ SumatraPDF \\ SumatraPDF.exe -print到默认的%% P呼叫,启动,等等...
But nothing works. If have also tried: "C:\Program Files (x86)\SumatraPDF\SumatraPDF.exe -print-to-default" "%%p" for call,start, and so on...
请问anyboy知道如何使sumatrapdf印刷工作?我也不会通过将其与福昕阅读器的工作进行规避。
Does anyboy know how to make the printing work with sumatrapdf? I also wouldn't be averse by making it work with foxit reader.
这将是一个很高兴得到一些建议:)
也许有人有类似的问题需要解决。
It would be a pleasure to get some advices :) Maybe someone got a similar problem to solve.
推荐答案
据<一个href=\"http://help.adobe.com/livedocs/acrobat_sdk/10/Acrobat10_HTMLHelp/DevFAQ_UnderstandingSDK.22.31.html\"相对=nofollow>我如何使用与Acrobat和Adobe Reader Windows命令行(这是安装Adobe Acrobat /阅读器10,而不是十一)用于与显示一个对话框打印命令?
Adobe Reader
According to How do I use the Windows command line with Acrobat and Adobe Reader? (which is for Adobe Acrobat/Reader 10 and not XI) the command to use for printing with displaying a dialog box is:
start "Print PDF" /wait "%ProgramFiles(x86)%\Adobe\Reader 11.0\Reader\AcroRd32.exe" /p "%%p"
我想,这是没有用的使用选项 / H
与最小化窗口启动Adobe阅读器是否应显示在打印对话框。
I think, it is not useful to use option /h
to start Adobe Reader with a minimized window if the print dialog box should be displayed.
要打印到特定打印机在命令行中使用会是这样
To print to a specific printer the command line to use would be something like
start "Print PDF" /wait /min "%ProgramFiles(x86)%\Adobe\Reader 11.0\Reader\AcroRd32.exe" /t "%%p" "printername" "drivername" "portname"
/等待
停止批处理作业的执行,直到ADOBE READER自行终止。而选项 /分钟
在最小化的窗口执行GUI应用程序,如果应用程序不覆盖它的结果和显示器仍然窗口最大化或恢复模式。
/wait
halts execution of batch job until Adobe Reader terminated itself. And option /min
results in executing the GUI application with a minimized window if the application does not override it and displays nevertheless the window maximized or in restored mode.
我不知道,如果 SumatraPDF手册是高达最新因为它连接在底部到wiki文档PDF苏门答腊与命令行参数一>页。这个Wiki页面最近更新,包含不同的信息,关于向打印选项。
I'm not sure if SumatraPDF Manual is up-to-date because it links at bottom to a Wiki documentation for Sumatra PDF with Command Line Arguments page. This Wiki page was recently updated and contains different information regarding to printing options.
- -print到默认搜索
打印此命令行到系统默认的打印机上显示所有文件。打印后,SumatraPDF立即退出(检查错误code失败)。
所以应该可以打印即使SumatraPDF的一个呼叫命令行上指定多个文件这将使批处理文件更高效
So it should be possible to print even multiple files specified on command line with one call of SumatraPDF which would make your batch file more efficient.
由于我没有安装SumatraPDF,我建议首先尝试只用3行的批处理文件
As I have not installed SumatraPDF, I suggest to try first a batch file with just the 3 lines
"%ProgramFiles(x86)%\SumatraPDF\SumatraPDF.exe" -print-to-default "Full Path and Name of a PDF file"
echo Exit code of SumatraPDF is: %ERRORLEVEL%
pause
这是批处理文件的输出接下来看看。则显示错误或预期打印PDF文件?
Next look on output of batch file. Is an error displayed or is the PDF file printed as expected?
时在控制台窗口中的第二行输出打印完成之前?
Is the second line output in console window before printing finished?
如果是这种情况,SumatraPDF开始作为一个单独的过程,并退出code评价是不是真的可能的。否则,你已经使用命令。
If this is the case, SumatraPDF is started as a separate process and exit code evaluation is not really possible. Otherwise you have already the command to use.
但如果SumatraPDF开始作为一个独立的(GUI)的过程,它是最有可能需要使用命令启动
与选项 /等待
或许也是 /分钟
如上图所示为安装Adobe Reader。
But if SumatraPDF is started as a separate (GUI) process, it is most likely necessary to use command start
with option /wait
and perhaps also /min
as shown above for Adobe Reader.
注:没有关闭@echo
在小批量的文件进行检测,也看到在批处理文件的执行命令的顶部
Note: There is no @echo off
at top of the small batch file for testing to see also the commands on execution of the batch file.
找有东西,你指定空格字符作为分隔符错误这是不利于一个文件路径/名空间内。另外,空格字符是默认命令的分隔符的
,因此没有必要明确将其定义为分隔符,如果是真的想。
Looking on your code for the FOR
loop there is something wrong as you specify the space character as delimiter which is not good for file paths/names with a space inside. Also the space character is by default a delimiter for command FOR
and therefore it is not necessary to explicit define it as delimiter if that is really wanted.
因此,我建议使用
@for /F "delims=" %%p in ('dir "Y:\*.pdf" /b /a-d /s' 2^>nul) do (
"%ProgramFiles(x86)%\SumatraPDF\SumatraPDF.exe" -print-to-default "%%p"
)
使用delims =
分隔符列表更改为仅换行。 %% P
也因此总是一个文件的完整路径和名称,即使通过命令 DIR $一行输出存在1个或多个空格C $ C>。
With "delims="
the delimiters list is changed to newline only. %%p
has therefore always the entire path and name of a file even if 1 or more spaces exist on a line output by command dir
.
2 ^&GT; NUL
燮presses命令的错误信息 DIR
如果没有PDF文件能在所有对整个驱动器Y为发现:通过重定向错误信息到设备NUL
2^>nul
suppresses the error message of command dir
if no PDF file could be found at all on entire drive Y: by redirecting the error message to device NUL.
这篇关于通过与苏门答腊PDF命令行批量打印PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!