Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

PDF Preview in Swift iOS

import UIKit
import PDFKit

class ViewController: UIViewController {

    @IBOutlet var pdfView: PDFView!

    override func viewDidLoad() {
        super.viewDidLoad()

        if let path = Bundle.main.path(forResource: "sample", ofType: "pdf") {
            if let pdfDocument = PDFDocument(url: URL(fileURLWithPath: path)) {
                pdfView.displayMode = .singlePageContinuous
                pdfView.autoScales = true
                pdfView.displayDirection = .vertical
                pdfView.document = pdfDocument
            }
        }
    }
}
Comment

swift pdf preview image

import PDFKit

func pdfThumbnail(url: URL, width: CGFloat = 240) -> UIImage? {
  guard let data = try? Data(contentsOf: url),
  let page = PDFDocument(data: data)?.page(at: 0) else {
    return nil
  }

  let pageSize = page.bounds(for: .mediaBox)
  let pdfScale = width / pageSize.width

  // Apply if you're displaying the thumbnail on screen
  let scale = UIScreen.main.scale * pdfScale
  let screenSize = CGSize(width: pageSize.width * scale, 
                          height: pageSize.height * scale)

  return page.thumbnail(of: screenSize, for: .mediaBox)
} 
Comment

PREVIOUS NEXT
Code Example
Swift :: rxswift combine two observables 
Swift :: HOW TO KNOW IPHONE BETTRY CHARGE IN SWIFTUI 
Swift :: swift make condition that you are in sumulator 
Swift :: init with bindings swiftui 
Swift :: set white place holder color in swift 
Swift :: add shadow to specific corner of UIView with shadow swift 6 site:stackoverflow.com 
Swift :: navigationbarhidden not working swiftui 
Swift :: average in array swift 
Swift :: swift array remove 
Swift :: convert image to base64 swift Ui 
Swift :: swiftui foreach enum not all cases 
Swift :: Swift Closures as Function Parameter 
Swift :: swift extension Array with type 
Swift :: swift 5 change message color of alert 
Swift :: How to remove the last item from an array in swift 
Swift :: swift array map example 
Swift :: how to send a file from file manager in mail swift 
Swift :: Swift nal Within The Same Module 
Swift :: Customize indicator view iOS swift 
Swift :: swift loop through array of objet 
Swift :: Swift convenience Initializer 
Swift :: rust How to pass out parameter to function from Swift FFI 
Swift :: continue keyword in swift language 
Swift :: swift 5 uidatepicker display inline 
Swift :: Swift Find Number of Array Elements 
Swift :: declare multiple variables at once in swift 
Swift :: remove child from scene swift 
Swift :: cifilter image preserve orientation 
Ruby :: how to delete a table in rails 
Ruby :: rails status migrations 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =