问题
I am working in Windows platform.
It is possible to open a PDF file at a specific page:
AcroRd32.exe /A "page=3" "file.pdf"
Is there a similar solution for printing a specific page? Something like:
AcroRd32.exe /P "page=3" "file.pdf"
回答1:
Is there a similar solution for printing a specific page?
Something like:
AcroRd32.exe /P "page=3" "file.pdf"
No. There is no option to print a specific page.
What you could do is use the /p
option together with a VBS (or similar) script to manipulate the Print dialog and select the required page to print:
AcroRd32.exe /p pathname
— Executes Adobe Reader and displays the Print dialog box.
See below for a list of the possible command line options.
How Do I Use Command Lines with Acrobat and Adobe Reader on Windows?
These are unsupported command lines, but have worked for some developers.
There is no documentation for these commands other than what is listed below. You can display and print a PDF file with Acrobat and Adobe Reader from the command line.
NOTE: All examples below use Adobe Reader, but apply to Acrobat as well.
If you are using Acrobat, substitute Acrobat.exe in place of AcroRd32.exe on the command line.
AcroRd32.exe pathname
— Executes Adobe Reader and displays the file, whose full path must be provided.Other options for the command line are:
/n
Launches a separate instance of Acrobat or Adobe Reader, even if one is currently open.
/s
Opens Acrobat or Adobe Reader, suppressing the splash screen.
/o
Opens Acrobat or Adobe Reader, suppressing the open file dialog.
/h
Opens Acrobat or Adobe Reader in a minimized window.
AcroRd32.exe /p pathname
— Executes Adobe Reader and displays the Print dialog box.
AcroRd32.exe /t path "printername" "drivername" "portname"
— Initiates Adobe Reader and prints a file, whosepath
must be fully specified, while suppressing the Print dialog box.The four parameters of the
/t
option evaluate topath
,printername
,drivername
, andportname
(all strings).
printername
— The name of your printer.
drivername
— Your printer driver’s name, as it appears in your printer’s properties.
portname
— The printer’s port.portname
cannot contain any/
characters; if it does, output is routed to the default port for that printer.
Source Acrobat Developer FAQ
回答2:
ImageMagick can extract specific page(s) of PDF documents as images, so if you want to print page 3, you could use the following command (bearing in mind that it counts from page ZERO):
magick file.pdf[2] page.bmp
mspaint /pt page.bmp
Or, if you have a "penchant" for one-liners:
magick file.pdf[2] page.bmp && mspaint /pt page.bmp
If the resolution is too low/blocky, use:
magick -density 144 file.pdf[2] page.bmp
If you don't like MS-Paint, or prefer PNG
files for some reason:
magick file.pdf[2] page.png
rundll32 C:\WINDOWS\system32\shimgvw.dll,ImageView_PrintTo "page.png" "Fictional HP Printer"
回答3:
Here is how I do it:
pdf_print_sendkeys.vbs:
Dim ObjArgs
Set ObjArgs = wscript.arguments
cmd = objargs(0) & " /P " & objargs(1)
Set objShell = WScript.CreateObject ("WScript.shell")
objshell.exec(cmd)
WScript.Sleep 5000
objShell.AppActivate "Print"
objShell.SendKeys "%g", TRUE ' Alt + g [Pages]
objShell.SendKeys "{TAB}", TRUE ' Input Pages
objShell.SendKeys objargs(2), TRUE ' Start and End Page
objShell.SendKeys "{ENTER}", TRUE ' Print!
Set objShell = Nothing
Test:
wscript "C:\tmp\pdf_print_sendkeys.vbs" "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" "C:\tmp\test.pdf" "2-3"
See here for my full write-up and further utilization etc.
https://www.freesoftwareservers.com/display/FREES/Print+PDF+Via+Batch+-+AcroRd32.exe+Switches+-+Print+Specific+Pages
来源:https://stackoverflow.com/questions/38698411/print-a-specific-pdf-page-using-command-line