I have an application that manages multiple magazine PDFs on the hard drive. I need to open the PDF files into a specific page. I am able to call vbscript from my own software so I am looking for some vbscript snippet to open a PDF with a specific page loaded. I am a mac developer doing cross platform software, windows is not my standard bread and butter.
From the Adobe docs, I checked that using system calls to open a URL like:
http://myserver/mypdf#page=3
works fine but trying to use similar URL with the dummy file protocol like:
file://path/to/mypdf#page=2
does not work. After figuring that, I decided that I should try some vbscript call to some COM or ActiveX or whatever they use these days on windows but I don't know how to do it.
Thanks for any help.
You could use the "page=..." parameter of Acrobat Reader, like this:
Sub OpenPdf(filename, page)
Set wshShell = WScript.CreateObject("WSCript.shell")
wshShell.Run """%ProgramFiles%\Adobe\Reader 9.0\Reader\AcroRd32.exe"" /A ""page=" & _
page & """ " & fileName
End Sub
OpenPdf "c:\temp\myfile.pdf", 20
Try to use AcroExch.AVPageView.Goto() Method
and avoid the path of adobe executable
Related
I am currently using Adobe Acrobat Pro DC 2015.23 on macOS Sierra.
My goal is to create AppleScript that do such things:
Open PDF File
Save this file to pdf-x format
Close file
I create AppleScript, that do all steps, but i can't find any documentation how to choose with PDF standard to use while saving.
If I want to do this manually I do following steps:
Open PDF in Adobe Acrobat
Choose PDF Standards Menu
Click (Save as PDF/X)
Press save
The question is how to set PDF/X standard while saving.
My script
on is_running(appName)
tell application "System Events" to (name of processes) contains appName
end is_running
set theFiles to choose file with prompt "Select the files" of type {"pdf"} with multiple selections allowed
set aaRunning to is_running("Adobe Acrobat")
tell application "Adobe Acrobat"
repeat with theFile in theFiles
open theFile without dialogs
save active doc to theFile
close active doc
end repeat
if not aaRunning then
quit
end if
end tell
As you may have noted, Applescript support of Acrobat is very limited.
Just so, the following possible workflows come to my mind:
a) you can use Preflight Profiles to create PDF/X (this is also the engine if you do it manually). You can run/apply Preflight Profiles using Acrobat JavaScript, and you can run Acrobat JavaScripts using the do script Applscript command.
b) you create a Preflight Droplet which makes an according PDF/X file. You then can use Applescript to open the document (file) in that droplet.
c) you use System Events to control the user interface elements of Acrobat. In other words, you do what you would do manually, but using System Events. You may want to use an utility, such as UI Browser to find the ways to address the various dialog elements.
I create a PDF with iTextsharp and then I show the preview of the PDF inside a webbrowser control. From the preview the user can SAVE or PRINT using the defaults Adobe Reader's buttons
Working on Windows x64 bits with Adobe Reader as the default PDF viewer everything works fine.
The same program on a Windows x64 bits but with Foxit Reader as the default PDF open the file on Foxit Reader on full application window, outside my program.
I need to manage that.
My code is like
Dim PathToPDF As String
PathToPDF = DirectoryOfMyApp & "\ReportPreview.pdf"
ReportPreviewWebBrowser.Navigate(PathToPDF)
Where DirectoryOfMyApp just gets the C: or D: letter of the hard disk.
I read this link
How to start an Adobe Reader or Acrobat from VB.NET?
but a line like
ReportPreviewWebBrowser.Navigate("acrobat", PathToPDF )
didn´t work and I think the webbrowser control don´t have the option to choose the PDF viewer
https://msdn.microsoft.com/es-es/library/system.windows.forms.webbrowser(v=vs.110).aspx
Is there a way to set the webbrowser to use Adobe Acrobat Reader only or to force any other PDF viewer to show the PDF inside the webbrowser control?
I agree with Zaggler on his comments on this. You are making assumptions at a certain point on software that is installed on an end user's computer. Unless you are going to make the application's PDF viewer be part of a dependency installation or cooked into .NET you cannot guarantee they have that program to use. Nor can you guarantee it's installed location.
However there is a cheap hack for Windows based processes you can do in VB.NET. You can use the ole System.Diagnostics.Process()
Sub Main()
Dim nProcess = New System.Diagnostics.Process()
nProcess.Start($"D:\PdfFile.pdf")
End Sub
In this example I did a quick file location, you can try to ensure it is a valid location that will not change or is in your app's running process folder. This is really low tech as far as development goes, but it is basically saying: "Run me a process, any process, at this location. I don't care what it is, use the Windows defaults to determine what to do with it."
So when I run this on my Windows 10 Dev box it loads up Edge to display it, at home it would fire up Adobe Viewer. It is just opening the file essentially with the OS's choice of what is using that file extension. Not glamorous or very good for hardened code but it works when you want something quick to happen.
No, you can't do this.
You can't even guarantee that Adobe Reader is installed at all.
Reader might not even exist on the machine. It's not built into Windows, and not everyone uses it. Even if it is, FoxIt isn't the only alternative. A big one is that Chrome includes it's own PDF viewer.
I saved the datawindow in PDF format using SAVEAS method and I want to open the saved file in Acrobat reader. But in web application after save as method using Downloadfile() i'm able to open it. I think using OLEobject it is possile but i don't know how to do that. Any suggestions ?
If you just want to view the document (ie, no interaction with your PowerBuilder application) you can use the 'RUN' command.
Example:
RUN('C:\temp\mydoc.pdf')
This will open the file using whichever program is associated with .pdf files within your Windows settings.
We simply use the Internet context service to open the PDF URL:
inet l_inet
string ls_url
// set ls_url to the URL to open
GetContextService("Internet", l_inet)
l_inet.HyperlinkToURL(ls_url)
tell application "Adobe Photoshop CS5.1"
set myFile to (choose file) as string
open file myFile
end tell
This results in 2 separate dialogs opening asking me what file to open.... It doesn't matter what I select first, it asks a second time and opens the second.
What I want to open is a PDF, so I really want:
tell application "Adobe Photoshop CS5.1"
set myFile to (choose file) as string
open file myFile as PDF with options {class:PDF open options, mode:CMYK, resolution:300, use antialias:true, page:1} showing dialogs never
end tell
Result:
Error: General Photoshop error occurred. This functionality may not be available in this version of Photoshop
All right a more direct approach:
tell application "Adobe Photoshop CS5.1"
set myFilePath to alias "other: PREPRESS SAVE:GAMES:3Sudoku:20120213pzsud-v:sudoku 0213.pdf"
with timeout of 300 seconds
open myFilePath as PDF with options {class:PDF open options, mode:CMYK, resolution:300, use antialias:true, page:1}
end timeout
end tell
The file exists or the setting of the alias would fail. So what do I get?
"Error: -43. Adobe Photoshop CS5.1 got an error: File some object wasn’t found."
I had asked over on the Adobe forums, with no response. The full code I'm really trying to use is there if you're interested. I reduced it to basics to figure out what the problem is.
Is there a setting somewhere that I am missing? I'm not sure what is wrong, the example out of the
There are horrible issues with The Photoshop 5 dictionary. One idea is to try and run it in 32-bit mode which 'solves' a lot of issues. Please digest further in http://forums.adobe.com/message/2822670#2822670?tstart=0#2822670
Might be a CS5 issue, but I honestly don't know.
This worked fine for me, but with CS4:
tell application "Adobe Photoshop CS4"
set myFile to (choose file) as alias
with timeout of 300 seconds
open myFile as PDF with options {class:PDF open options, mode:CMYK, resolution:300, use antialias:true, page:1}
end timeout
end tell
The only real difference (that I can see) is that I alias the chosen file, and call open ... - not open file ...
I want to create a COM dll that will take any Word file and generate an image file of the first page of the document. I have already done this using the IExtractImage functionality of the Windows SDK, but this only works if there is a thumbnail saved with the file. (Since the Word user has to make an extra effort to save the thumbnail by going down into the Advanced options of the Prepare | Properties dialog, most Word docs don’t have a preview available.)
(Unfortunately I am stuck with using COM because I am integrating this solution with an existing ASP web app that does not interact well with .NET.)
One approach I am considering is using a PDF-generating SDK to generate a PDF of the file, or ideally a PDF of just the first page of the file, and then generate the preview image from the PDF. (I don’t have access to Adobe’s proprietary PDF SDK, but if it could be shown to work well for this solution, I would look into purchasing a license.)
Ideally I would like to be able to generate a preview of many other (non-image) file types besides just a Word doc.
I notice that Google now provides a preview of many kinds of files, and I am wondering what approach they have used.
Any thoughts, clues, suggestions, and/or insults are welcome.
Thanks.
The thumbnail from the old OLE-Automation property pages is a very small (not even anti-aliased) black & white Metafile that does not look any good these days. Within classic VB6 or VBA, you can trigger saving the thumbnail with a few lines of code (If I remember correctly). However, Winword, Excel etc. are automated by loading the Gui application invisibly and this does not always work in a (web) server context. Consider to thumbnail the documents while uploading / virus scanning but not from inside a DLL that gets loaded into the web server.
The google approach builds most-likely upon some open-source components that do not work under classic ASP either.
ASP? You could use 2JPEG. It support 275 formats (including Word, Excel, Publisher & Powerpoint files.) The vendor recommends calling 2JPEG as a scheduled background task so you don't impact performance.
Here's a couple of examples:
Command line syntax. You can start in from a batch file or from the Windows Task Scheduler:
2jpeg.exe -src "C:\In\*.*" -dst "C:\Out"
Launch command line from Visual C++ application:
ShellExecute(NULL, "open", "2jpeg.exe", "-src \"C:\\In\\*.*\" -dst \"C:\\Out\"", NULL, SW_HIDE)
From Visual Basic:
Shell ("""2jpeg.exe"" -src ""C:\In\*.*"" -dst ""C:\out""")
Delphi syntax:
ShellExecute(0, 'open', PChar('2jpeg.exe'), PChar('-src "C:\In\*.*" -dst "C:\Out"'), nil, 0);
PERL script on Windows server:
exec '2jpeg.exe -src C:\In\*.* -dst C:\out';
VB Script code example:
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run """2jpeg.exe"" -src ""C:\In\*.*"" -dst ""C:\Out""", 1, True
Set objShell = Nothing
JavaScript code example:
var objShell = new ActiveXObject("Shell.Application");
objShell.ShellExecute("2jpeg.exe", "-src \"C:\\In\\*.*\" -dst \"C:\\Out\"", "", "open", "1");
PHP code example:
<?php
echo exec('2jpeg.exe -src "C:\In\*.*" -dst "C:\Out" -oper Resize size:"800 600" -jpeg quality:50');
?>
Launch 2JPEG from C# application:
System.Diagnostics.Process.Start("2jpeg.exe", "-src \"C:\\In\\*.*\" -dst \"C:\\Out\"");