2015-03-31 55 views

回答

2

下面是一個例子:

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

我才意識到你想Objective-C代碼,遺憾的雨燕。如果對你沒有用處,我會刪除我的答案。 – Moritz 2015-03-31 18:27:09

+1

非常感謝它!我用Objective-C翻譯它。 – 2015-03-31 19:16:38