Xamarin iOS: How to open a .pdf file using the default reader?
I'm using Xamarin iOS. I'd like to have our application open a .pdf file in the default reader. For Android I managed to get it done by following a two-fold process: (1) copy the file from the Assets folder to the Android device's Downloads folder, and (2) starting an activity to view the file.
I cannot find any similar resources for the iOS. We don't want to use the control in the Xamarin website, as it involves downloading lots of JavaScript (?) code, making the size of the app bigger, and also doesn't support pinching the screen to zoom. We want to use the OS's default pdf reader.
Thank you.
c# ios pdf xamarin assets
add a comment |
I'm using Xamarin iOS. I'd like to have our application open a .pdf file in the default reader. For Android I managed to get it done by following a two-fold process: (1) copy the file from the Assets folder to the Android device's Downloads folder, and (2) starting an activity to view the file.
I cannot find any similar resources for the iOS. We don't want to use the control in the Xamarin website, as it involves downloading lots of JavaScript (?) code, making the size of the app bigger, and also doesn't support pinching the screen to zoom. We want to use the OS's default pdf reader.
Thank you.
c# ios pdf xamarin assets
add a comment |
I'm using Xamarin iOS. I'd like to have our application open a .pdf file in the default reader. For Android I managed to get it done by following a two-fold process: (1) copy the file from the Assets folder to the Android device's Downloads folder, and (2) starting an activity to view the file.
I cannot find any similar resources for the iOS. We don't want to use the control in the Xamarin website, as it involves downloading lots of JavaScript (?) code, making the size of the app bigger, and also doesn't support pinching the screen to zoom. We want to use the OS's default pdf reader.
Thank you.
c# ios pdf xamarin assets
I'm using Xamarin iOS. I'd like to have our application open a .pdf file in the default reader. For Android I managed to get it done by following a two-fold process: (1) copy the file from the Assets folder to the Android device's Downloads folder, and (2) starting an activity to view the file.
I cannot find any similar resources for the iOS. We don't want to use the control in the Xamarin website, as it involves downloading lots of JavaScript (?) code, making the size of the app bigger, and also doesn't support pinching the screen to zoom. We want to use the OS's default pdf reader.
Thank you.
c# ios pdf xamarin assets
c# ios pdf xamarin assets
asked Sep 13 '17 at 23:33
MrProgrammer
639
639
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Method 1:
Set the Build Action to BundleResource. You can set the build action for a file by right-clicking on that file and and choosing Build Action in the menu that opens.
Create a UIWebView and add it to a view:
webView = new UIWebView (View.Bounds);
View.AddSubview(webView);
Load the file using NSUrl and NSUrlRequest classes:
string fileName = "Loading a Web Page.pdf"; // remember case-sensitive
string localDocUrl = Path.Combine (NSBundle.MainBundle.BundlePath, fileName);
webView.LoadRequest(new NSUrlRequest(new NSUrl(localDocUrl, false)));
webView.ScalesPageToFit = true;
Method 2:
public void OpenFile (NSUrl fileUrl)
{
var docControl = UIDocumentInteractionController.FromUrl (fileUrl);
var window = UIApplication.SharedApplication.KeyWindow;
var subViews = window.Subviews;
var lastView = subViews.Last ();
var frame = lastView.Frame;
docControl.PresentOpenInMenu (frame, lastView, true);
}
Thanks for the help. It's not compiling, and is offering three solutions: (1a) Fully qualify 'Webclient with Data.Abstractions.WebClient, (1b) Fully qualify 'Webclient with Plugin.WebClient, (2) Generate type 'WebClient,' and (3) Add reference to 'System.dll..' Which one should I use?
– MrProgrammer
Sep 14 '17 at 0:23
The previous code only works on shared project, try it now @MrProgrammer
– Angel Arias González
Sep 14 '17 at 0:59
@MrProgrammer is there some way to scroll webview programmatically ?
– pavel
May 29 at 12:04
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46208297%2fxamarin-ios-how-to-open-a-pdf-file-using-the-default-reader%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Method 1:
Set the Build Action to BundleResource. You can set the build action for a file by right-clicking on that file and and choosing Build Action in the menu that opens.
Create a UIWebView and add it to a view:
webView = new UIWebView (View.Bounds);
View.AddSubview(webView);
Load the file using NSUrl and NSUrlRequest classes:
string fileName = "Loading a Web Page.pdf"; // remember case-sensitive
string localDocUrl = Path.Combine (NSBundle.MainBundle.BundlePath, fileName);
webView.LoadRequest(new NSUrlRequest(new NSUrl(localDocUrl, false)));
webView.ScalesPageToFit = true;
Method 2:
public void OpenFile (NSUrl fileUrl)
{
var docControl = UIDocumentInteractionController.FromUrl (fileUrl);
var window = UIApplication.SharedApplication.KeyWindow;
var subViews = window.Subviews;
var lastView = subViews.Last ();
var frame = lastView.Frame;
docControl.PresentOpenInMenu (frame, lastView, true);
}
Thanks for the help. It's not compiling, and is offering three solutions: (1a) Fully qualify 'Webclient with Data.Abstractions.WebClient, (1b) Fully qualify 'Webclient with Plugin.WebClient, (2) Generate type 'WebClient,' and (3) Add reference to 'System.dll..' Which one should I use?
– MrProgrammer
Sep 14 '17 at 0:23
The previous code only works on shared project, try it now @MrProgrammer
– Angel Arias González
Sep 14 '17 at 0:59
@MrProgrammer is there some way to scroll webview programmatically ?
– pavel
May 29 at 12:04
add a comment |
Method 1:
Set the Build Action to BundleResource. You can set the build action for a file by right-clicking on that file and and choosing Build Action in the menu that opens.
Create a UIWebView and add it to a view:
webView = new UIWebView (View.Bounds);
View.AddSubview(webView);
Load the file using NSUrl and NSUrlRequest classes:
string fileName = "Loading a Web Page.pdf"; // remember case-sensitive
string localDocUrl = Path.Combine (NSBundle.MainBundle.BundlePath, fileName);
webView.LoadRequest(new NSUrlRequest(new NSUrl(localDocUrl, false)));
webView.ScalesPageToFit = true;
Method 2:
public void OpenFile (NSUrl fileUrl)
{
var docControl = UIDocumentInteractionController.FromUrl (fileUrl);
var window = UIApplication.SharedApplication.KeyWindow;
var subViews = window.Subviews;
var lastView = subViews.Last ();
var frame = lastView.Frame;
docControl.PresentOpenInMenu (frame, lastView, true);
}
Thanks for the help. It's not compiling, and is offering three solutions: (1a) Fully qualify 'Webclient with Data.Abstractions.WebClient, (1b) Fully qualify 'Webclient with Plugin.WebClient, (2) Generate type 'WebClient,' and (3) Add reference to 'System.dll..' Which one should I use?
– MrProgrammer
Sep 14 '17 at 0:23
The previous code only works on shared project, try it now @MrProgrammer
– Angel Arias González
Sep 14 '17 at 0:59
@MrProgrammer is there some way to scroll webview programmatically ?
– pavel
May 29 at 12:04
add a comment |
Method 1:
Set the Build Action to BundleResource. You can set the build action for a file by right-clicking on that file and and choosing Build Action in the menu that opens.
Create a UIWebView and add it to a view:
webView = new UIWebView (View.Bounds);
View.AddSubview(webView);
Load the file using NSUrl and NSUrlRequest classes:
string fileName = "Loading a Web Page.pdf"; // remember case-sensitive
string localDocUrl = Path.Combine (NSBundle.MainBundle.BundlePath, fileName);
webView.LoadRequest(new NSUrlRequest(new NSUrl(localDocUrl, false)));
webView.ScalesPageToFit = true;
Method 2:
public void OpenFile (NSUrl fileUrl)
{
var docControl = UIDocumentInteractionController.FromUrl (fileUrl);
var window = UIApplication.SharedApplication.KeyWindow;
var subViews = window.Subviews;
var lastView = subViews.Last ();
var frame = lastView.Frame;
docControl.PresentOpenInMenu (frame, lastView, true);
}
Method 1:
Set the Build Action to BundleResource. You can set the build action for a file by right-clicking on that file and and choosing Build Action in the menu that opens.
Create a UIWebView and add it to a view:
webView = new UIWebView (View.Bounds);
View.AddSubview(webView);
Load the file using NSUrl and NSUrlRequest classes:
string fileName = "Loading a Web Page.pdf"; // remember case-sensitive
string localDocUrl = Path.Combine (NSBundle.MainBundle.BundlePath, fileName);
webView.LoadRequest(new NSUrlRequest(new NSUrl(localDocUrl, false)));
webView.ScalesPageToFit = true;
Method 2:
public void OpenFile (NSUrl fileUrl)
{
var docControl = UIDocumentInteractionController.FromUrl (fileUrl);
var window = UIApplication.SharedApplication.KeyWindow;
var subViews = window.Subviews;
var lastView = subViews.Last ();
var frame = lastView.Frame;
docControl.PresentOpenInMenu (frame, lastView, true);
}
edited Sep 14 '17 at 1:11
answered Sep 13 '17 at 23:57
Angel Arias González
15416
15416
Thanks for the help. It's not compiling, and is offering three solutions: (1a) Fully qualify 'Webclient with Data.Abstractions.WebClient, (1b) Fully qualify 'Webclient with Plugin.WebClient, (2) Generate type 'WebClient,' and (3) Add reference to 'System.dll..' Which one should I use?
– MrProgrammer
Sep 14 '17 at 0:23
The previous code only works on shared project, try it now @MrProgrammer
– Angel Arias González
Sep 14 '17 at 0:59
@MrProgrammer is there some way to scroll webview programmatically ?
– pavel
May 29 at 12:04
add a comment |
Thanks for the help. It's not compiling, and is offering three solutions: (1a) Fully qualify 'Webclient with Data.Abstractions.WebClient, (1b) Fully qualify 'Webclient with Plugin.WebClient, (2) Generate type 'WebClient,' and (3) Add reference to 'System.dll..' Which one should I use?
– MrProgrammer
Sep 14 '17 at 0:23
The previous code only works on shared project, try it now @MrProgrammer
– Angel Arias González
Sep 14 '17 at 0:59
@MrProgrammer is there some way to scroll webview programmatically ?
– pavel
May 29 at 12:04
Thanks for the help. It's not compiling, and is offering three solutions: (1a) Fully qualify 'Webclient with Data.Abstractions.WebClient, (1b) Fully qualify 'Webclient with Plugin.WebClient, (2) Generate type 'WebClient,' and (3) Add reference to 'System.dll..' Which one should I use?
– MrProgrammer
Sep 14 '17 at 0:23
Thanks for the help. It's not compiling, and is offering three solutions: (1a) Fully qualify 'Webclient with Data.Abstractions.WebClient, (1b) Fully qualify 'Webclient with Plugin.WebClient, (2) Generate type 'WebClient,' and (3) Add reference to 'System.dll..' Which one should I use?
– MrProgrammer
Sep 14 '17 at 0:23
The previous code only works on shared project, try it now @MrProgrammer
– Angel Arias González
Sep 14 '17 at 0:59
The previous code only works on shared project, try it now @MrProgrammer
– Angel Arias González
Sep 14 '17 at 0:59
@MrProgrammer is there some way to scroll webview programmatically ?
– pavel
May 29 at 12:04
@MrProgrammer is there some way to scroll webview programmatically ?
– pavel
May 29 at 12:04
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46208297%2fxamarin-ios-how-to-open-a-pdf-file-using-the-default-reader%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown