Re: Changing PDF pages
Re: Changing PDF pages
- Subject: Re: Changing PDF pages
- From: Diggory Laycock <email@hidden>
- Date: Thu, 8 Aug 2002 12:53:59 +0100
I had a play about with PDF and got the following code to work:
#import "PDFViewer.h"
@implementation PDFViewer
-(void)awakeFromNib
{
NSData *myPDFasData = [[NSData alloc]
initWithContentsOfFile:@"/users/diggory/syncML.PDF"];
NSLog(@"initing PDF");
myPDFRepresentation = [[NSPDFImageRep alloc]
initWith
Data:myPDFasData];
numPages = [myPDFRepresentation pageCount];
NSLog(@"PDF has %d pages", numPages);
[self drawPDFPageAtPageNumber: 0];
}
-(void)drawPDFPageAtPageNumber: (int)pageToDisplay
{
NSImage *myPDFPageImage;
NSLog(@"Drawing Page: %d of %d", pageToDisplay, numPages);
[myPDFRepresentation setCurrentPage: pageToDisplay];
myPDFPageImage=[[NSImage alloc] init];
[myPDFPageImage addRepresentation: myPDFRepresentation];
[PDFImageView setImage: myPDFPageImage];
[PDFImageView setNeedsDisplay: YES];
[myPDFPageImage release];
}
- (IBAction)nextPage:(id)sender
{
int nextPage=([myPDFRepresentation currentPage]+1);
[self drawPDFPageAtPageNumber: nextPage];
}
@end
On Thursday, August 8, 2002, at 12:49 am, Ben Mackin wrote:
>
Ok, I have a 5 page pdf (lets say) and I want the displaying page (in my
>
NSImageView) to change when I push the next page button. The following
>
code
>
works to get me the number of pages in the document:
>
>
myPDFasData = [[NSData alloc]
>
initWithContentsOfFile:@"/tmp/myFile.PDF"];
>
myPDF = [[NSPDFImageRep alloc] initWithData:myPDFasData];
>
numPages = [myPDF pageCount];
>
>
However, now I am at a loss of how to change the page. I saw the
>
setCurrentPage function, but am not sure exactly how to implement it.
>
Here
>
is what I have tried:
>
>
[image1 addRepresentation:myPDF];
>
[myPDF setCurrentPage:curPage];
>
myPDFasData = [myPDF PDFRepresentation];
>
>
image1 = [[NSImage alloc] initWithData:myPDFasData];
>
myImageToDisplay = [[NSImage alloc] initWithSize:kUSLetterSize];
>
[myImageToDisplay lockFocus];
>
[image1 compositeToPoint:NSZeroPoint operation:NSCompositeCopy];
>
[myImageToDisplay unlockFocus];
>
>
But no matter the curPage variable is set to, it always only shows the
>
first
>
page. If anyone has some insight, please let me know.
>
>
Thanks,
>
Ben
>
_______________________________________________
>
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.
>
>
Diggory Laycock
-----------------------
http://www.diggory.net
_______________________________________________
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.