943,865 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 7382
  • C RSS
You are currently viewing page 1 of this multi-page discussion thread
Feb 6th, 2009
0

Open PDF files at a certain page

Expand Post »
Hi!
I'm using a C program to open PDF files with this code:

  1. ShellExecute(GetDesktopWindow(), "open", "c:\\someFolder\\myFile.pdf", NULL, NULL, SW_SHOWNORMAL);

Now I need to go furthrer; I need to open the PDF file at a certain page. I've tried

  1. "c:\\someFolder\\myFile.pdf#page=5"...

...as is suggested in Adobe's docs, but this does not work.

Any hints?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
marcosjp is offline Offline
42 posts
since Mar 2008
Feb 7th, 2009
0

Re: Open PDF files at a certain page

EDIT:

On second thoughts, you are right.

Just a little change
  1. ShellExecute(GetDesktopWindow(), "open", "c:\\someFolder\\myFile.pdf #page=4", NULL, NULL, SW_SHOWNORMAL);

Just add a space, cause page=4 is an argument.

----------------
I don't know if there are any real ways to do it. But how about triggering some keyboard inputs with keybd_event()
All you have to do is Ctrl+Shift+N to open the "go to page" dialog box. and then the input the number 4(say) and also "Enter" with the same function. Before all this you have to give time for the pdf to get opened and become active(You may have to use the function Sleep())

You can get the complete set of Virtual key codes in msdn

Hope it helps
Last edited by Prabakar; Feb 7th, 2009 at 1:43 am.
Reputation Points: 94
Solved Threads: 33
Posting Whiz
Prabakar is offline Offline
342 posts
since May 2008
Feb 8th, 2009
0

Re: Open PDF files at a certain page

The official way is with Win32 COM
(never use keybd_event, not professonal at all...)
Last edited by marco93; Feb 8th, 2009 at 12:54 pm.
Reputation Points: -76
Solved Threads: 14
Junior Poster
marco93 is offline Offline
132 posts
since Apr 2008
Feb 9th, 2009
0

Re: Open PDF files at a certain page

Click to Expand / Collapse  Quote originally posted by marco93 ...
The official way is with Win32 COM
(never use keybd_event, not professonal at all...)
I'll take a note of that.

And the actual answer is not either. Its just to give an argument to the pdf we are opening
Reputation Points: 94
Solved Threads: 33
Posting Whiz
Prabakar is offline Offline
342 posts
since May 2008
Feb 9th, 2009
0

Re: Open PDF files at a certain page

Well, so far I've not succeeded in making it work.
It is very easy to get the righ result when you open PDF files in a web browser: all you have to do is follow the PDF file name with the #page=n parameter (and without space).

However it does not work when calling the PDF from C/C++. I know it is possible, I've seen it work somewhere...

I'll post the solution here when I find it...
Reputation Points: 10
Solved Threads: 0
Light Poster
marcosjp is offline Offline
42 posts
since Mar 2008
Feb 9th, 2009
1

Hurray!!!

Sorry to have suggested an untested code.
My little Google search found me this

Have a look at it.

This time I have tested the code and it really works.
cpp Syntax (Toggle Plain Text)
  1. ShellExecute(GetDesktopWindow(), "open", "\"D:\\program files\\Adobe Reader 9.exe\"", "/A page=45 Ubuntu.Pdf", NULL, SW_SHOWNORMAL);

D:\Program files\Adobe Reader 9.exe is the path to the portable reader in my computer(I always try to get portable versions).

Ubuntu.pdf was in the same folder as my CPP program, hence I did not specify its path.

Details about parameter options could be found int the link above.

Good Luck
Last edited by Prabakar; Feb 9th, 2009 at 11:28 am. Reason: Spelling Mistake :$
Reputation Points: 94
Solved Threads: 33
Posting Whiz
Prabakar is offline Offline
342 posts
since May 2008
Feb 11th, 2009
0

Re: Open PDF files at a certain page

THANK YOU!!!
Thank you VERY MUCH!
You saved my day!!!
Thanks!
All the Best!
Reputation Points: 10
Solved Threads: 0
Light Poster
marcosjp is offline Offline
42 posts
since Mar 2008
Feb 11th, 2009
0

Re: Open PDF files at a certain page

Well.... I was too quick to celebrate...

It works fine in Win XP, but not on Vista.... oh well...

I wonder why!!
Reputation Points: 10
Solved Threads: 0
Light Poster
marcosjp is offline Offline
42 posts
since Mar 2008
Feb 11th, 2009
0

Re: Open PDF files at a certain page

Hey Prabakar,

You mentioned you use a portable reader. Maybe this is a solution, where do I get it?

I've googled it and found so many different options... is there one from Adobe?

Thanks!
Reputation Points: 10
Solved Threads: 0
Light Poster
marcosjp is offline Offline
42 posts
since Mar 2008
Feb 12th, 2009
0

Re: Open PDF files at a certain page

I do not have vista, to help you I don't know why it is not working in vista, these functions are ment to work on windows after all. Perhaps you'll have to wait for others to respond
Reputation Points: 94
Solved Threads: 33
Posting Whiz
Prabakar is offline Offline
342 posts
since May 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Dynamicaly defining a structure in C
Next Thread in C Forum Timeline: What method is better?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC