Currently I’m writing an app for OSX which will eventually need to be ported to iOS.
The data that needs to be printed is being drawn via CoreGraphics into a PDF context – that is working perfectly.
I’ve been reading the Apple dev documentation on printing in both iOS and OSX, and, ironically, it actually seems printing from iOS will be easier.
On iOS, UIPrintInteractionController‘s printingItem property can take an NSData object containing PDF data and print that. Looks like it should be fairly straight-forward.
OSX on the other hand, (looks like it) requires using the NSPrintOperation class – but it seems the only way to get data into an instance is via an NSView. (+printOperationWithView: or +printOperationWithView:printInfo:).
Seeing as the content is formatted and paginated already it seems rather pointless to have to re-draw the PDF data to something like an NSView.
Could there possibly be another way of achieving this that I’ve missed?
This code is by no means complete, but for anyone who comes across this later, this is basically how you can print directly from an NSData stream:
(via Core Printing Reference)
Beware this code lacks memory management so you will need to use the
PMRetain()andPMRelease()functions as well as the CoreFoundation memory-management functions as well.If anyone can tell me how I can get data from the OSX print dialogue into data I can use in this method I’ll accept their answer instead of this. That is, without using Carbon functions.