1

I have set the following code:

let printInfo = NSPrintInfo.sharedPrintInfo
let textPrint = NSPrintOperation(view: theTextView,printInfo: printInfo())

Now I would like to set the orientation to Landscape, but I can't find any Swift functions that do this.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
TMan
  • 11
  • 2

2 Answers2

2

This is what I'm using. The NSView is called drawing.

let pinfo = NSPrintInfo.shared()
pinfo.orientation = .landscape
pinfo.bottomMargin = 0.0
pinfo.topMargin = 0.0
pinfo.leftMargin = 0.0
pinfo.rightMargin = 0.0
drawing!.print(self)
0

Try this:

let pmPageFormat = printInfo.PMPageFormat()
PMSetOrientation(pmPageFormat, kPMLandscape, kPMUnlocked)
printInfo.updateFromPMPageFormat()
Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • I tried this but get the following compile errors: () -> NSPrintInfo' does not have a member named 'PMPageFormat' , also '() -> NSPrintInfo' does not have a member named 'updateFromPMPageFormat' – TMan Aug 13 '15 at 15:09
  • The first line of your code is missing parentheses. It should be `let printInfo = NSPrintInfo.sharedPrintInfo()`. You were getting a reference to the function rather than calling the function and getting its result. Of course, you then should **not** have parenthesis when passing the `printInfo` on your next line. Pass `printInfo`, not `printInfo()`. – Ken Thomases Aug 13 '15 at 15:29
  • Thanks, I did miss the parentheses, However, I still get the Cannot invoke 'PMSetOrientation' with an argument list of type '(() UnsafeMutablePointer, Int, Int)' in the PMSetOrientation(pmPageFormat, kPMLandscape, kPMUnlocked) statement – TMan Aug 15 '15 at 09:57
  • Did you include the parentheses in the first line of my code when you copied it? – Ken Thomases Aug 15 '15 at 11:49
  • Yes. Here is all the code: let printInfo = NSPrintInfo.sharedPrintInfo() let textPrint = NSPrintOperation(view: theTextView,printInfo: printInfo) let pmPageFormat = printInfo.PMPageFormat PMSetOrientation(PMCreatePageFormat(pmPageFormat, kPMLandscape, kPMUnlocked) – TMan Aug 16 '15 at 11:30
  • Right, you've forgotten the parentheses at the end of `let pmPageFormat = printInfo.PMPageFormat()`. Also, you should set the orientation before creating the `NSPrintOperation`, just to be sure. – Ken Thomases Aug 16 '15 at 14:45
  • I already tried that with the same compile error. This may be an apple problem. – TMan Aug 18 '15 at 11:21