Junaid Noor
Junaid Noor

Reputation: 474

Printing PDF on OSX

i am working in unity and i have a task of creating and then printing pdf from some of the snapshots taken through cameras in unity.

On windows after creating the pdf that can easily be done by calling the ShellExecute function and passing print as the parameter or using a function posted on stackoverflow i.e:

private void SendToPrinter()
{
    ProcessStartInfo info = new ProcessStartInfo();
    info.Verb = "print";
    info.FileName = @"c:\output.pdf";
    info.CreateNoWindow = true;
    info.WindowStyle = ProcessWindowStyle.Hidden;

    Process p = new Process();
    p.StartInfo = info;
    p.Start();

    p.WaitForInputIdle();
    System.Threading.Thread.Sleep(3000);
    if (false == p.CloseMainWindow())
        p.Kill();
}

, but i have no clue at all how would i be able to achieve the same for the OSX build?

Any help will be really appreciated.

Upvotes: 0

Views: 677

Answers (1)

user3821934
user3821934

Reputation:

  1. You need to look at Apple's "Printing Programming Guide for Mac". (https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Printing/osxp_aboutprinting/osxp_aboutprt.html)

  2. To print a PDF page, you need a CGContextRef. In your views drawRect: method, you can get the the correct graphics context like this:

    CGContextRef myContext = [[NSGraphicsContext currentContext] graphicsPort];

  3. The method you use to draw a PDF page into a context is CGContextDrawPDFPage(context,page);

  4. The easiest way to open a PDF document is to use CGPDFDocumentCreateWithURL

  5. You get the pages using CGPDFDocumentGetPage.

Upvotes: 1

Related Questions