Adobe Reader Command Line Reference - acrobat

Is there any official command line (switches) reference for the different versions of
Adobe (formerly Acrobat) Reader?
I didn't find anything on Adobe Developer Connection.
Especially I want to:
Start Reader and open a file
Open a file at a specific position (page)
Close Reader (or single file)

You can find something about this in the Adobe Developer FAQ. (It's a PDF document rather than a web page, which I guess is unsurprising in this particular case.)
The FAQ notes that the use of the command line switches is unsupported.
To open a file it's:
AcroRd32.exe <filename>
The following switches are available:
/n - Launch a new instance of Reader even if one is already open
/s - Don't show the splash screen
/o - Don't show the open file dialog
/h - Open as a minimized window
/p <filename> - Open and go straight to the print dialog
/t <filename> <printername> <drivername> <portname> - Print the file the specified printer.

I found this:
http://www.robvanderwoude.com/commandlineswitches.php#Acrobat
Open a PDF file with navigation pane active, zoom out to 50%, and search for and highlight the word "batch":
AcroRd32.exe /A "zoom=50&navpanes=1=OpenActions&search=batch" PdfFile

To open a PDF at page 100 the follow works
<path to Adobe Reader> /A "page=100" "<Path To PDF file>"
If you require more than one argument separate them with &
I use the following in a batch file to open the book I'm reading to the page I was up to.
C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe /A "page=149&pagemode=none" "D:\books\MCTS(70-562) ASP.Net 3.5 Development.pdf"
The best list of command line args for Adobe Reader I have found is here.
http://partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf
It's for version 7 but all the arguments I tried worked.
As for closing the file, I think you will need to use the SDK, or if you are opening the file from code you could close the file from code once you have finished with it.

Call this after the print job has returned:
oShell.AppActivate "Adobe Reader"
oShell.SendKeys "%FX"

Having /A without additional parameters other than the filename didn't work for me, but the following code worked fine with /n
string sfile = #".\help\delta-pqca-400-100-300-fc4-user-manual.pdf";
Process myProcess = new Process();
myProcess.StartInfo.FileName = "AcroRd32.exe";
myProcess.StartInfo.Arguments = " /n " + "\"" + sfile + "\"";
myProcess.Start();

Related

VBA - Macro - To Print Multiple digital signed PDF file and save it in subfolder by using "Microsoft Print to PDF" Printer

I am printing multiple digital signed PDF file into PDF via "Microsoft print to PDF" ( To Edit document) . Below mention VBA code is working perfectly. But when run this code each time, it is asking Filename & Destination folder for printed file.
My Expection:
It has to capture file name from existing saved documents file name and destination folder path we have include in VBA Code.
Please help me, How to solve this
Public Sub Print_All_PDF_Files_in_Folder()
Dim folder As String
Dim PDFfilename As String
folder = "C:\Users\Desktop\VBA\" 'CHANGE AS REQUIRED
If Right(folder, 1) <> "\" Then folder = folder & "\"
PDFfilename = Dir(folder & "*.pdf", vbNormal)
While Len(PDFfilename) <> 0
Print_PDF folder & PDFfilename
PDFfilename = Dir() ' Get next matching file
Wend
End Sub
Private Sub Print_PDF(sPDFfile As String)
Shell "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe /p /h " & Chr(34) & sPDFfile & Chr(34), vbNormalFocus
End Sub
Path with spaces must be in quotes, because it is has spaces. Keys /p and /h must be separate from Program name. I check it this way:
i make this command in cmd.exe and when i see what it correct - I revrite it into macro.
Private Sub Print_PDF(sPDFfile As String)
Shell "" & Chr(34) & "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" & Chr(34) & " /p /h " & Chr(34) & sPDFfile & Chr(34)
End Sub
You seem to have multiple conflicts
Your command includes the command to open the Printer Dialog
/P <filename> - Open and go straight to the Printer Prompt dialog
And for "Microsoft Print to PDF" that will allow you to make the manual changes you require to the PDF then manually save to a folder or filename of your choosing.
However you say you want Acrobat to save to a known filename without that prompting. Which in turn makes me question WHY are you using Acrobat to open a PDF and re-save it as a file name without interaction ?
You could do that simply by renaming the PDF without opening it in Acrobat.
One advantage of programmatically opening a "Complex" PDF in Acrobat and Re-Printing as a "Dumber" PDF using "Microsoft Print to PDF" is it can pseudo-manically emulate much more efficient ways of flattening by using a very inefficient reprinting and for that you need to use:-
/T <filename> <printername> <drivername> <portname> - Print the file on the specified printer.
Where printername and drivername are "Microsoft Print to PDF" and portname is where you want it printed.
There are much lighter ways to process a PDF from the command line, but if you already have installed heavyweight Adobe Reader then this is the defacto standard.
[EDIT] in the comments you imply you still need to use acrobat for processing before printing to a fixed name. Then in that case, you need to run those actions first. Before saving as new PDF, prior to printing, thus you need to
get filename
make changes
save changes as new filename
send new filename to printer using:-
"C:\Full path\to\AcroRd32.exe" /T "C:\path to\Input.pdf" "Microsoft Print to PDF" "Microsoft Print to PDF" "C:\path to\Output.pdf"
The problem with batch printing, using /T = TSR (Terminate and Stay Resident), is that the window stays open waiting for the next print in the batch, and most users then add /H to hide it, then afterwards complain its not accessible so as to close at the end of the batch (which simply requires sendkeys %FX or Alt+F4 to close the open window)!
One way round that is, on the last print invoke /T without H, and then a VB focused command (object.AppActivate title) and at simplest sendkeys %FX will close the window.
If using the command line or a .cmd it is simple to use Wscript with a single line .VBS command, however in this case you are already using VBA.

AppleScript Read The Keywords In The Preview App

The Preview App on the Mac lets you add keywords to a PDF file.
Is it possible to use AppleScript to read the keywords? If so, how?
The Exiftool manages keywords for many file types, including PDF. This is a free command line tool you can download. Once the tool is installed, you can use it via Terminal or, of course, via Applescript with "do shell script".
If myFile is the PDF file selected, then you can read the existing keywords with:
set myKeyWords to do shell script "/usr/local/bin/exiftool -Keywords " & quoted form of (POSIX path myFile)
if length of myKeyWords > 35 then
set myKeyWords to text 35 thru -1 of myKeyWords
end if
The result of the command is empty (if no keywords) or it is made of 33 spaces, ':', 1 space, and the list of keywords separated by ','. This is why I added the 'if' statement after the do shell script command.
And you can also write new keywords (variable MyKey) in your PDF file with :
do shell script "/usr/local/bin/exiftool -Keywords+='" & MyKey & "' -Overwrite_Original " & quoted form of (POSIX path of myFile)
Exiftool can do many other things for images and PDF files. Some actions are specific to images, some to PDF, or for all file types. Please use the man page in Terminal to know more.
Preview.app supports only the generic classes / commands and has no application specific dictionary.
It might be possible with the ugly GUI scripting.

Can I use CreateObject to print a .tif document with vba? If not, what?

The following vba routine works well to print a word document
If sHlink <> "" Then
Set OfficeObject = CreateObject("Word.Application")
OfficeObject.Documents.Open sHlink
OfficeObject.PrintOut Background:=False
OfficeObject.Quit
Set OfficeObject = Nothing
End If
but what I need to print are .TIF documents. They open by default with the Microsoft Photo Viewer. Is there something similar that will call the MS Photo Viewer, or failing that, Acrobat? Perhaps with Acrobat could I use some kind of command line?
Thank You
I found this shell command that prints using the Photo Editor that was formerly installed with Office:
Shell """C:\Program Files\Common Files\Microsoft Shared\PhotoEd\photoed.exe"" -p h:\misc\MyPicture.tif"
I think it can be adapted to print using the current Picture Manager - I bet it uses the same -p switch. This seems to be named "OIS.EXE" for some reason.

print automatically pdf file with powershell

I'm printing a pdf file with:
Start-Process -FilePath "C:\file.pdf" –Verb Print
This opens an empty adobe reader window, prints the file, but keeps the adobe reader open. So, how do I close adobe reader?
Thank you in advance.
From here seems like that is how AcroRd32 will work - it will keep the Adobe Reader open and you can only control whether it is minimized when it starts or not.
One alternative is to use Foxit Reader as described here- http://www.deltasblog.co.uk/code-snippets/printing-pdf-files-from-command-line-without-adobe-reader/
Or,Hack:
Start-Process -FilePath "test.pdf" –Verb Print
sleep 10
kill -name AcroRd32
Updated hack for multiple Adobe readers open:
Start-Process -FilePath "test.pdf" –Verb Print -PassThru | %{sleep 10;$_} | kill

How to programmatically generate a PDF from any document on OSX?

I'm working on a project for OSX where the user can pick a collection of documents (from any application) which I need to generate PDF's from. The standard Macintosh Print dialog has a PDF button which has a number of PDF-related commands including "Save as PDF...". However, I need to generate the PDF file without requiring user interactions. I ideally want this to work with any type of document.
Here's the options I've explored so far:
Automator actions. There's a PDF library for Automator but it provides actions for working with PDF files, not generating them. There's a Finder action for printing any file but only to a real printer.
AppleScript. Some applications have the ability to generate PDF files (for instance, if you send 'save doc in "test.pdf"' to Pages it will generate a PDF (but this only works for Pages - I need support for any type of document).
Custom Printer. I could create a virtual printer driver and then use the automator action but I don't like the idea of confusing the user with an extra printer in the print list.
My hope is that there's some way to interact with the active application as if the user was carrying out the following steps:
Do Cmd-P (opens the print dialog)
Click the "PDF" button
Select "Save as PDF..." (second item in menu)
Type in filename in save dialog
Click "Save"
If that's the best approach (is it?) then the real problem is: how do I send UI Events to an external application (keystrokes, mouse events, menu selections) ?
Update: Just to clarify one point: the documents I need to convert to PDF are documents that are created by other applications. For example, the user might pick a Word document or a Numbers spreadsheet or an OmniGraffle drawing or a Web Page. The common denominator is that each of these documents has an associated application and that application knows how to print it (and OSX knows how to render print output to a PDF file).
So, the samples at Cocoa Dev Central don't help because they're about generating a PDF from my application.
I think you could use applescript to open a document and then use applescript UI scripting to invoke print menu.
For example :
tell application "System Events"
tell window of process "Safari"
set foremost to true
keystroke "p" using {command down}
delay 3
click menu button "PDF" of sheet 2
click menu item "Save as PDF…" of menu 1 of menu button "PDF" of sheet 2
keystroke "my_test.file"
keystroke return
delay 10
end tell
end tell
Take a look at a program called CUPS-PDF
It is a virtual printer for OS X which does what the "Save As PDF" method does when print through your normal printer except every print job passed through it results in a pdf output.
Once you install it then you could create shell or AppleScripts using the lp command.
For example, once the virtual printer is setup you could print test.txt and have it automatically save as a pdf. To do this using an AppleScript you would use the following code:
do shell script "lp -d CUPS_PDF test.txt"
The CUPS-PDF app saves all output to /Users/Shared/CUPS-PDF. I am not sure if you can change that path but you could retrieve the file in your script and move it.
There are a few caveats though.
First, the lp command cannot print .doc files. I think there are some other third party apps which will allow you to do this though.
Second, the CUPS-PDF app shows in the Printer pane of System Preferences as having the hyphen in its name but CUPS shows the queue name as having an underscore. So, on the command line you need to refer to the CUPS queue name which is CUPS_PDF with an underscore.
Even if you don't find it very useful to build a script via the lp command
and still want to involve GUI scripting then having a virtual printer should save you some steps.
you could use cups like this
on open afile
set filename to name of (info for afile)
tell application "Finder"
set filepath to (container of (afile as alias)) as alias
end tell
set filepath to quoted form of POSIX path of filepath
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set filename to text item 1 of filename
set AppleScript's text item delimiters to tid
set afile to quoted form of POSIX path of afile
do shell script "cupsfilter " & afile & " > " & filepath & filename & ".pdf"
end open
I have created an alias in bash for this:
convert2pdf() {
/System/Library/Printers/Libraries/convert -f "$1" -o "$2" -j "application/pdf"
}
I typed up the code below with the assistance of Automator (recording an action, and then dragging the specific action out of the "Watch Me Do" window in order to get the Applescript). If you want to print a PDF from an application other than Safari, you might have to run through the same process and tweak this Applescript around the Print dialogue, since each program might have a different Print GUI.
# Convert the current Safari window to a PDF
# by Sebastain Gallese
# props to the following for helping me get frontmost window
# http://stackoverflow.com/questions/480866/get-the-title-of-the-current-active-window- document-in-mac-os-x
global window_name
# This script works with Safari, you might have
# to tweak it to work with other applications
set myApplication to "Safari"
# You can name the PDF whatever you want
# Just make sure to delete it or move it or rename it
# Before running the script again
set myPDFName to "mynewpdfile"
tell application myApplication
activate
if the (count of windows) is not 0 then
set window_name to name of front window
end if
end tell
set timeoutSeconds to 2.0
set uiScript to "keystroke \"p\" using command down"
my doWithTimeout(uiScript, timeoutSeconds)
set uiScript to "click menu button \"PDF\" of sheet 1 of window \"" & window_name & "\" of application process \"" & myApplication & "\""
my doWithTimeout(uiScript, timeoutSeconds)
set uiScript to "click menu item 2 of menu 1 of menu button \"PDF\" of sheet 1 of window \"" & window_name & "\" of application process \"" & myApplication & "\""
my doWithTimeout(uiScript, timeoutSeconds)
set uiScript to "keystroke \"" & myPDFName & "\""
my doWithTimeout(uiScript, timeoutSeconds)
set uiScript to "keystroke return"
my doWithTimeout(uiScript, timeoutSeconds)
on doWithTimeout(uiScript, timeoutSeconds)
set endDate to (current date) + timeoutSeconds
repeat
try
run script "tell application \"System Events\"
" & uiScript & "
end tell"
exit repeat
on error errorMessage
if ((current date) > endDate) then
error "Can not " & uiScript
end if
end try
end repeat
end doWithTimeout
"/System/Library/Printers/Libraries/./convert"
has been removed in later version of MacOS.
You can use sips now. AppleScript example:
do shell script: sips -s format pdf Filename.jpg --out Filename.pdf