Reputation: 111
I add pdfdocument to the PDFView . but it is showing margin and also showing in the canter. How to remove this margin . And Is there any way to set pdfdocument to the top-left position.
Upvotes: 4
Views: 2220
Reputation: 199
I think this would help with the problem.
https://developer.apple.com/documentation/pdfkit/pdfview/2881210-pagebreakmargins
Just set a value to this variable pageBreakMargins
by passing a UIEdgeInsets
value.
Something like this
self.pdfView.pageBreakMargins = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
Upvotes: 8
Reputation: 5052
Here is the sample code:
private func openPdf() {
let pdfView = PDFView(frame: CGRect(x: 0, y: 20, width: self.view.frame.width, height: self.view.frame.height))
view.addSubview(pdfView)
guard let path = Bundle.main.url(forResource: "test", withExtension: "pdf") else { return }
if let document = PDFDocument(url: path) {
pdfView.document = document
pdfView.pageShadowsEnabled = false
pdfView.displayMode = .singlePage
pdfView.autoScales = true
pdfView.frame.size.height = pdfView.documentView?.frame.height ?? self.view.frame.height
self.view.layoutIfNeeded()
pdfView.minScaleFactor = pdfView.scaleFactorForSizeToFit
}
}
Output: With margin and without margin.
Upvotes: 1