• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Performance Issue with Drawing PDFPages on NSView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Performance Issue with Drawing PDFPages on NSView


  • Subject: Performance Issue with Drawing PDFPages on NSView
  • From: Naresh Kongara <email@hidden>
  • Date: Wed, 26 Aug 2009 16:50:42 +0530

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 (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


  • Follow-Ups:
    • Re: Performance Issue with Drawing PDFPages on NSView
      • From: John Calhoun <email@hidden>
  • Prev by Date: Re: [IPhone 3.0] How do I make a UITextField the first responder?
  • Next by Date: How to create GPS enabled Iphone application?
  • Previous by thread: Using shortcuts and FirstResponder
  • Next by thread: Re: Performance Issue with Drawing PDFPages on NSView
  • Index(es):
    • Date
    • Thread