Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get dimensions and load PDF Page?

I have a single PDF page in Swift Xcode iOS,

let page = self.pdfDocument!.page(at: page_index!)!

and I wish to get the dimensions of the page. When I create a breakpoint on the code above, I can see just the PDF. How can I get the width and height of my PDF page and its relative location on my screen (x, y) from top left?

In addition, I wish to load this single page (not the entire pdfDocument) into QuickLookPreviewContainer. How can I get a NSURL of this page with the code above?

Thanks in advance.

like image 846
Galen BlueTalon Avatar asked Oct 16 '25 15:10

Galen BlueTalon


1 Answers

You can get a page dimension for PDFPage doing the following:

let page = self.pdfDocument!.page(at: page_index!)!
let bounds = page?.bounds(for: PDFDisplayBox.mediaBox)
let size = bounds?.size
like image 190
Lew Winczynski Avatar answered Oct 18 '25 04:10

Lew Winczynski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!