1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

PDFView Printing Hangs

Discussion in 'Mac Programming' started by best4gotten, Jul 21, 2009.

  1. macrumors newbie


    I am trying to print a pdf file thru my application using the below code.

    NSPrintInfo *printInfo = [[NSPrintInfo sharedPrintInfo] retain];
    NSRect printRect = [printInfo imageablePageBounds];
    PDFDocument *document = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:FilePath]];
    PDFView *pfView = [[PDFView alloc] initWithFrame:NSMakeRect(0 , 0,printRect.size.width,printRect.size.height )];
    [pfView setDocument:document];
    [pfView printWithInfo:printInfo autoRotate:YES];
    This displays the print panel and the preview looks fine however when I press any button for print or cancel the application hangs. I hav also tried to make my own PDF file using photos from hard disk and then printing it but no luck. here is the code for this...

    PDFDocument *pdf = [[PDFDocument alloc] init];
            for (size_t i = 0; i < path.size(); i++) {
                    NSString* file = [NSString fromUTF8String:path[i]];
                    NSImage* img = [[NSImage alloc]initWithContentsOfFile:file];
                    PDFPage *page = [[PDFPage alloc] initWithImage:img];
                    [pdf insertPage: page atIndex:  i];
            NSPrintInfo *sharedInfo = [NSPrintInfo sharedPrintInfo];
            NSRect rect = NSMakeRect(0.0, 0.0, [sharedInfo imageablePageBounds].size.width, [sharedInfo imageablePageBounds].size.height);
            PDFView *pdfView =[[PDFView alloc] initWithFrame:rect];
            [pdfView setDocument:pdf];
            [pdfView printWithInfo:sharedInfo autoRotate:YES];
    any idea on where the things going wrong.

    Best regards

    Intel Macmini
    Using MAC OSX v 10.4
  2. macrumors 6502a


    "printWithInforintInfo" looks wrong. Also, use code tags when you post code on the forum.
  3. macrumors newbie

    Thats a Mistake only in the POST.. my code does'nt have that typo.. sorry for that...

    sorry for not using tags... my first time...

    any clue about the problem???

    I am myself unsure about the rect

    NSRect rect = NSMakeRect(0.0, 0.0, [sharedInfo imageablePageBounds].size.width, [sharedInfo imageablePageBounds].size.height);

    is it the correct way of specifying the frame for PDFView???
  4. macrumors 6502a


    fileURLWithPathdfFilePath is also wrong. You should be copy/pasting your code so you don't create typos when posting.
  5. macrumors newbie

    Thanks GorillaPaws for replys I have added the Code tags and Removed the typos..

    I have been struglling with this for few days so my code has alot of RED TEXT ( comments and all that).... the typos jumped in somehow... sorry for that...

    so have a clue now? :(
  6. macrumors 6502a


    sharedInfo is being used in:
    NSRect rect = NSMakeRect(0.0, 0.0, [sharedInfo imageablePageBounds].size.width, [sharedInfo imageablePageBounds].size.height);
    but it's not being created until the next line.
  7. macrumors newbie

    :eek: HOLDON before i get blocked...

    let me tell you what I am doing wrong.. I am copy/pasting my code and removing Commentted and debug code to make it look nice but its getting more STUPID than nice :eek:

    the code in the second code tag now is the one I am using and its generating the same problem i.e hangs when i press print or cancel...

    any clue?? or found one of my stupidity again???:confused:

Share This Page