PSPDFKit in rubymotion

Update

If you’re using Bundler, you can simply add gem ‘pspdfkit’ to your Gemfile. See more on https://github.com/tmeinlschmidt/rm-pspdfkit


As I’ve started using this famous framework, I’d like to use it in my rubymotion application. So, there’s my setup to include this fmw in rubymotion project

  • extract PSPDFKit anywhere
  • create directory vendor  in your RM project
  • create symbolic link from your unzipped PSPDFKit to vendor/PSPDFKit.framework
cd vendor
ln -s ../../pdf/Products/PSPDFKit.embeddedframework/PSPDFKit.framework ./
cd ../resources
ln -s ../../pdf/Products/PSPDFKit.embeddedframework/Resources/PSPDFKit.bundle ./

and modify Rakefile accordingly

app.vendor_project('vendor/PSPDFKit.framework', :static, products: ['PSPDFKit'], headers_dir: 'Headers')

app.libs << '/usr/lib/libz.1.1.3.dylib'

app.frameworks += %w(MessageUI AssetsLibrary MediaPlayer PSPDFKit)

try rake , it should link and start simulator.

Next step

Add some PDF file into your app resources  folder.

And then you can try to modify app/app_delegate.rb  with simple example:

class AppDelegate
  def application(application, didFinishLaunchingWithOptions:launchOptions)

    documentURL = NSBundle.mainBundle.resourceURL.URLByAppendingPathComponent "DevelopersGuide.pdf"
    @document = PSPDFDocument.PDFDocumentWithURL documentURL

    pdfController = PSPDFViewController.alloc.initWithDocument @document
    navController = UINavigationController.alloc.initWithRootViewController pdfController

    @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
    @window.makeKeyAndVisible

    @window.rootViewController = navController
  end
end

4 thoughts on “PSPDFKit in rubymotion

  1. Hey Tom – thanks for this. Really quite helpful for me.

    One question – how would go able about enabling the options – such as print & annotations?

  2. Hi Matt,
    you have to check examples in PSPDFKit (PSPDFCatalog/Annotations). This gem is only for enabling PSPDFKit in RubyMotion application, doesn’t provide any other functionality (maybe later I’ll write some wrapper around PSPDFKit)

    tom

  3. Hi, I appreciate the information and efforts which you offered.
    About this article, which version did you use PSPDFKit?
    I have tried with version 1 of PSPDFKit, but error has occurred as below:
    2013-04-12 05:03:18.636 test01[11042:c07] *** Terminating app due to uncaught exception ‘NSRangeException’, reason: ‘Cannot remove an observer for the key path “selectedSegmentIndex” from because it is not registered as an observer.’

    Please let me know your advise.

  4. Hi, I have tried with version2 demo of PSPDFKit, and I could get correct result.
    So please remove posted comments by me.
    Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *

9 × = 27