Objective-C获取所有自定义文件的列表

时间:2016-03-02 07:43:10

标签: objective-c macos printing nsprintinfo

我正在制作一个小框架,我需要获取所有可用自定义论文的列表

Core Printing Reference中,只有一个名为PMPrinterGetPaperList的方法,但它不会返回自定义文件:

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

如果我打开pdf文档,然后打开打印对话框,我可以创建并选择自定义文件。

总结一下,我想得到一个自定义论文列表,我可以使用print-dialog和Objective-C方法创建自定义论文PMPaperCreateCustom

必须在Objective-C中。

有什么想法吗?感谢

EDIT1:

以下是基于第一个答案的摘录:

        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, &currentPaper);

                if (error != noErr)
                {
                    // TODO
                }

                if (PMPaperIsCustom(currentPaper))
                {
                    NSLog(@"It's custom");
                }
            }

            break;
        }

        currentPrinter = NULL;
    }

但我只能获得“普通”论文清单,而不是自定义论文。

在打印对话框中,我创建了一个自定义纸张(参见屏幕截图),这应该在列表中。

截图:

Screenshot xcode

2 个答案:

答案 0 :(得分:1)

使用PMSessionCreatePageFormatList()获取所有页面格式,枚举它们,并为每个格式调用PMGetPageFormatPaper()以获取其论文可能会有用。您可以使用PMPaperIsCustom()查看每个是否是自定义文件。

答案 1 :(得分:1)

由于自定义纸张清单显然不是(目前)可通过核心印刷和可可印刷获得......

可以使用Objective-C来读取存储用户创建的自定义论文字典的plist:

〜/库/首/ com.apple.print.custompapers.plist

然后,根据需要随后使用PMPaperCreateCustom