首页 > 解决方案 > Swift - 以 PDF 格式加载时质量不佳的图像 - 使用 TPPDF

问题描述

使用TPPDF library时,当在 pdf 中加载高质量图像时,图像会变得模糊。

我尝试了所有可能的方法。

这是我的代码:

let coverImage = PDFImage(image: UIImage(named: "Banner")!, quality: 1, options: [.resize])

    //To find proportional width and height
    let imageWidth: CGFloat = coverImage.image.size.width
    let imageHeight: CGFloat = coverImage.image.size.height

    let targetHeight: CGFloat = imageHeight/imageWidth

    print("PdfWidth", pdf.layout.width)
    print("PdfHeight", pdf.layout.height)
    print("TargetHeight", pdf.layout.width*targetHeight)

    print("ImageWidth", coverImage.image.size.width)
    print("ImageHeight", coverImage.image.size.height)

    coverImage.size = CGSize(width: pdf.layout.width, height: pdf.layout.width*targetHeight)
    print("size", coverImage.size)
    pdf.addImage(.contentCenter, image: coverImage)

日志,我得到的是:

PdfWidth 595.0
PdfHeight 842.0
TargetHeight 44.5
ImageWidth 595.0
ImageHeight 44.5
size (595.0, 44.5)

我还尝试添加 8000x600 的高分辨率图像,但图像仍然模糊。

标签: iosswiftpdf

解决方案


推荐阅读