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.
How to remove PDFDocument margin
2k Views Asked by Spanix Dev At
2
There are 2 best solutions below
0

- To remove the margin: you need to set pageShadowsEnabled to false.
- Change the position: You need to adjust height of the PdfView.
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
}
}
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 aUIEdgeInsets
value.Something like this