【问题标题】:How to save PDF to images on OS X?如何在 OS X 上将 PDF 保存为图像?
【发布时间】:2014-04-11 03:36:26
【问题描述】:

有没有办法通过 Xcode 5 将 PDF 页面保存到 OS X 上的图像?我在 Stackoverflow 上搜索过,发现了这个Xcode save a PDF as Image?

但它适用于 iOS,而不是 OS X。我想将 PDF 页面导出为 JPG 或 PNG 等图像。

提前谢谢你。

【问题讨论】:

    标签: objective-c macos pdf


    【解决方案1】:

    试试这个:

    NSData *pdfData = [NSData dataWithContentsOfFile:pathToUrPDF];    
    NSPDFImageRep *pdfImg = [NSPDFImageRep imageRepWithData:pdfData];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSInteger pageCount = [pdfImg pageCount];
    for(int i = 0 ; i < pageCount ; i++) {
        [pdfImg setCurrentPage:i];
        NSImage *temp = [[NSImage alloc] init];
        [temp addRepresentation:pdfImg];
        NSBitmapImageRep *rep = [NSBitmapImageRep imageRepWithData:[temp TIFFRepresentation]];
        NSData *finalData = [rep representationUsingType:NSJPEGFileType properties:nil];
        NSString *pageName = [NSString stringWithFormat:@"Page_%ld.jpg", (long)[pdfImg currentPage]];
        [fileManager createFileAtPath:[NSString stringWithFormat:@"%@/%@", @"pathWrUWantToSave", pageName] contents:finalData attributes:nil];
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-09
    • 1970-01-01
    • 2018-07-17
    • 2017-06-02
    • 1970-01-01
    • 1970-01-01
    • 2011-08-02
    • 1970-01-01
    相关资源
    最近更新 更多