如何仅打印具有不同字体大小的NSTextView? [英] How to have a NSTextView with a different font size just for printing?

查看:76
本文介绍了如何仅打印具有不同字体大小的NSTextView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a NSTextview that only shows good when the text is set to at least 16 in size, but that is too big for printing. How to have a NSTextView with a different font size just for printing ? I have digged into NSPrintInfo but got no result so far. Thanks

推荐答案

下面是一个示例:

// 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()

这篇关于如何仅打印具有不同字体大小的NSTextView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆