Answered by:
[U8.1]C# : how open pdf file at a specific page

Question
-
Hello Everyone,
I develop a windows universal app (8.1) in C# and i want to open a local pdf file at a specific page with using Adobe Pdf Reader (not rendering pdf in my application).
It seems to be impossible in options of Windows.System.Launcher and use of Process object is not accessible for universal app (to launch acrobat.exe).
Someone has already do that ? After some hours of search it seems to be impossible :(
- Edited by Romain1987 Thursday, July 16, 2015 2:46 PM
- Edited by Franklin ChenMicrosoft employee Friday, July 17, 2015 7:09 AM Subject
Thursday, July 16, 2015 11:49 AM
Answers
-
Hello Romain,
Unfortunately, that's not possible, you can't tell the target app to open your file at a specific page from a Windows Runtime App.
An alternative way to do it, (even if you don't want to use it) is by rendering pdf in your application by using the PdfDocument class.The steps to make it work are:
- LoadFromFileAsync(IStorageFile) - Load the file
- GetPage - Get the PdfPage you want
- PreparePageAsync - Build the Page
- RenderToStreamAsync(IRandomAccessStream) - Outputs a stream of image data
- Show your image to the user
- Dispose - Free resources
The bad news are that it's not supported by Windows Phone 8.1.
But it is supported by the whole Windows 10 device family!- Proposed as answer by Franklin ChenMicrosoft employee Wednesday, July 29, 2015 12:02 PM
- Marked as answer by Franklin ChenMicrosoft employee Thursday, July 30, 2015 2:47 AM
Thursday, July 16, 2015 9:14 PM -
Yes, I understand.
Is there any Adobe reader app for Win 8.1 available?
If it is, you can set it as the default app to open pdf files and launch it by Pallam's suggestion. But as you said, you can't open it to a specific page. That's impossible unfortunately.
I would really go with my suggestion.
George- Proposed as answer by Franklin ChenMicrosoft employee Wednesday, July 29, 2015 12:02 PM
- Marked as answer by Franklin ChenMicrosoft employee Thursday, July 30, 2015 2:47 AM
Friday, July 17, 2015 12:49 PM -
It is impossible without knowing the user's default pdf program. Unless you only distribute your app in a closed environment (e.g. an enterprise network) you cannot dictate what app the user would download to open pdf files.
Even if you already know the user's default pdf program you still have to figure out how to jump to specific page. You need to negotiate with the author of the program to make the feature possible for windows store apps.
Visual C++ MVP- Proposed as answer by Franklin ChenMicrosoft employee Wednesday, July 29, 2015 12:03 PM
- Marked as answer by Franklin ChenMicrosoft employee Thursday, July 30, 2015 2:47 AM
Monday, July 20, 2015 2:34 AM
All replies
-
Hi Romain1987,
It is possible, and here is documentation.
Note: make sure you are adding document library in manifest file & PDF file type declaration.
Thanks,
Pallam Madhukar Windows Phone Developer
- Edited by Pallam Madhukar Thursday, July 16, 2015 6:25 PM
Thursday, July 16, 2015 6:23 PM -
Hello Romain,
Unfortunately, that's not possible, you can't tell the target app to open your file at a specific page from a Windows Runtime App.
An alternative way to do it, (even if you don't want to use it) is by rendering pdf in your application by using the PdfDocument class.The steps to make it work are:
- LoadFromFileAsync(IStorageFile) - Load the file
- GetPage - Get the PdfPage you want
- PreparePageAsync - Build the Page
- RenderToStreamAsync(IRandomAccessStream) - Outputs a stream of image data
- Show your image to the user
- Dispose - Free resources
The bad news are that it's not supported by Windows Phone 8.1.
But it is supported by the whole Windows 10 device family!- Proposed as answer by Franklin ChenMicrosoft employee Wednesday, July 29, 2015 12:02 PM
- Marked as answer by Franklin ChenMicrosoft employee Thursday, July 30, 2015 2:47 AM
Thursday, July 16, 2015 9:14 PM -
Hi Pallam,
I have already seen this documentation but unfortunatly it doesn't allow to open pdf file at a specific page (page 5 for example)
Friday, July 17, 2015 9:00 AM -
Hi George,
Thanks for your answer, i see this solution too but the the aim problem is we lost some important functions of pdf reader (like search) and developp them will be a little bit expensive (in my professionnal context) !!!
- Edited by Romain1987 Friday, July 17, 2015 9:12 AM
Friday, July 17, 2015 9:11 AM -
Yes, I understand.
Is there any Adobe reader app for Win 8.1 available?
If it is, you can set it as the default app to open pdf files and launch it by Pallam's suggestion. But as you said, you can't open it to a specific page. That's impossible unfortunately.
I would really go with my suggestion.
George- Proposed as answer by Franklin ChenMicrosoft employee Wednesday, July 29, 2015 12:02 PM
- Marked as answer by Franklin ChenMicrosoft employee Thursday, July 30, 2015 2:47 AM
Friday, July 17, 2015 12:49 PM -
It is impossible without knowing the user's default pdf program. Unless you only distribute your app in a closed environment (e.g. an enterprise network) you cannot dictate what app the user would download to open pdf files.
Even if you already know the user's default pdf program you still have to figure out how to jump to specific page. You need to negotiate with the author of the program to make the feature possible for windows store apps.
Visual C++ MVP- Proposed as answer by Franklin ChenMicrosoft employee Wednesday, July 29, 2015 12:03 PM
- Marked as answer by Franklin ChenMicrosoft employee Thursday, July 30, 2015 2:47 AM
Monday, July 20, 2015 2:34 AM