Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

swift pdf thumbnail

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 :: swift file size from url 
Swift :: navigationBarTitle text size swiftui 
Swift :: user defaults swift 
Swift :: swift iterate through string 
Swift :: swiftlint 
Swift :: find range of string swift 
Swift :: how to make text selectable swiftui 
Swift :: initialize array with zero in swift 
Swift :: how to recieve hex value from NSData swift 
Swift :: Swift Character Example 
Swift :: Swift for-in Loop 
Swift :: uilabel center text programmatically swift 
Swift :: uikit call swiftui view 
Swift :: swift switch statement 
Swift :: swift reload view 
Swift :: Swift Double 
Swift :: swift 5 flatMap wtih keypath 
Swift :: Swift for Loop inside a while Loop 
Swift :: Swfit Add Elements to an Array 
Swift :: swift reading binary data 
Swift :: Initializer Swift 
Swift :: Generic Function Swift 
Swift :: Typealias for built-in types 
Swift :: swift string pad 
Swift :: Type Constraints in Swift Generics 
Swift :: get device height spritekit 
Swift :: allowed filename characters swift 
Ruby :: activerecord list tables 
Ruby :: rake db:rollback not doing anything 
Ruby :: ruby on rails rollback migration 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =