2016-06-02 8 views
2

UIViewをPDFファイルに変換して印刷するにはA4用紙サイズに合わせるアプリケーションを開発中です。a4に合わせてUIVIewを調整する方法用紙サイズ

UIViewをA4用紙サイズに合わせるにはどうすればよいですか?

私はUIViewをA4ページに完全に収めました。

+0

A4サイズのスクロールビューでビューを追加します。用紙サイズのフレーム。 –

+0

UIGraphicsBeginPDFContextToFileを使用してPDFに変換して印刷します。 http://stackoverflow.com/q/11809133/742298 –

+0

UIVIewをA4サイズに調整する用紙サイズ –

答えて

1

あなたはより多くの詳細については、何かのように、

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) 
    } 
} 

読むthis articleを変換することができ、どのように異なるサイズでそれをレンダリングすることを知っています。

+0

のリンクで示唆されているようにこれは完璧ですが、これはA4に収まるようにUIVIewをスケールしません。用紙サイズ –

関連する問題