Open a PDF with the built in PDF Viewer?

CodeMonkeyCodeMonkey GBMember ✭✭✭

Is it possible to open a pdf using the built in PDF viewer? The same one that is used if I open a PDF from my iBooks?

Cheers

Posts

  • prashantvcprashantvc USXamarin Team Xamurai

    Hi Adrian,

    Yes it is possible to open PDF (or any other supported file types) with built in viewers, the UIDocumentInteractionController help us to do so.
    Here's the sample code that you could refer.

    partial void OpenFie (NSObject sender)
    {
        string path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
        string filePath = Path.Combine(path, "sample.pdf");
        var viewer = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(filePath));
        viewer.PresentOpenInMenu(new RectangleF(0,-260,320,320),this.View, true);
    }
    
  • CodeMonkeyCodeMonkey GBMember ✭✭✭

    Sorry, I forgot the most important bit, can it be done without having to leave the app?

  • CharlieMcKeeganCharlieMcKeegan GBBeta, University ✭✭

    UIWebView will open a PDF (and other documents) its functional but nowhere near as slick as iBooks. For that you would need to look at something like PSPDFKit.

  • CodeMonkeyCodeMonkey GBMember ✭✭✭

    We really need to use the built in viewer unfortunately, else I would be using this:

    https://github.com/AlexanderMac/mTouch-PDFReader

  • prashantvcprashantvc USXamarin Team Xamurai

    @CodeMonkey There is no out of the box PDF viewer available in the iOS SDK, you could implement your own viewer or use one of the existing third party viewers like the one you mentioned. You can refer this Stack Overflow question for alternate options.

  • CodeMonkeyCodeMonkey GBMember ✭✭✭

    @prshnt Is there a way I could tell the PDF viewer to include a back button in its navigation bar so that the user could navigate back to my app without having to access the 'running apps' drawer?

    We really just want to prevent them from having to double tap the home button and select our app.

  • prashantvcprashantvc USXamarin Team Xamurai

    @CodeMonkey, if you are building PDF viewer app you can make use custom URL schemes to switch back to your app.

  • CodeMonkeyCodeMonkey GBMember ✭✭✭

    @prshnt Sorry but could you elaborate?

    My requirement is only to select a PDF file from within my app, view that PDF using the native pdf viewer, and show a back button which will return the user to my app.

    I am trying to not write any custom PDF viewer code, including print functionality which is why I want to use the native viewer.

  • CodeMonkeyCodeMonkey GBMember ✭✭✭

    When you say custom URL schemes, does this mean including specific markup as part of the PDF location URL which will tell the PDF viewer to include a back button and where to take the user when they click that back button?

  • prashantvcprashantvc USXamarin Team Xamurai
    edited December 2012

    I apologise, I could have elaborated it.

    By binding the custom URL scheme to your app, you enable other apps/browser to launch your app. You can find more details here on Apple documentation http://bit.ly/H9tIf9 ("Communicating with Other Apps" section). But I don't think there is any way you could tell native PDF viewer to include back button to navigate back to your app.

  • CodeMonkeyCodeMonkey GBMember ✭✭✭

    Does anyone have any suggestion for a reliable efficient library for displaying PDF's which has a monotouch binding? We also need to display Word and Powerpoint documents so if this was included that would be great!

  • JasonAwbreyJasonAwbrey USInsider, University, Developer Group Leader mod

    iOS has two native ways that you can display PDF and Word documents in your app - UIDocumentInteractionController class or QLPreviewController class. You can also use a UIWebView if you just want to display a PDF. I don't think there is native support for PowerPoint.

  • AlexSotoAlexSoto MXXamarin Team Xamurai

    PSPDFKit its a really powerful option I recommend you to give it a try, you can find MonoTouch Bindings here and if you need some help with it just ask :)

  • CodeMonkeyCodeMonkey GBMember ✭✭✭

    After much googling, and then testing we have decided to go with PSPDFKit using the binding dalexsoto mentioned, it really is a very powerful library and worth every cent.

  • StavrosMenegosStavrosMenegos GRBeta, University ✭✭

    Is there any monotouch bindings for the vfr reader which is a good alternative to PSPDFKit?

  • MarketAllyMarketAlly USMember ✭✭

    I am unsure why PDF seems to have held the coveted "No Royalty Free" version and the industry seems to accept this.

  • mubimubi USMember ✭✭✭

    @prashantvc said:
    Hi Adrian,

    Yes it is possible to open PDF (or any other supported file types) with built in viewers, the UIDocumentInteractionController help us to do so.
    Here's the sample code that you could refer.

    partial void OpenFie (NSObject sender)
    {
    string path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
    string filePath = Path.Combine(path, "sample.pdf");
    var viewer = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(filePath));
    viewer.PresentOpenInMenu(new RectangleF(0,-260,320,320),this.View, true);
    }

    this solution not working for me
    Its very unclear and code showing bugs
    Someone please rewrite this code for me in a class inherited by contentPage and also the placing of file

  • FaaizFaaiz USMember ✭✭

    https://github.com/Krumelur/MonoTouch-PSPDFKit-bindings
    This link is down. Any work around guys?
    I wanted to view a PDF file within app. Also I need the current page (which user is viewing) and total pages of pdf. Thanks in advance.

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    That link was a third party's binding of the PSPDFKit SDK. Can't say why they removed it, but that post was from 2012.

    The only "workaround" I can think of is to get the PSPDFKit SDK and do the binding yourself.

  • ZainJafriZainJafri USMember ✭✭

    @prashantvc said:
    Hi Adrian,

    Yes it is possible to open PDF (or any other supported file types) with built in viewers, the UIDocumentInteractionController help us to do so.
    Here's the sample code that you could refer.

    partial void OpenFie (NSObject sender)
    {
    string path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
    string filePath = Path.Combine(path, "sample.pdf");
    var viewer = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(filePath));
    viewer.PresentOpenInMenu(new RectangleF(0,-260,320,320),this.View, true);
    }

    Hi,
    this code is not working now. Can you plz tell what are the necessary changes that needs to be done ?

Sign In or Register to comment.