Re: Generating a paginated PDF for use with PDFDocument
Re: Generating a paginated PDF for use with PDFDocument
- Subject: Re: Generating a paginated PDF for use with PDFDocument
- From: John Calhoun <email@hidden>
- Date: Wed, 12 Sep 2007 12:29:29 -0700
One solution that quickly comes to mind (not elegant I'm afraid) is to
use -[NSView dataWithPDFInsideRect:] multiple times (once for each
page).
You'll have to compute the rect for each page. And you'll have to
create a PDFDocument for each page as well (this is the particularly
inelegant part). WIth a PDFDocument per page, you can then get the
one PDFPage from each PDFDocument, add it to an empty PDFDocument and
then release the donor PDFDocument. Does that make sense?
Something like:
PDFDocument newDocument = [[PDFDocument alloc] init]; // NOTE, may
only work on Leopard, on Tiger you may need to keep around the first
donor document below and add pages to it.
NSRect pageBounds = NSMakeRect(0, 0, PAGE_WIDE, PAGE_TALL);
int p;
for (p =0; p < numPages; p++)
{
// Create new PDFDocumetn for one page.
PDFDocument *donor = [[PDFDocument alloc] initWithData: [myView
dataWithPDFInsideRect: pageBounds]];
// Insert page from donor document into newDocument, release donor.
[newDocument insertPage: [donor pageAtIndex: 0] atIndex: [newDocument
pageCount] - 1];
[donor release];
// Move rect down.
pageBounds = NSOffsetRect(pageBounds, 0, PAGE_TALL);
}
See if you can get something like that working.
On Sep 12, 2007, at 11:03 AM, Keith Blount wrote:
However, what I would now like to do is generate PDF
data from this view that can be used to create a
PDFDocument (using PDFDocument's -initWithData:) and
then displayed in the PDFView right inside my app. In
other words, I want to create a sort of one-click
preview of the paginated view right within in my app,
without having to go to print > preview and without
having to save the PDF to disk.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden