【发布时间】:2019-04-02 14:09:56
【问题描述】:
我正在尝试从 HTML 模板生成 PDF 文件。一般来说,除了一件事之外,这种方法效果很好。 当我尝试使用包含在我的包中的自定义字体 AvenirLTStd-Black 时,我在 PDF 中得到空文本,但在 webView 中看起来很好。我也看不到我的捆绑包中的图像。所以我可以假设 UIMarkupTextPrintFormatter 看不到我的字体文件和图像。 我的假设正确吗?有什么解决方法吗?
这是css的一部分:
<style>
@font-face {
font-family: 'AvenirLTStd-Book';
src: url('ChampagneLimousinesItalic.ttf');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'AvenirLTStd-Heavy';
src: url('ChampagneLimousinesItalic.ttf');
font-weight: normal;
font-style: normal;
}
body, html{
margin: 0;
padding: 0;
font-family: 'AvenirLTStd-Book';
font-size: 15px;
}
以及生成代码:
func exportHTMLContentToPDF(HTMLContent: String) { 让 printPageRenderer = CustomPrintPageRenderer()
let printFormatter = UIMarkupTextPrintFormatter(markupText: HTMLContent)
printPageRenderer.addPrintFormatter(printFormatter, startingAtPageAt: 0)
let pdfData = drawPDFUsingPrintPageRenderer(printPageRenderer: printPageRenderer)
pdfFilename = "\(AppDelegate.getAppDelegate().getDocDir())/Invoice\(invoiceNumber!).pdf"
pdfData?.write(toFile: pdfFilename, atomically: true)
print(pdfFilename)
}
【问题讨论】: