PDF colours weird via web view and CGPDFDocumentCreate, yet not in preview

落爺英雄遲暮 提交于 2019-12-08 04:48:16

问题


I've been using a couple of methods in an iPad app for over a year now, largely based on apple code available here to display PDF pages nicely - it's worked fine for dozens of different PDFs until now. I just got a bunch of PDFs that appear to be having their colours warped in some way. What Preview/Adobe shows:

And here's what I'm seeing, both in Layer based CGPDFDrawPDFPage() and in an iPad UIWebView (pointing to the file), using simulator:

I am wondering if somehow the PDF is in some weird colorspace (CMYK?), but that wouldn't explain why Preview/Adobe Reader can open it just fine. For reference, this is the sum totality of the display code used in the UIView subclass (note, pdfPage is an instance variable):

// Draw the CGPDFPageRef into the layer at the correct scale.
-(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context
{
    // from https://stackoverflow.com/questions/3889634/fast-and-lean-pdf-viewer-for-iphone-ipad-ios-tips-and-hints
    CGContextSetInterpolationQuality(context, kCGInterpolationHigh); 
    CGContextSetRenderingIntent(context, kCGRenderingIntentDefault);

    // First fill the background with white.
    CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 1.0f);
    CGContextFillRect(context, self.bounds);

    CGContextSaveGState(context);
    // Flip the context so that the PDF page is rendered
    // right side up (all the PDF routines are built for Mac OS X
    // coordinate systems, where Y is upwards.

    // first move the origin down by the full height
    CGContextTranslateCTM(context, 0.0f, self.bounds.size.height);
    // now invert the Y position (scale by -1)
    CGContextScaleCTM(context, 1.0f, -1.0f);

    // Scale the context so that the PDF page is rendered 
    // at the correct size for the zoom level.
    CGContextScaleCTM(context, myScale, myScale);   
    CGContextDrawPDFPage(context, pdfPage);

    CGContextRestoreGState(context);
}

As you can see, we also have been avid readers of Fast and Lean PDF Viewer for iPhone / iPad / iOs - tips and hints?

Any suggestions on how to diagnose what we're seeing, and/or alter the color space (or alter the PDF document? We do have that option too).


回答1:


I would guess that your PDF uses one or more spot color(s) in addition to CMYK. It seems that those are not supported on iOS – as far as I know, this isn't documented anywhere, but it has been my experience.

If you have Acrobat Pro, you can check this with the Ink Manager (Advanced → Print Production → Ink Manager).

You can also use Acrobat to convert the spot colors to process colors (Advanced → Print Production → Convert Colors...). Click the "Ink Manager" button in the color conversion dialog and activate the "Convert all Spots to Process" checkbox there.




回答2:


In my experience iOS butchers colors when converting CMYK to RGB. There is a nice tool in Acrobat that you can use to convert a PDF to RGB in advance, thus sidestepping the issue entirely:

Tools > Print Production > Convert Colors
Check "Convert Colors to Output Intent"
Set Output Intent to "Apple RGB"
Click OK



回答3:


You can make things easier in Acrobat Pro if you have a lot of PDFs to convert by creating an Action and convert to sRGB profile.



来源:https://stackoverflow.com/questions/10464823/pdf-colours-weird-via-web-view-and-cgpdfdocumentcreate-yet-not-in-preview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!