How I can show/display pdf document to full screen on pdfView?
Asked Answered
T

1

0

I took pdfView, and I am trying to load pdf document on this pdfView. Pdf is not displaying/showing full screen w.r.t its pdfView as I added in storyboard. It has some gaps from top and bottom. (see the gray colour in pdf) Here is the screenshot,

enter image description here

Here is the code I wrote for this,

     func loadPdf(documentsURL:String){

       if let pdfDocument = self.createPdfDocument(forFileName: documentsURL) {
        
        self.pdfView.document = pdfDocument
        
        pdfView.autoresizesSubviews = true
        pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight, .flexibleTopMargin, .flexibleLeftMargin]
        pdfView.displayDirection = .vertical
        pdfView.autoScales = true
        pdfView.displayMode = .singlePage//.singlePageContinuous
        pdfView.displaysPageBreaks = true
        pdfView.maxScaleFactor = 4.0
        pdfView.minScaleFactor = pdfView.scaleFactorForSizeToFit
        pdfView.usePageViewController(true, withViewOptions: [:])
        self.pdfView.backgroundColor = UIColor.gray
      }
    }

How I can remove that extra space from top and bottom and make/show/display that pdf document to full to screen w.r.t pdfView which I added in storyboard that same size.

Any solution for this?

Here is the complete project

Tredecillion answered 16/2, 2021 at 5:17 Comment(4)
What happens if you take out the line: pdfView.usePageViewController(true, withViewOptions: [:])Headpin
it will allow me to go next page of pdf. If I don't write it, then there is no option to goto next page of pdfTredecillion
and in my case, only single page is needed to show on pdfview at one time, if he wants to go to next screen then he can scroll up then it will goto next pageTredecillion
I think that is causing the issue. Note how the space it takes up is the same as the gaps at the top/bottom. Basically causing a ‘border’ around the pdf. Maybe add a swipe action to the pdf to allow moving between pages, and remove that code to enlarge pdf to full screenHeadpin
L
0

You can use webView for show .pdf on fullscreen you can show url and local file both

let url : NSURL! = NSURL(string: "http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIWebViw_Class/UIWebView_Class.pdf") 
webView.loadRequest(NSURLRequest(URL: url))

and for local file you can use

 let pdf = NSBundle.mainBundle().URLForResource("myPDF", withExtension: "pdf", subdirectory: nil, localization: nil)  
        let req = NSURLRequest(URL: pdf)
        webView.loadRequest(req)
        
    
Lichter answered 16/2, 2021 at 6:32 Comment(1)
in my case webView is not applicable. I am doing some extra operations on pdf view.Tredecillion

© 2022 - 2024 — McMap. All rights reserved.