Hi ,

I'm drawing the pages from the pdf document onto an NSVIew. The fallowing method draws all the pages from the document in a View, this method will be called from the view's drawrect. Its taking much time when there are more than 40 pages as all the pages needs to be displayed at a time .


Is there any other way of doing it ? or How can increase the performance..?

========================================================
- (void)drawPDFPages
{
        PDFDocument *doc = [self document];
        // draw paper "page"
        [[NSColor whiteColor] set];

        float offset = 1.0;
        int matrix = MAX(pagesWide, pagesHigh);
        NSRect frameRect = [self frame];
        for (int i = 0; i < [doc pageCount]; i++) {
                PDFPage *pdfPage = [doc pageAtIndex:i];
                int x = i % pagesWide;
                int y = i / pagesWide;
                // Let PDFView do most of the hard work.
                
                float scale = 0.98;
                NSPrintingOrientation orientation = NSPortraitOrientation;

NSPDFImageRep *pdfImage = [NSPDFImageRep imageRepWithData:[pdfPage dataRepresentation]];
                if( [pdfImage size].width > [pdfImage size].height ) {
                        orientation = NSLandscapeOrientation;
                        scale = scale * [pdfImage size].height / [pdfImage 
size].width;
                }
                
                scale = scale / matrix;
                
                if( orientation == NSPortraitOrientation )
                {
NSRect portraitPageView = NSMakeRect( offset + x * ((offset + (frameRect.size.width) * scale)), (frameRect.size.height) - (offset + ((y + 1) * ((offset + (frameRect.size.height) * scale)))),
                                                                                
                 frameRect.size.width * scale,
                                                                                
                 frameRect.size.height * scale);
                        
                        NSRectFill(portraitPageView);
                        [pdfImage drawInRect:portraitPageView];
                }
                else
                {
NSRect landscapePageView = NSMakeRect( offset + x * ((offset + (frameRect.size.height) * scale)), (frameRect.size.height) - (offset + ((y + 1) * ((offset + (frameRect.size.width) * scale)))),
                                                                                
                  frameRect.size.height * scale,
                                                                                
                  frameRect.size.width * scale);
                        NSRectFill(landscapePageView);
                        [pdfImage drawInRect:landscapePageView];
                }
        }
}



============================================

Regards,
Naresh Kongara




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to