Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

macos - How to export a view to PDF in OS X?

In OS X 10.9, Apple introduced a simple way to export user content as PDF. The menu item called 'Export as PDF' is used to present a save sheet to export the data. (A example for this is Safari) In its WWDC Videos Apple showed how it works, but my solution doesn't seem to be right. I am using a non-document based app.

I have managed to get the save sheet so far, but with my current code, I get the print sheet as well after that. Furthermore, no data is saved so far.

Here is my code:

NSPrintOperation* printOP = [NSPrintOperation printOperationWithView:_textView];
printOP.printInfo.jobDisposition = NSPrintSaveJob;
[printOP runOperationModalForWindow:_window 
                           delegate:nil didRunSelector:nil contextInfo:nil];

What am I doing wrong?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

From NSView Class Reference:

dataWithPDFInsideRect:
Returns PDF data that draws the region of the receiver within a specified rectangle.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...