I have an app that captures an image and converts it to pdf. It is then displayed in a PDFView. However, the PDF does not fit into the dimensions of my PDFView. How do I scale the pdf to fit the PDFView?
When the image is selected from imagePickerController the following function is executed:
// OUTLETS
@IBOutlet weak var myPDFView: PDFView!
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
print("image selected ...")
// Get picked image info dictionary
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
// Add captured and selected image to your Photo Library
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
// Create PDFDocument object and display in PDFView
let document = createPDFDataFromImage(image: image)
myPDFView.document = document
myPDFView.scaleFactorForSizeToFit
// Dimiss imagePicker
dismiss(animated: true, completion: nil)
}
func createPDFDataFromImage(image: UIImage) -> PDFDocument{
let document = PDFDocument.init()
let imagePDF = PDFPage.init(image: image)
document.insert(imagePDF!, at: 0)
return document
}