Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 19, 2013, 02:28 AM   #1
Jitin Jindal
macrumors newbie
 
Join Date: Feb 2013
Location: India
Printing With Objective C

Please help in order to resolve the printing issue that i am facing while coding in objective c.
I want to print any file like (*.pages,*.numbers,*.keynote)
but i am not able to print these files using PMPrinterPrintWithFile function of objective c
I am able to print other files like *.txt,*.jpeg,*.png, *.pdf.

when I try to print iwork document like *.pages file with PMPrinterPRintWithFile, it returns a status as 1028
when I am printing other files like *.pdf,*.txt it is printed easily with status 0

and one more point I am not able to find out the MimeType of files like *.pages,*.number,*.keynote
the MIMETYPE object gets NULL value when i fetch it using the below code.
The Code I am using :
Code:
    #import "Cocoa/Cocoa.h"

    int main(int argc, char *argv[])
    {

    NSPrintInfo *printInfo = [[NSPrintInfo alloc] init];
    PMPrintSession myPrintSession= (PMPrintSession)[printInfo PMPrintSession];
    PMPrintSettings printSetting= (PMPrintSettings)[printInfo PMPrintSettings];
    PMPageFormat pageFormat=(PMPageFormat)[printInfo PMPageFormat]; 
    OSStatus err = PMCreateSession(&myPrintSession);
    OSStatus status;
    CFURLRef fileURL =(CFURLRef) [NSURL fileURLWithPath:@"filename example *.*"];
    NSString* filePath=@"filename ex *.*";
    NSString* FullPath=[filePath stringByExpandingTildeInPath];
    NSURL * url= [NSURL fileURLWithPath:FullPath];
    NSURLRequest* fileUrlRequest = [[NSURLRequest alloc] initWithURL:url];
    NSError* error = nil;
    NSURLResponse* response = nil;
    NSData* fileData = [NSURLConnection sendSynchronousRequest:fileUrlRequest 
    returningResponse:&response error:&error];
    NSString * MIMETYPE= [response MIMEType];
    [fileUrlRequest release];
    NSLog(@"MIMETYPE %@",MIMETYPE);
    PMPrinter thisPrinter= "printername";		
    status = PMPrinterGetMimeTypes(thisPrinter, printSetting,&mimeTypes);
    if(status==noErr)
	{
	status= PMPrinterPrintWithFile(thisPrinter, printSetting, pageFormat,      
        (CFStringRef)MIMETYPE, fileURL);
	NSLog(@" value :%@",MIMETYPE);
	NSLog(@"%i",status);
	NSLog(@"=======Printer %@=======", PMPrinterGetName( thisPrinter) );
	}
	[printInfo release];
      return 0;
    return NSApplicationMain(argc,  (const char **) argv);
    }

Last edited by maflynn; Feb 19, 2013 at 04:00 PM. Reason: code tags added
Jitin Jindal is offline   0 Reply With Quote
Old Feb 19, 2013, 03:14 PM   #2
ElectricSheep
macrumors 6502
 
Join Date: Feb 2004
Location: Wilmington, DE
Send a message via AIM to ElectricSheep
PMPrinterGetMimeTypes(thisPrinter, printSetting,&mimeTypes) will give you a list of MIME types supported by the printer, if you actually pass a declared CFArray mimeTypes to it. I would wager that .pages, .numbers, and .keynote files do not appear in the list of supported MIME types.

These files need to be rendered into a format suitable for printing before you can submit a print job.
__________________
15'' MBP (early 2011) | i7 3770k Hackintosh | i7 Mac Mini (late 2012) | iPhone 5 | iPad 3 (2012) | iPad mini | MacOS X 10.9.2
ElectricSheep is offline   0 Reply With Quote
Old Feb 19, 2013, 11:10 PM   #3
Jitin Jindal
Thread Starter
macrumors newbie
 
Join Date: Feb 2013
Location: India
In which format do we need to render iwork documents to get it print

yes, you are right i tried PMPrinterGetMimeTypes(thisPrinter, printSetting,&mimeTypes) and i am getting various mimetypes supported by printer but i am not able to understand which one to use in order to print the iwork documents.
And if i hav to render the iwork documents in the compatible mimetype for printing then please tell me how to render it and in which format.

Thanks....
Jitin Jindal is offline   0 Reply With Quote
Old Feb 26, 2013, 11:37 PM   #4
Jitin Jindal
Thread Starter
macrumors newbie
 
Join Date: Feb 2013
Location: India
Printing With Objective C

Please help in order to resolve the printing issue that i am facing while coding in objective c.
I want to print any file like (*.pages,*.numbers,*.keynote)
but i am not able to print these files using PMPrinterPrintWithFile function of objective c
I am able to print other files like *.txt,*.jpeg,*.png, *.pdf.

when I try to print iwork document like *.pages file with PMPrinterPRintWithFile, it returns a status as 1028
when I am printing other files like *.pdf,*.txt it is printed easily with status 0
Jitin Jindal is offline   0 Reply With Quote
Old Feb 27, 2013, 05:24 AM   #5
ghellquist
macrumors regular
 
Join Date: Aug 2011
Location: Stockholm Sweden
I believe the only way forward is to use the actual program to do the printing. You need to somehow start-up pages / numbers / keynotes and order it to do the printing. I believe that file formats are not published and I have not heard of any library or similar things that allows you to interpret the file and do printing.

I would approach this by trying to automate the printing somehow. There might be parameters you could pass to the program or it could be possible to use some other automation. Once this is understood, next step would be to see how to start this from inside your application. There are ways to start a process running a shell from inside Objective-C which could be used. You might want to mimic the parameters passed to the program or do automation functions. This is not any nice situation as it will probably be quite dependant on version of OS and/or version of pages -- and these change over time and between different client stations.

// Gunnar
ghellquist is offline   0 Reply With Quote
Old Feb 27, 2013, 05:30 AM   #6
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by Jitin Jindal View Post
Please help in order to resolve the printing issue that i am facing while coding in objective c.
I want to print any file like (*.pages,*.numbers,*.keynote)
but i am not able to print these files using PMPrinterPrintWithFile function of objective c
I am able to print other files like *.txt,*.jpeg,*.png, *.pdf.

when I try to print iwork document like *.pages file with PMPrinterPRintWithFile, it returns a status as 1028
when I am printing other files like *.pdf,*.txt it is printed easily with status 0
That's because Pages, Numbers etc. are applications that know how to print their documents; it is not built into the operating system.

Start Script Editor, look at the dictionaries for Pages, Numbers and so on, and check if you can use AppleScript to let the apps print these documents.
gnasher729 is offline   0 Reply With Quote
Old Feb 27, 2013, 06:01 AM   #7
Jitin Jindal
Thread Starter
macrumors newbie
 
Join Date: Feb 2013
Location: India
Quote:
Originally Posted by gnasher729 View Post
That's because Pages, Numbers etc. are applications that know how to print their documents; it is not built into the operating system.

Start Script Editor, look at the dictionaries for Pages, Numbers and so on, and check if you can use AppleScript to let the apps print these documents.
yes i am able to print the pages, keynote and numbers file using applescript but i am not able to set the various settings like orientation and duplex printing with them.
so I am thinking that is there any way to convert these documents into PDF files so that i can print PDF files using objective c, that can be done easily even with different printing settings.
Jitin Jindal is offline   0 Reply With Quote
Old Feb 27, 2013, 06:45 AM   #8
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by Jitin Jindal View Post
yes i am able to print the pages, keynote and numbers file using applescript but i am not able to set the various settings like orientation and duplex printing with them.
so I am thinking that is there any way to convert these documents into PDF files so that i can print PDF files using objective c, that can be done easily even with different printing settings.
There's lots of things you can do with AppleScript. Have a closer look at everything in these dictionaries.
gnasher729 is offline   0 Reply With Quote
Old Feb 27, 2013, 08:23 AM   #9
Jitin Jindal
Thread Starter
macrumors newbie
 
Join Date: Feb 2013
Location: India
Quote:
Originally Posted by gnasher729 View Post
There's lots of things you can do with AppleScript. Have a closer look at everything in these dictionaries.
You are saying about GUI script and all. Actually I dont want to use the GUI script as in future if the apple changes the print panel layout then it needs to be updated thats the issue in using GUI scripting.

If you have any idea how to convert the iwork document like keynote and numbers into PDF using applescript then please let me know.

Thanks...
Jitin Jindal is offline   0 Reply With Quote
Old Feb 28, 2013, 06:49 AM   #10
Jitin Jindal
Thread Starter
macrumors newbie
 
Join Date: Feb 2013
Location: India
Quote:
Originally Posted by gnasher729 View Post
There's lots of things you can do with AppleScript. Have a closer look at everything in these dictionaries.
Hello
if you know anything about how to convert a document of type pages,keynote ,numbers into PDF using applescript then please let me know its urgent...

thanks
Jitin Jindal is offline   0 Reply With Quote
Old Feb 28, 2013, 08:52 AM   #11
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Quote:
Originally Posted by Jitin Jindal View Post
Hello
if you know anything about how to convert a document of type pages,keynote ,numbers into PDF using applescript then please let me know its urgent...

thanks
If it's urgent then I would say go the quick and easy route of relying on the current menu paths to the export options. There's a good chance it'll fail when iWork is updated, but it'll work until the machines running it are updated with a new version.

Or rely on the include preview button being checked in the Save dialog and just grab the preview.pdf file I mentioned in another thread.
ArtOfWarfare is offline   0 Reply With Quote
Old Feb 28, 2013, 10:15 AM   #12
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by Jitin Jindal View Post
Hello
if you know anything about how to convert a document of type pages,keynote ,numbers into PDF using applescript then please let me know its urgent...

thanks
If it's urgent, then maybe your boss should post, and tell us what idea of payment he has.

You did see "print settings" in AppleScript?

Last edited by gnasher729; Feb 28, 2013 at 10:24 AM.
gnasher729 is offline   0 Reply With Quote
Old Feb 28, 2013, 12:01 PM   #13
Jitin Jindal
Thread Starter
macrumors newbie
 
Join Date: Feb 2013
Location: India
Quote:
Originally Posted by ArtOfWarfare View Post
If it's urgent then I would say go the quick and easy route of relying on the current menu paths to the export options. There's a good chance it'll fail when iWork is updated, but it'll work until the machines running it are updated with a new version.

Or rely on the include preview button being checked in the Save dialog and just grab the preview.pdf file I mentioned in another thread.
ya i also tried with the preview button being enabled but with this case the print quality of the document is not as same as the preview is just not the exact pdf with the same resolution when you will print the preview.pdf file manually then you will see the size of it, it will be very small.

----------

Quote:
Originally Posted by gnasher729 View Post
If it's urgent, then maybe your boss should post, and tell us what idea of payment he has.

You did see "print settings" in AppleScript?
yes i saw the print settings but it is not able to set the duplex and orientation settings of the document when i will try to print it through applescript.
Jitin Jindal is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Printing issues - keeps printing in reverse order! mikeqls iMac 6 Jun 4, 2013 10:27 AM
Objective-C: What is subclassing? moonman239 Mac Programming 3 Feb 26, 2013 08:08 PM
to many requests in objective-c, please help wfs123 iPhone/iPad Programming 2 Feb 4, 2013 06:20 AM
New Objective-C Tutorial ryanhodson Wasteland 4 Feb 1, 2013 01:24 AM
C and Objective-C relationships nashyo iPhone/iPad Programming 16 Jan 21, 2013 05:48 AM

Forum Jump

All times are GMT -5. The time now is 08:17 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC