View Full Version : PDFView Printing Hangs

Jul 21, 2009, 05:27 AM

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

Jul 21, 2009, 06:17 AM
"printWithInforintInfo" looks wrong. Also, use code tags when you post code on the forum.

Jul 21, 2009, 06:22 AM
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???

Jul 21, 2009, 06:30 AM
fileURLWithPathdfFilePath is also wrong. You should be copy/pasting your code so you don't create typos when posting.

Jul 21, 2009, 06:40 AM
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? :(

Jul 21, 2009, 07:00 AM
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.

Jul 21, 2009, 07:19 AM
: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 :o

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: