I'm working on a little framework and I need to get a list of all available custom papers
In the Core Printing Reference there's only a method called PMPrinterGetPaperList, but it doesn't return custom paper:
This function obtains a list of the papers that a given printer claims to support.
The paper list does not include any custom paper sizes that may be available
If I open a pdf-document and then open the print-dialog I can create and select custom papers.
As summary I want to get a/the list of custom papers which I can create with print-dialog and with Objective-C method PMPaperCreateCustom
It has to be in Objective-C.
Any ideas? Thanks
Edit1:
Here is a snippet based on the first answer:
for (int i = 0; i < printerCount; i++)
{
CFStringRef currentPrinterName;
currentPrinter = (PMPrinter) CFArrayGetValueAtIndex(printerList, i);
currentPrinterName = PMPrinterGetName(currentPrinter);
if ([(NSString *) currentPrinterName caseInsensitiveCompare:printerName] == NSOrderedSame)
{
error = PMSessionCreatePageFormatList([[NSPrintInfo sharedPrintInfo] PMPrintSession], currentPrinter, &pageFormatList);
if (error != noErr)
{
// TODO
}
NSUInteger pageCount = CFArrayGetCount(pageFormatList);
for (int n = 0; n < pageCount; n++)
{
currentPage = (PMPageFormat) CFArrayGetValueAtIndex(pageFormatList, n);
error = PMGetPageFormatPaper(currentPage, ¤tPaper);
if (error != noErr)
{
// TODO
}
if (PMPaperIsCustom(currentPaper))
{
NSLog(@"It's custom");
}
}
break;
}
currentPrinter = NULL;
}
But I only get the list of 'normal' papers and no custom ones.
On print dialog I created a custom paper (see screenshot) and this should be in the list.
Screenshot:
Since the custom papers list is apparently not (currently) accessible via Core Printing and Cocoa Printing …
One could use Objective-C to read the plist which stores a dictionary of the custom papers created by the user:
~/Library/Preferences/com.apple.print.custompapers.plist
Then, use subsequently use
PMPaperCreateCustom
as needed.