Re: cocoa-dev digest, Vol 2 #396 - 14 msgs
Re: cocoa-dev digest, Vol 2 #396 - 14 msgs
- Subject: Re: cocoa-dev digest, Vol 2 #396 - 14 msgs
- From: Brock Brandenberg <email@hidden>
- Date: Tue, 26 Mar 2002 09:48:02 -0600
Hi Ben.
I'm not sending an NSTextView to a file, but I am sending a view with
NSTextView subviews and here's how it's done. The secret is in the
NSView method "dataWithPDFInsideRect:". Below is a pair of snippets for
an NSView subclass that invoke a save sheet and write the view to a
file. You just hook the savePDF: method to a menu, button, etc. and the
dataWithPDFInsideRect: method simply calls the drawRect: method to image
the view.
Sending an NSTextView directly should be similar.
-(IBAction)savePDF:(id)sender
{
NSSavePanel *panel = [NSSavePanel savePanel];
[panel setRequiredFileType:@"PDF"];
[panel beginSheetForDirectory:nil file:nil modalForWindow:[self
window] modalDelegate:self
didEndSelector:@selector(didEnd:returnCode:contextInfo:)
contextInfo:nil];
}
-(void)didEnd:(NSSavePanel *)sheet returnCode:(int)code
contextInfo:(void *)contextInfo
{
if(code == NSOKButton)
{
NSData *data;
NSRect r;
r = [self bounds];
data = [self dataWithPDFInsideRect:r];
[data writeToFile:[sheet filename] atomically:YES];
}
}
Good luck.
Brock Brandenberg
I have an NSTextView that I need to save as PDF file on the computer.
What
he purpose is so that people using my program can write a quick cover
sheet
and save it using my program. Then they can choose this cover sheet.
If anyone can point me to some docs that would be great. I tried
searching
on Apple's site, but no luck for any objective-c stuff on pdf.
While I am at it, how exactly does print preview convert any kind of a
document to PDF? What I mean is, if I choose Preview from the print
menu, a
PDF file will open up (which I can then save in Preview). Is there some
calls I can make to convert files to PDF, or is this done somehow
through
the printer drivers?
What I would like to be able to do is let the user select a file on
there
hard drive, and my code would, "behind the scenes", create a pdf file
from
this (and store it /tmp) and then I can deal with that file. Help on
this
would be great as well.
Thanks,
Ben
----- industrial design @ bergdesign ------
web site: www.bergdesign.com
email: email@hidden
--------------------------------------------
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.