PDFKit正在垂直翻转用图像初始化的PDFPage [英] PDFKit is vertically flipping PDFPage initialised with image

查看:80
本文介绍了PDFKit正在垂直翻转用图像初始化的PDFPage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知道这是不是一个错误,因为PDFKit在iOS的Beta中,但是当我基于图像数组(使用PDFPage(image :))创建PDFDocument时,它将垂直翻转图像.

Not sure if this is a bug as PDFKit is in Beta on iOS, but when I create a PDFDocument based on an array of images (using PDFPage(image:), it flips the image vertically.

@IBAction func export(_ sender: Any){
    let apdf = PDFDocument()
    var i = 0
    while i < arrayOfImages.count{
        let image = arrayOfImages[i]
        let pdfpage = PDFPage(image: image)
        apdf.insert(pdfpage!, at: i)
        i = i + 1
    }
    //Code for sharing the PDF Document
    let objectsToShare = [apdf.dataRepresentation()]
    let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)

    activityVC.popoverPresentationController?.sourceView = view
    self.present(activityVC, animated: true, completion: nil)
}

输出是这样的:

应该是这样:

我100%确保不会翻转源图像,因为它们已在应用程序的其他位置使用.您可以设置PDFPage的旋转度,但是看不到任何手动将其翻转回去的方法.

I am 100% sure that the source images are not flipped because they are used elsewhere in the app. You can set the rotation of a PDFPage but I can't see any way to manually flip it back.

推荐答案

对此错误(?)的一种(不好的)解决方案是提前垂直翻转图像,以使其向后翻转:

One (bad) solution to this bug (?) is to flip the image vertically in advance so it gets flipped back:

let img = arrayOfImages[i]
let image = UIImage(cgImage: img.cgImage!, scale: img.scale, orientation: .downMirrored)
let pdfpage = PDFPage(image: image)

这篇关于PDFKit正在垂直翻转用图像初始化的PDFPage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆