【发布时间】:2022-07-06 00:38:26
【问题描述】:
我正在尝试使用ShellExecute() 在特定命名目的地打开.pdf,但我不知道应该如何格式化参数。我在这里使用的参数是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;
}
【问题讨论】:
-
使用
std::wstring(str.begin(), str.end())不是将std::string转换为std::wstring的正确方法。您需要对数据进行转换,例如使用MultiByteToWideChar()、std::wstring_convert等。或者,只需以宽字符串文字开头,例如:std::wstring url = "\"...asuras.pdf\""; std::wstring action = L"open"; std::wstring strPageDestination = L"/A \"page=52\" \"pdf\""; -
在任何情况下,您可以指定的输入参数完全取决于您使用的特定 PDF 查看器,而您没有指定。没有每个 PDF 查看器统一实现的通用参数集。
-
因此,如果我从 std::wstring 开始,在特定页面或命名目的地打开 pdf 的正确格式参数是什么。 ** std::wstring pagetemp = "/A \"page=52\" \"pdf\"; LPCWSTR pagew = pagetemp.c_str(); **
-
@RemyLebeau 所以我使用 Adobe Acrobat Reader DC 作为默认查看器。 Acrobat 阅读器的输入参数是什么,Chrome 的参数会起作用。如果有人有这个想法,将不胜感激。
-
Acrobat 有一个 COM 组件,但我不推荐它,至少其他选项会更容易满足您的目的
标签: c++ pdf bookmarks shellexecute page-numbering