Re: Generating PDFs....
Re: Generating PDFs....
- Subject: Re: Generating PDFs....
- From: Joshua Scott Emmons <email@hidden>
- Date: Wed, 29 Jun 2005 09:55:45 -0400
I'm looking for a way to generate PDFs. I've got a whole bunch of
NSAttributedStrings that I need to schlep out to a PDF, and I have
no clue how to do it.
Here's how I would do it:
Create a new NSView either programatically or in IB. We'll call it
printView.
layout your attributed strings (using NSTextView or whatever) in this
view so that they looks how you want it to. Set the size to something
nice. If you want it to wrap, make sure it does. etc.
Follow the instructions at
http://developer.apple.com/documentation/Cocoa/Conceptual/Printing/
index.html
If you're in a document based app, you'll probably want to do
something like:
Get an instance to NSPrintInfo, set horizontal and vertical centering
to NO, set horizontal pagination to NSFitPagination and vertical
pagination to NSAutoPagination. You'll also want to use your
NSPrintInfo instance to set your page size, orientation, and margins.
After doing that, you can ask it for the page's printable area and
resize your printView to match (unless you want it to paginate).
Then you call NSPrintOperation's
+PDFOperationWithView:insideRect:toData:printInfo: or
+PDFOperationWithView:insideRect:toPath:printInfo:
depending on your preference, passing it your print view and you
instance of NSPrintInfo.
There are clearly a lot of variations on this theme, and I don't know
which would suit your project best. So it'd be a good idea to go
through the printing architecture docs yourself.
Alternatively, I suppose you could do everything manually by using
PDFKit, but I've never done anything on that low of a level before.
Cheers,
-Joshua Emmons
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden