I'm using PDFKit to display simple PDF's. When I display them on the screen inside a UIView, I've used the code below.
Aims: - Start off with the content to fill the view (conforming to aspect ratio) - Not to get bigger than x4 on zooming - Never to get smaller than screen fill size
override func viewDidLoad() {
super.viewDidLoad()
if let path = Bundle.main.path(forResource: "Disclaimer", ofType: "pdf") {
let url = URL(fileURLWithPath: path)
if let pdfDocument = PDFDocument(url: url) {
pdfView.document = pdfDocument
pdfView.autoScales = true
pdfView.maxScaleFactor = 4.0
pdfView.minScaleFactor = pdfView.scaleFactorForSizeToFit
pdfView.displayMode = .singlePageContinuous
pdfView.displaysPageBreaks = false
}
}
self.view.backgroundColor = UIColor.black
}
In storyboard I have set a constraint for UIview to fill full width of the screen - which it does.
Now while most of this works, the original size of the PDF in the UIView is smaller than the UIView. There is a margin around the PDF. I can zoom in and make he Pdf fill the whole screen, before it overflows and scroll bars come into play.
I can't seem to work out how to make the PDF fill the UIView fully. I've tried using .aspectFill but this doesn't change anything. Interestingly, if I make autoScale = false, then the PDF starts off 2x as big as the screen
Would appreciate some help. Thanks in advance
from iOS PDFKit not filling UIView

No comments:
Post a Comment