Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

best4gotten

macrumors newbie
Original poster
Jul 21, 2009
4
0
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
 
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???
 
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? :(
 
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.
 
: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:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.