• 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
Printing Multiple-Pages Issue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Printing Multiple-Pages Issue


  • Subject: Printing Multiple-Pages Issue
  • From: "Renzil D'Souza" <email@hidden>
  • Date: Sun, 16 Aug 2009 23:26:02 +0530

Hi,

I'm trying to print a really large image into 'N' pages. So I over-rode
'knowsPageRange' and 'rectForPage'. Since I was able to successfully draw on
a single page, my rectForPage function returns the entire 'print view frame'
itself, and I draw a sub-image in this frame. My understanding is that
rectForPage simply returns an NSRect in the print view to which all drawing
operations are clipped. So I don't want to clip anything, but I do it myself
by creating a sub-image (using CGImageCreateWithImageInRect) and drawing it
like any other image on the entire view. But this doesn't seem to work, I'm
getting just a single line on my 2nd page, and from my 3rd page onwards I
don't get any output. My first page appears fine. What could be wrong? Here
is the basic skeleton of the code I'm using:

// BEGIN CODE

void OnPrint()
{
    PrintView *printView = [[PrintView alloc] initWithFrame:printViewFrame];
    NSPrintOperation *printOp = [NSPrintOperation
printOperationWithView:printView];
    [printOp runOperation];
}

Class print view functions over-ridden:

- (BOOL) knowsPageRange: (NSRangePointer) aRange
{
    aRange->location = 1;
    aRange->length = totalPages;
    return YES;
}

- (NSRect) rectForPage: (int) page
{
    mCurrentPage = page;
    return [self frame];
}

- (void) drawRect: (NSRect) rect
{
    // assume a CGImageRef 'sourceImage', its width and height as
'imageWidth' and 'imageHeight'
    CGRect imageRect = {{0, imageHeight*((float)(numPages-1)/totalPages)},
{imageWidth, imageHeight / totalPages} };
    CGImageRef subImage = CGImageCreateWithImageInRect(sourceImage,
imageRect);

    NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
    CGContextRef context = (CGContext*)[currentContext graphicsPort];

    CGContextDrawImage(context, imageRect, subImage);
}

// END CODE

Thanks,
Renzil
_______________________________________________

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: Printing Multiple-Pages Issue
      • From: Graham Cox <email@hidden>
  • Prev by Date: RE: Cleaning "garbage" in Core Data
  • Next by Date: Adding string encodings CoCoa
  • Previous by thread: [OT] Re: Running otest in Instruments
  • Next by thread: Re: Printing Multiple-Pages Issue
  • Index(es):
    • Date
    • Thread