PDA

View Full Version : Saving NSView Content As A PDF




Blakeasd
May 10, 2011, 06:39 PM
Hello,
I am attempting to save the contents from an NSView to a PDF file at the resolution 1920x1200. I found the method:

dataWithPDFInsideRect:


I got the data from the view saved to a NSData object. My question is how do I save and open the file at 1920x1200 now that I have the NSData object with the PDF data.
Thanks



Sydde
May 10, 2011, 07:29 PM
Hello,
I am attempting to save the contents from an NSView to a PDF file at the resolution 1920x1200. I found the method:

dataWithPDFInsideRect:


I got the data from the view saved to a NSData object. My question is how do I save and open the file at 1920x1200 now that I have the NSData object with the PDF data.
Thanks

from the documentation for that method:
Discussion
This data can be placed on an NSPasteboard object, written to a file, or used to create an NSImage object.

NSImage is the easiest way to handle displaying a PDF. You can set the size of the NSImage in the image itself or draw the image into a rect if the size you want. Just initialize the NSImage with the data you saved. What could be simpler?

Blakeasd
May 10, 2011, 08:21 PM
I know how to save it as an NSImage but how do I save it as a PDF to the Desktop or a Folder? My project is Document-Based but I'm not sure about what method I should use.

jiminaus
May 10, 2011, 08:34 PM
I know how to save it as an NSImage but how do I save it as a PDF to the Desktop or a Folder? My project is Document-Based but I'm not sure about what method I should use.

The NSData object should contain the bytes of the PDF file. Try sending it one of the writeToFile or writeToURL messages.