如何使用C++如何在特定页面或命名目的地打开PDF Shellexecute命令
我正在尝试使用 shellexecute()
在特定命名目标上打开 .pdf
,但我无法弄清楚应该如何格式化参数。我在这里使用的paramater是 pagew
。
有人尝试过吗?我找到了几个答案,但是他们没有我需要的帮助。
PS:仅打开 .pdf
工作正常。
int main()
{
std::string url = "\"C:/Users/asura/Downloads/asuras.pdf\"";
std::wstring stemp = std::wstring(url.begin(), url.end());
LPCWSTR sw = stemp.c_str();
std::string action = "open";
std::wstring atemp = std::wstring(action.begin(), action.end());
LPCWSTR actiont = atemp.c_str();
//1 INTRODUCTION
string strPageDestination = "/A \"page=52\" \"pdf\"";
std::wstring pagetemp = std::wstring(strPageDestination.begin(), strPageDestination.end());
LPCWSTR pagew = pagetemp.c_str();
//The line below works fine, it opens pdf with default pdf opener at first page.
//ShellExecute(NULL, actiont, sw, NULL, NULL, SW_SHOWNORMAL);
//The line below attempting to open file at specific page number doesn't work
ShellExecute(NULL, actiont, sw, pagew, NULL, SW_SHOWNORMAL);
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在评论中,您说:
根据这个杂技
我使用Adobe Acrobat Reader DC安装了DC,并通过查看Windows注册表中注册的方式,使用
Shellexecute(“ Open”)(“ open”)
,只需.pdf
file> file> file> file> 将无法在使用/a
参数时产生上面概述的命令语法。您传递给lpparameters
shelexecute()
的参数都没关系,Acrobat将忽略它。因此,我看到的方式有两个选择:
通过使用
createProcess()
直接运行Acrobat.exe
程序,指定完整的命令行您需要。使用
shellexecute()
启动一个Web浏览器,以.pdf
文件指定URL,以ACROBAT文档中概述的格式,如下:我尚未尝试使用URL,但是此方法可能需要您运行本地HTTP服务器,或者至少使用
文件:
url,以打开本地。 PDF
通过URL文件。In comments, you state:
According to this Acrobat documentation (and others like it that I found):
I have Adobe Acrobat Reader DC installed, and from looking at the way it is registered in the Windows Registry, using
ShellExecute("open")
with just a.pdf
file path WILL NOT be able to produce the command syntax outlined above that Acrobat requires when using the/A
parameter. It doesn't matter what you pass in to thelpParameters
parameter ofShellExecute()
, it will be ignored by Acrobat.So, the way I see it, you have two choices:
run the Acrobat
.exe
program directly by usingCreateProcess()
, specifying the complete command-line you need.use
ShellExecute()
to launch a web browser specifying a URL to the.pdf
file, in the format outlined in the Acrobat documentation, as follows:I have not tried using a URL, but this approach may require you to run a local HTTP server, or at least use a
file:
url, in order to open a local.pdf
file via a URL.在Windows上,您将在我的情况下使用命令级别的
应用程序/PDF处理程序运行Windows Windows,
其中包括片段(片段需要替换为%20),并且Windows可以将其转换为\,如果传统命令呼叫使用了file)
file:// /c:/users/asura/downloads/asuras.pdf#page=52
//i.sstatic.net/owt8a.png“ alt =“在此处输入图像说明”>
对语法可能会更加挑剔
Acrobat在称为Direct时, “ https://i.sstatic.net/ue9hh.png” rel =“ nofollow noreferrer”>
命名的目的地可能非常善变,需要准确地建造(避免连字符或空格),并针对观众特定,因此Adobes自己的文档是Yardstick测试的一个好指标。
在这里,Edge中的第三书标记为#parameters或第二名为#Contents
或使用命名为最终,但它的薄片。页面可靠。
On windows you would run at command level
Application/pdf handler in my case Windows Own
with unquoted URL argument including fragment (spaces require replace with %20 and windows can reverse the \ if they were used by a conventional command call)
file:///C:/Users/asura/Downloads/asuras.pdf#page=52
Acrobat can be a lot fussier about the syntax when called direct you place the /Action before the file name
Named destinations can be very fickle, they need to be accurately built (avoid hyphens or spaces) and specific to viewer, so Adobes own documentation is one good indicator for yardstick test.
Here calling the 3rd bookmark in edge as simply #Parameters or 2nd as #Contents
or use nameddest but its flakey. Pages are reliable.
“ c:\ program文件(x86)\ adobe \ acrobat读取器dc \ reader /acrord32.exe” /a“ natydest = onenameddest”“ c:\ users \ users \ asur \ asur \ asur \ asur \ asur \ asur \ asur \ test.pdf”
上述解决方案或任何开放式动作在命名目的地而不是书签上。
"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader/AcroRd32.exe" /A "nameddest=OneNamedDest" "C:\Users\asur\Downloads\Test.pdf"
Named destination and Bookmarks are totally different for Acrobat.
The above solution or any open action works on named destination not bookmarks.