     var document: Document?
     
     let userDeaults = UserDefaults.standard
+    
+    var portraitScaleFactorForSizeToFit: CGFloat = 0.0
+    var landscapeScaleFactorForSizeToFit: CGFloat = 0.0
     
 //    縦書き
     var verticalWriting = false

                    if self.verticalWriting {
                        // ページ交換ファンクションを利用して、降順ソートして置き換える。
                        let actionCount = document.pageCount/2
                        for i in 0...actionCount{
                            document.exchangePage(at: i, withPageAt: document.pageCount-i)
                        }
                    }

                    self.moveToLastReadingProsess()
                }
            } else {
                // Make sure to handle the failed import appropriately, e.g., by presenting an error message to the user.

        self.document?.close(completionHandler: nil)
    }
    
    @objc func didChangeOrientationHandler() {
        if portraitScaleFactorForSizeToFit != 0.0 && UIApplication.shared.statusBarOrientation.isPortrait {
            pdfView.minScaleFactor = portraitScaleFactorForSizeToFit
            pdfView.scaleFactor = portraitScaleFactorForSizeToFit
        } else if landscapeScaleFactorForSizeToFit != 0.0 && UIApplication.shared.statusBarOrientation.isLandscape {
            pdfView.minScaleFactor = landscapeScaleFactorForSizeToFit
            pdfView.scaleFactor = landscapeScaleFactorForSizeToFit
        }
    }
    
    @IBAction func dismissDocumentViewController() {
        dismiss(animated: true) {
            self.saveAndClose()
