How to convert PDF from CMYK to RGB, for displaying on iPad?

后端 未结 4 834
梦毁少年i
梦毁少年i 2021-02-03 15:22

According to this question:

Displaying PDF documents on iPad - Color Problems

some PDFs don\'t display right on iOS devices due to colors not being in RGB. It\'s

4条回答
  •  攒了一身酷
    2021-02-03 16:21

    I've solved the same issue here by downgrading the -dCompatibilityLevel from v1.4 to v1.3

    UPDATE: v1.3 will turn all content in the PDF in just one object, this means the end user will not be able to select texts neither extract images in his viewer.

    In order to keep using v1.4, I've discovered a trick on ghostscript that helps to keep the color accuracy, which is to disable PDF transparencies, they convert inaccurately because RGB doesn't have an alpha channel, so, information is lost.

    So if you use: -dNOTRANSPARENCY you can still use: -dCompatibilityLevel=1.4 and it will work.

    The exact command:

    gs -sDEVICE=pdfwrite -dBATCH -dNOPAUSE -dCompatibilityLevel=1.4 -dNOTRANSPARENCY -dColorConversionStrategy=/sRGB -dProcessColorModel=/DeviceRGB -dColorConversionStrategyForImages=/DeviceRGB -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dUseCIEColor=true -sOutputFile=output.pdf input.pdf
    

    As I'm handling it with PHP, I wrote a simple class:

    /**
     * Convert color profiles - PDF to PDF
     * Class Conversor
     */
    class Conversor
    {
        /**
         * Convert CMYK to RGB
         *
         * @param $input
         * @param $output
         * @return string
         */
        public static function gsCmykToRgb($input, $output)
        {
            $gsScript = ('gs -sDEVICE=pdfwrite \
                             -dBATCH -dNOPAUSE \
                             -dCompatibilityLevel=1.4 \
                             -dNOTRANSPARENCY \
                             -dColorConversionStrategy=/sRGB \
                             -dProcessColorModel=/DeviceRGB \
                             -dColorConversionStrategyForImages=/DeviceRGB \
                             -dTextAlphaBits=4 \
                             -dGraphicsAlphaBits=4 \
                             -dUseCIEColor=true \
                             -sOutputFile='."$output".' '."$input");
            exec($gsScript);
    
            return realpath($output);
        }
    }
    

    You can find everything about ghostscript here: http://www.ghostscript.com/doc/9.05/Use.htm

提交回复
热议问题