gpt4 book ai didi

objective-c - 如何让 NSTextView 具有不同的字体大小仅用于打印?

转载 作者:行者123 更新时间:2023-12-03 17:02:18 25 4
gpt4 key购买 nike

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

最佳答案

这是一个例子:

// 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 - 如何让 NSTextView 具有不同的字体大小仅用于打印?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29375189/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com