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

4
  • What happens if you take out the line: pdfView.usePageViewController(true, withViewOptions: [:]) Commented Mar 25, 2021 at 7:46
  • 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 pdf Commented Mar 25, 2021 at 12:59
  • 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 page Commented Mar 25, 2021 at 13:02
  • 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 screen Commented Mar 25, 2021 at 21:00

1 Answer 1

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)
        
    
Sign up to request clarification or add additional context in comments.

1 Comment

in my case webView is not applicable. I am doing some extra operations on pdf view.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.