best4gotten
Jul 21, 2009, 05:27 AM
Hi,
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];
return;
any idea on where the things going wrong.
Best regards
Leopard
Intel Macmini
XCode
Using MAC OSX v 10.4
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];
return;
any idea on where the things going wrong.
Best regards
Leopard
Intel Macmini
XCode
Using MAC OSX v 10.4
