[英]How to scale UIVIew to fit in a4 Paper size
I am developing application to convert UIView
to PDF file and fit it into A4 paper size to print. 我正在开发应用程序将
UIView
转换为PDF文件并将其装入A4纸张尺寸进行打印。
How can I scale any UIView
to fit into A4 paper size? 如何缩放任何
UIView
以适合A4纸张尺寸?
I ned my UIView
to completely fit into an A4 page. 我的
UIView
完全适合A4页面。
you can convert something like, 你可以转换像,
func createPdfFromView(aView: UIView, saveToDocumentsWithFileName fileName: String)
{
let pdfData = NSMutableData()
UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil)
UIGraphicsBeginPDFPage()
guard let pdfContext = UIGraphicsGetCurrentContext() else { return }
aView.layer.renderInContext(pdfContext)
UIGraphicsEndPDFContext()
if let documentDirectories = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first {
let documentsFileName = documentDirectories + "/" + fileName
debugPrint(documentsFileName)
pdfData.writeToFile(documentsFileName, atomically: true)
}
}
Read this article for more details and to know that how to render it in different sizes. 阅读本文以获取更多详细信息,并了解如何以不同的大小呈现它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.