PDA

View Full Version : Printing With Objective C




Jitin Jindal
Feb 19, 2013, 02:28 AM
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 :

#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);
}



ElectricSheep
Feb 19, 2013, 03:14 PM
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.

Jitin Jindal
Feb 19, 2013, 11:10 PM
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
Feb 26, 2013, 11:37 PM
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

ghellquist
Feb 27, 2013, 05:24 AM
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

gnasher729
Feb 27, 2013, 05:30 AM
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.

Jitin Jindal
Feb 27, 2013, 06:01 AM
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.

gnasher729
Feb 27, 2013, 06:45 AM
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.

Jitin Jindal
Feb 27, 2013, 08:23 AM
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
Feb 28, 2013, 06:49 AM
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

ArtOfWarfare
Feb 28, 2013, 08:52 AM
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.

gnasher729
Feb 28, 2013, 10:15 AM
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?

Jitin Jindal
Feb 28, 2013, 12:01 PM
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.

----------

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.