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

    #1
    Hi,

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

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

    Code:
    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];
            return;
    
    any idea on where the things going wrong.

    Best regards

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

    GorillaPaws

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

    #3
    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

    GorillaPaws

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

    #5
    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

    GorillaPaws

    #6
    sharedInfo is being used in:
    Code:
    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

    #7
    :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