indexForPage: page not found - Problem with PDFView on Tiger, works fine on Leopard

  • Hi, I have recently stumbled upon a strange problem which I am at a
    loss to solve.  Any pointers would be greatly appreciated.

    This snippet of code works fine on Leopard but not on Tiger.....

    - (void)awakeFromNib  {

    NSString *outPath = [@"~/Desktop/debug.pdf"
    stringByExpandingTildeInPath];
    [self writeDebugPDFDocument:[self pdfDocument] toPath:outPath];


    [self setPageCount:[pdfDocument pageCount]]; <---- pageCount = 1
    (like it should)
    [pdfView setDocument:[self pdfDocument]];    <-------  Throws
    exception here.
    [self skipToPage:[NSNumber numberWithInt:1]];
    [pdfView layoutDocumentView];
    }

    Debugger log output:
    2008-02-17 12:26:51.163 Imposer[455] indexForPage: page not found
    2008-02-17 12:26:51.163 Imposer[455] *** Uncaught exception:
    <NSGenericException> indexForPage: page not found

    Stack trace:
    #0    0x92c0107c in _NSRaiseError
    #1    0x92c00db8 in +[NSException raise:format:]
    #2    0x9648b894 in -[PDFDocument indexForPage:]
    #3    0x9648aaec in -[PDFView viewSizeForPage:]
    #4    0x9648a1b0 in -[PDFView resizeDisplayView:]
    #5    0x964899e0 in -[PDFView setDocument:]
    #6    0x000d512c in -[KRImposerDocument awakeFromNib] at
    KRImposerDocument.m:78

    I added the first two lines of code to ensure that the document is
    valid and that the page does in fact exist.  When I check the document
    that is written to the desktop, it does in fact have the page and
    appears to be normal.  I'm wondering why the PDFView is unable to
    access the page when the document does in fact have the page.

    I'm sure it's something I'm doing (possibly some autorelease
    craziness?) since this snippet works fine when the document is opened
    via the "Open" menu, and only happens when a new document has been
    created programmatically from the originally opened one.

    Let me know if I need to provide more information.  Again, any
    pointers would be greatly appreciated.  Thanks for the help.

    Kevin
  • On Feb 17, 2008, at 1:07 PM, Kevin Ross wrote:
    > This snippet of code works fine on Leopard but not on Tiger.....
    >
    > - (void)awakeFromNib  {
    >
    > NSString *outPath = [@"~/Desktop/debug.pdf"
    > stringByExpandingTildeInPath];
    > [self writeDebugPDFDocument:[self pdfDocument] toPath:outPath];
    >
    >
    > [self setPageCount:[pdfDocument pageCount]];    <---- pageCount = 1
    > (like it should)
    > [pdfView setDocument:[self pdfDocument]];    <-------  Throws
    > exception here.
    > [self skipToPage:[NSNumber numberWithInt:1]];
    > [pdfView layoutDocumentView];
    > }
    >
    > Debugger log output:
    > 2008-02-17 12:26:51.163 Imposer[455] indexForPage: page not found
    > 2008-02-17 12:26:51.163 Imposer[455] *** Uncaught exception:
    > <NSGenericException> indexForPage: page not found
    >
    > Stack trace:
    > #0    0x92c0107c in _NSRaiseError
    > #1    0x92c00db8 in +[NSException raise:format:]
    > #2    0x9648b894 in -[PDFDocument indexForPage:]
    > #3    0x9648aaec in -[PDFView viewSizeForPage:]
    > #4    0x9648a1b0 in -[PDFView resizeDisplayView:]
    > #5    0x964899e0 in -[PDFView setDocument:]
    > #6    0x000d512c in -[KRImposerDocument awakeFromNib] at
    > KRImposerDocument.m:78

    It's hard to answer you without knowing more about your class/app.

    I take it the code snippet is from KRImposerDocument?  This is a
    PDFView subclass?

    What does skipToPage: do?  Specifically, is it 1-based or zero based
    (because PDFKit is zero-based).

    > I'm sure it's something I'm doing (possibly some autorelease
    > craziness?) since this snippet works fine when the document is
    > opened via the "Open" menu, and only happens when a new document has
    > been created programmatically from the originally opened one.

    That bit puzzles me.  How are you creating the document
    programatically?  There were small odd differences between Leopard and
    Tiger here....

    John Calhoun—