NSPDFImageRep / PDFOperationWithView question

  • Dear Cocoa-dev People,

    When I read a two page PDF file and use PDFOperationWithView to "copy" its
    NSPDFImageRep* pdfRep to pdxRep:

        [pdfRep bounds] is x=0, y=0, width=612, height=792
        [pdfRep pageCount] is 2

        [pdxRep bounds] is x=0, y=0, width=612, height=1584
        [pdxRep pageCount] is 1

    I'd like the pdxRep copy to have the same bounds and pageCount as the original
    How could I accomplish this?  Or is this change of pageCount and bounds

    Note about my "added code":  I tried using both:


    But adding printInfo didn't affect the pageCount or bounds.


    P.S. My question is similar to Brock Brandenberg's well-written
    "PDFOperationWithView" question which was asked but not answered in 2002.

    // I added code at the end of this method in the PDFView sample
    // http://developer.apple.com/samplecode/PDFView/

    // PDFImageView loadFromPath: -- Load the PDF at the specified path into the
    // This automatically resizes the view to fit all pages of the document.

    - (void) loadFromPath: (NSString *) path
        NSPDFImageRep *pdfRep;
        NSImage      *pdfImage;
        NSRect        frame;

        //  Load the file into an image-representation,
        //    then create an image and add the representation to it.
        pdfRep = [NSPDFImageRep imageRepWithContentsOfFile: path];
        pdfImage = [[[NSImage alloc] init] autorelease];
        [pdfImage addRepresentation: pdfRep];

        //    Figure our frame by getting the bounds, which is really the size
        //    of one page, and multiplying the height by the page count.
        frame = [pdfRep bounds];
        frame.size.height *= [pdfRep pageCount];

        //    Install the image (remember, we're an NSImageView subclass)
        [self setImage: pdfImage];

        //  Set our frame to match the PDF's full height (all pages)
        //  (don't involve our override of -setFrame:, or things won't work right)
        [super setFrame: frame];

        //    Always scroll to show the top of the image
        if ([self isFlipped])
            [self scrollPoint: NSMakePoint (0, 0)];
            [self scrollPoint: NSMakePoint (0, frame.size.height)];

      //  ADDED CODE
        NSMutableData* pdxRepData = [[NSMutableData alloc] init];
        NSPrintOperation* printOp = [NSPrintOperation PDFOperationWithView:self

        [printOp runOperation];
        NSPDFImageRep *pdxRep = [[NSPDFImageRep alloc] initWithData: pdxRepData];

    Be a better pen pal.
    Text or chat with friends inside Yahoo! Mail. See how.  http://overview.mail.yahoo.com/
previous month november 2007 next month
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today