Search code examples
objective-cprintingnsviewnsprintoperation

How should I print a receipt of a transaction in Objective-C?


I've looked up a couple of documents but I was just hoping to get a general idea here.

I want to be able to print off an invoice once a sale has been made. My client will provide me with a specified paper size, also indicating that the paper will have default info on it (ie company name, address, phone number, etc.)

I'm wondering what the best method would be to print off an invoice that could have many items on it - possibly so many that it goes off of the paper my client provides, necessarily onto a new paper.

Now I've looked into NSView, NSPrintOperation, and NSPrintInfo, which I believe I'll definitely be making use of, but is it possible to draw the view behind the scenes? I'm also questioning the best method to store that receipt locally, as possibly a PDF?


Solution

  • You can make use of NSView , NSPrintInfo and NSPrintOperation. and Yes NSView will take care of drawing while printing. (You can differentiate the context i.e either screen or printer).

    To save as a PDF, have a look at NSPrintOperation methods (PDFOperationWithView:) which helps to create PDF Data that can be saved to disk.