1

I've spent a couple of days searching the bowels of the internet to find out the answer to my question, so since I can't find the answer I'm throwing it out to the masses...

Within my Qt application I'm able to open a PDF using the OS default viewer thru the following command:

QDesktopServices::openUrl(QUrl("file:////C:help.pdf", QUrl::TolerantMode));

This works fine because all I'm wanting to do is display a help file to a user, but when I try to add a "#page=20" parameter to my URL, the document still only opens to the first page, not page 20. If I cut and paste the command into a browser it jumps correctly.

So -- my questions are:

  1. Would poppler or another viewing tool allow me to jump to a page?
  2. Is there another way with Qt to jump to a page? Or maybe another command to open the file instead of with QDesktopServices?

edit: I tried with QProcess and that doesn't jump to the page either -- not that I expected it to...

user1020750
  • 11
  • 1
  • 4

3 Answers3

4

Use QProcess with one of the answers from Adobe Reader Command Line Reference :

<path to Adobe Reader> /A "page=100" "<Path To PDF file>"
Community
  • 1
  • 1
Stephen Chu
  • 12,724
  • 1
  • 35
  • 46
  • Hmmm, I'll have to give this a shot later (when I get home from my day job). I'd already successfully launched it with QProcess w/out the page numbers but if I can figure out a way to embed those options within the arguments to QProcess maybe that'll do it! – user1020750 Aug 15 '12 at 18:32
  • Note that while this *is* a solution, it isn't portable at all neither respecting the operating system nor the PDF viewer. – leemes Aug 16 '12 at 00:12
  • Yep, already considered that...I used QProcess for something else in my app and already had to address it -- thanks! – user1020750 Aug 16 '12 at 19:09
1
  1. Yes. evince, for example, takes option --page-index which you can set page number
  2. No. QDesktopServices::openUrl() ends up calling one of helper commands, such as xdg-open or kfmclient, without any arguments.

Of cause, you can always use libpoppler in your app to open your PDFs. Poppler::Document::page() is your friend.

Yasushi Shoji
  • 4,028
  • 1
  • 26
  • 47
  • that explains why QDesktopServices::openUrl(QUrl("file://C:/help.pdf#page=20")); drops the #page=20 parameter when I associated the test.pdf file Chrome instead of Reader -- thanks for that input... – user1020750 Aug 15 '12 at 18:09
  • If I can't get QProcess to work (which seems like a faster way of getting to a solution since I'm almost there), then I'll try your two ideas -- thanks! – user1020750 Aug 15 '12 at 18:35
0

Another solution I was able to work out was to convert my PDF to HTML, create a QWebView, and display the HTML there. I then added an ID attribute to the HTML doc, and when I tacked that ID to my URL it loaded into the widget at the location of the attribute...

scott

user1020750
  • 11
  • 1
  • 4