Giter VIP home page Giter VIP logo

pdfpageview's Introduction

PDF Page View

A UIView subclass to display PDF pages

Usage

  1. Copy the PDFPageView.swift source file from the demo app into your Xcode project.

  2. On your Storyboard, add a UIView to one of your view controllers and set the class to PDFPageView.

    • Turn off the Opaque property.
    • Set the Content Mode property appropriately. (Aspect Fit is recommended.)
    • Set the Use Crop Box property appropriately, depending on whether your PDF expects cropping.
      NOTE: Content Mode always positions the content using the crop box, not the media box.
    • Don't forget your layout constraints!

...or do the equivalent in your view controller's loadView() code.

  1. In your view controller's viewDidLoad(), set the page view's .page property to the PDFPage you want to display.
    • You need to import PDFKit at the top of your source file.
    • You need to load your PDF file as a PDFDocument object.

Document Viewer Demo app

  1. Download the entire Xcode project.

  2. Build and run for the Simulator. (Or a real device, if you add your developer license to the project.)

  3. The demo app hosts the PDFPageView in a UIPageViewController, so swipe left and right to turn pages.

If I had to do it all over again...

I'd use a layer hierarchy instead of doing everything directly in the view.

  • Create a CALayer to hold the PDF content.
  • Flip its geometry to match the PDF.
  • Set the bounds of the layer using the size of the media box and the origin of the crop box.
  • Use the .position and .anchorPoint of the layer to implement content gravity, rather than transforms.
  • Only use a scaling transform for the Aspect Fill, Aspect Fit, and Size to Fit content modes.

pdfpageview's People

Contributors

lardieri avatar

Stargazers

 avatar Ferencz Andras avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.