简体   繁体   English

如何缩放UIVIew以适应a4纸张尺寸

[英]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.

相关问题 缩放 CGPath 以适应 UIVIew - Scale CGPath to Fit UIVIew 使用原始尺寸的图像创建A4尺寸纸张的PDF - Create PDF of A4 size paper with images of original sizes 使用UIPrintInteractionController打印完整的A4纸需要什么图像尺寸? - What image size need to print a full A4 paper with UIPrintInteractionController? 设置 UIView 大小以适合子视图 - Set UIView size to fit subViews 在UIView上缩放字体大小UITextView - Scale font size UITextView on UIView 如何将iframe视频缩放到较小尺寸以适合iOS中的UIWebView框架? - How to scale iframe video to smaller size to fit UIWebView frame in iOS? 在方向更改时自动缩放UIView,以按比例缩放以适合父视图 - Scale a UIView automatically on orientation change to scale proportionaltely to fit in parent view "如何在保持纵横比的同时缩放 UIView 的内容以适应目标矩形?" - How To Scale The Contents Of A UIView To Fit A Destination Rectangle Whilst Maintaining The Aspect Ratio? 使用动画更改UIView大小而不缩放 - Change UIView size without scale with animation 调整 UIView 的大小以适合 uiScrollView 中的所有内容 - Size a UIView to fit all of its contents in a uiScrollView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM