open a .PDF file in PDF reader

Discussion in 'Mac Programming' started by Monaj, Jul 20, 2009.

  1. macrumors regular

    Joined:
    May 24, 2009
    Messages:
    193
    #1
    In cocoa how can I open a .PDF file in a PDF reader?
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Messages:
    3,172
    Location:
    Dallas, TX
    #2
    Launch Services

    The terminal app "open" will do the same, but it's probably "cleaner" to use launch services.

    -Lee
     
  3. macrumors regular

    Joined:
    May 24, 2009
    Messages:
    193
    #3
    Thank you Lee for your quick reply ... but I think you did not get me .. I want something like this:

    -(IBAction)openPDFAction:(id)sender{
    // code for opening a .PDF file in PDF reader
    }

    I don't know which code to use :confused:
     
  4. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Messages:
    3,172
    Location:
    Dallas, TX
    #4
    Let's say you have a fixed path:
    Code:
    struct FSRef myRef;
    OSStatus myStatus = FSPathMakeRef("/my/path/to/thisPDF.pdf",&myRef,NULL);
    //Check myStatus
    myStatus = LSOpenFSRef(&myRef,NULL);
    //Check myStatus
    
    The NULL values are optional parameters that I didn't use to keep it simple. The one in FSPathMakeRef would be a Boolean * that would contain whether or not the path is a directory on return. The NULL in LSOpenFSRef would be a FSRef * that would contain the opening program if you needed to know on return.

    -Lee
     
  5. macrumors 6502a

    GorillaPaws

    Joined:
    Oct 26, 2003
    Messages:
    923
    Location:
    Richmond, VA
    #5
    Just to clarify, are you asking how to open a .pdf file with the user's default application for .pdf's? or are you asking about how to implement PDFView and/or PDFKit into your app?
     
  6. macrumors regular

    Joined:
    May 24, 2009
    Messages:
    193
    #6
    how to open a .pdf file with the user's default application for .pdf's
     

Share This Page