首页 > 解决方案 > TPPDF (iOS) - 页脚部分的图像显示超出页面边界

问题描述

我正在显示一个示例 pdf,其中包含页眉图像、页脚图像和中间的一些内容。(库 - https://github.com/techprimate/TPPDF

页眉图像显示正常,但页脚图像显示在页面底部边界下方。

这是代码:

var layout = PDFPageLayout()
layout.margin = UIEdgeInsets(top: 30, left: 30, bottom: 30, right: 30)
layout.size = PDFPageFormat.a4.size
layout.space.header = 30
let document = PDFDocument(layout: layout)

let headerImage = UIImage(named: "header")!
let headerImageElement = PDFImage(image: headerImage)
headerImageElement.quality = 1.0
headerImageElement.options = [.none]
document.addImage(.headerCenter, image: headerImageElement)

for i in 1...100 {
    document.addText(.contentCenter, text: "Content goes here. \(i)")
}

let footerImage = UIImage(named: "footer")!
let footerImageElement = PDFImage(image: footerImage)
footerImageElement.quality = 1.0
footerImageElement.options = [.none]
document.addImage(.footerCenter, image: footerImageElement)

do {
    var docURL = try PDFGenerator.generateURL(document: document, filename: "Example.pdf")
    let request = NSURLRequest(url: docURL);
    webView.load(request as URLRequest);
}
catch {
    print("error loading PDF")
}

输出如下(未显示页脚图像):

在此处输入图像描述

现在,如果我将底部边距插图增加到 150 左右,即

layout.margin = UIEdgeInsets(top: 30, left: 30, bottom: 150, right: 30)

页脚图像开始显示,但页脚图像和内容之间存在很大差距。

在此处输入图像描述

注意:页脚图像内部没有任何空白。

我在这里有什么遗漏吗?

标签: iosswift

解决方案


推荐阅读