【问题标题】:How to have a NSTextView with a different font size just for printing?如何使用不同字体大小的 NSTextView 仅用于打印?
【发布时间】:2015-03-31 17:51:10
【问题描述】:

我有一个 NSTextview,仅当文本设置为至少 16 时才会显示良好,但这对于打印来说太大了。如何使用不同字体大小的 NSTextView 仅用于打印?我已经深入研究了 NSPrintInfo 但到目前为止还没有结果。谢谢

【问题讨论】:

    标签: objective-c cocoa nstextview


    【解决方案1】:

    这是一个例子:

    // Create another text view just for printing
    var printTextView = NSTextView(frame: NSMakeRect(0, 0, 528, 688)) // A4
    // Add a modified version of your attributed string to the view
    printTextView.textStorage!.mutableString.appendString(myAttributedStringWithAdjustedSize)
    // Get printing infos
    let sharedInfo = NSPrintInfo.sharedPrintInfo()
    let sharedDict = sharedInfo.dictionary()
    let printInfoDict = NSMutableDictionary(dictionary: sharedDict)
    printInfoDict.setObject(NSPrintSpoolJob, forKey: NSPrintJobDisposition)
    let printInfo = NSPrintInfo(dictionary: printInfoDict)
    // Set some preferences
    printInfo.horizontallyCentered = true
    printInfo.verticallyCentered = false
    printInfo.scalingFactor = 0.8
    // Print the custom text view
    let op = NSPrintOperation(view: printTextView, printInfo: printInfo)
    op.runOperation()
    

    【讨论】:

    • 我刚刚意识到你想要 Objective-C 代码,对不起 Swift。如果对您没有用,我会删除我的答案。
    猜你喜欢
    • 2014-08-24
    • 2017-09-29
    • 2012-04-20
    • 1970-01-01
    • 1970-01-01
    • 2012-08-30
    • 2015-12-02
    • 1970-01-01
    • 2014-10-21
    相关资源
    最近更新 更多