1
我有一个NSTextview,只有在文本大小至少设置为16时才显示出来,但对于打印而言太大了。如何使用不同字体大小的NSTextView来打印?我已经深入研究了NSPrintInfo,但到目前为止还没有结果。由于如何使用不同字体大小的NSTextView进行打印?
我有一个NSTextview,只有在文本大小至少设置为16时才显示出来,但对于打印而言太大了。如何使用不同字体大小的NSTextView来打印?我已经深入研究了NSPrintInfo,但到目前为止还没有结果。由于如何使用不同字体大小的NSTextView进行打印?
下面是一个例子:
// 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代码,遗憾的雨燕。如果对你没有用处,我会删除我的答案。 – Moritz 2015-03-31 18:27:09
非常感谢它!我用Objective-C翻译它。 – 2015-03-31 19:16:38