Open PDF files at a certain page

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Mar 2008
Posts: 42
Reputation: marcosjp is an unknown quantity at this point 
Solved Threads: 0
marcosjp marcosjp is offline Offline
Light Poster

Open PDF files at a certain page

 
0
  #1
Feb 6th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 334
Reputation: Prabakar is on a distinguished road 
Solved Threads: 29
Prabakar's Avatar
Prabakar Prabakar is offline Offline
Posting Whiz

Re: Open PDF files at a certain page

 
0
  #2
Feb 7th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 118
Reputation: marco93 is infamous around these parts marco93 is infamous around these parts marco93 is infamous around these parts 
Solved Threads: 12
marco93 marco93 is offline Offline
Junior Poster

Re: Open PDF files at a certain page

 
0
  #3
Feb 8th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 334
Reputation: Prabakar is on a distinguished road 
Solved Threads: 29
Prabakar's Avatar
Prabakar Prabakar is offline Offline
Posting Whiz

Re: Open PDF files at a certain page

 
0
  #4
Feb 9th, 2009
Originally Posted by marco93 View Post
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 42
Reputation: marcosjp is an unknown quantity at this point 
Solved Threads: 0
marcosjp marcosjp is offline Offline
Light Poster

Re: Open PDF files at a certain page

 
0
  #5
Feb 9th, 2009
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...
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 334
Reputation: Prabakar is on a distinguished road 
Solved Threads: 29
Prabakar's Avatar
Prabakar Prabakar is offline Offline
Posting Whiz

Hurray!!!

 
1
  #6
Feb 9th, 2009
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.
  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 :$
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 42
Reputation: marcosjp is an unknown quantity at this point 
Solved Threads: 0
marcosjp marcosjp is offline Offline
Light Poster

Re: Open PDF files at a certain page

 
0
  #7
Feb 11th, 2009
THANK YOU!!!
Thank you VERY MUCH!
You saved my day!!!
Thanks!
All the Best!
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 42
Reputation: marcosjp is an unknown quantity at this point 
Solved Threads: 0
marcosjp marcosjp is offline Offline
Light Poster

Re: Open PDF files at a certain page

 
0
  #8
Feb 11th, 2009
Well.... I was too quick to celebrate...

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

I wonder why!!
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 42
Reputation: marcosjp is an unknown quantity at this point 
Solved Threads: 0
marcosjp marcosjp is offline Offline
Light Poster

Re: Open PDF files at a certain page

 
0
  #9
Feb 11th, 2009
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!
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 334
Reputation: Prabakar is on a distinguished road 
Solved Threads: 29
Prabakar's Avatar
Prabakar Prabakar is offline Offline
Posting Whiz

Re: Open PDF files at a certain page

 
0
  #10
Feb 12th, 2009
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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC