0

I am inserting svg image into pdf using tcpdf. And tcpdf writes pdf in rgb using this command

$pdf->ImageSVG

But i want to convert it to cmyk. So i thought i have 2 way to do this,

1)convert svg to cmyk

For this i tried this command

shell_exec("convert {$svgPath} -profile 'Canon_iPF_5000_-_iPF_8000_-_iPF_9000.icc' {$svgoppath}"); 

But not working

2)convert pdf to cmyk while writing svg

I tried to find in google regarding this, but no proper documentation of tcpdf to force write pdf in cmyk

Is there any better way to achieve this?

Himanshu Bhardiya
  • 1,047
  • 14
  • 37
  • https://www.w3.org/TR/SVG/color.html#ColorProfileElement – Kaiido Apr 23 '16 at 12:27
  • @Kaiido thanks for getting through my situation, svg is generating autoamtic, so what code should i have to append or insert or update in svg? i have many elements in svg like ` Type Text Here ` which has `fill` property in `rgb`. – Himanshu Bhardiya Apr 23 '16 at 12:32
  • ok thanks @Kaiido appreciate. – Himanshu Bhardiya Apr 23 '16 at 12:35
  • Does the image need to be an SVG? If this is not necessary then you could use ImageMagick to change it to another format (example at https://stackoverflow.com/questions/10289686/rendering-an-svg-file-to-a-png-or-jpeg-in-php) and then user ImageMagick again the change the image's colourspace using `transformImageColorspace`. – Michael Apr 23 '16 at 13:07
  • @Michael i installed imagick on server and i am getting error here https://www.printhubpro.co.uk/ajax/svgtest – Himanshu Bhardiya Apr 25 '16 at 06:23
  • My suggestion was to convert the SVG to another format before changing its colourspace which you do not appear to be doing. – Michael Apr 25 '16 at 08:21
  • @Michael problem is i need to keep vector image, after converting to any other it converted to grey-scale – Himanshu Bhardiya Apr 25 '16 at 09:04
  • @Michael `PDF_load_iccprofile` is it usefull? i am not getting any example of this function even. – Himanshu Bhardiya Apr 26 '16 at 05:43

1 Answers1

1

The PHP way to convert to colorspace is to use iMagick's setimagecolorspace which is the equivalent to the exec(convert..... If option 1) doesn't work, chances are setimagecolorspace will fail too.

Ensure that imagemagick library & utilities are installed on server, else you'd be spending hours debugging code that isn't broken.

Alvin K.
  • 4,329
  • 20
  • 25
  • i have installed imagick on server and trying this code also, `$image=Config::get('constants.paths.uploads.images.base')."/test.svg"; $image2=Config::get('constants.paths.uploads.images.base')."/test_new.svg"; $IMagick = new IMagick(); $IMagick->clear(); $IMagick->readImage($image); $icc_cmyk = ltrim(Config::get('constants.paths.uploads.images.base').'/1.icc',"/"); $IMagick->profileImage('icc', $icc_cmyk); //unset($icc_cmyk); $IMagick->transformImageColorspace(12); $IMagick->writeImage ($image2);` but getting error `ColorspaceColorProfileMismatch `icc' ` – Himanshu Bhardiya Apr 25 '16 at 06:16
  • yes great no error now, but issue is, svg is not readable now, it only shows codes like this, http://printhubpro.co.uk/images/test_new.svg and original is here http://printhubpro.co.uk/images/test.svg – Himanshu Bhardiya Apr 25 '16 at 06:54
  • Are you trying to change the `fill` RGB to CMYK color? That's not possible with iMagick. The only app I am aware of is Scribus, where you can export [SVG to PDF CMYK](https://fedoraproject.org/wiki/How_to_set_CMYK_color_on_a_design_for_printing) – Alvin K. Apr 25 '16 at 09:00
  • is ther any other way to do with php? – Himanshu Bhardiya Apr 25 '16 at 11:01
  • Have you tried using ghostscript to convert a RGB to CMYK PDF? It is a tall order to insert cmyk into svg, then update internals of tcpdf to read cmyk. – Alvin K. Apr 26 '16 at 16:56
  • but i dont know how to use it in laravel – Himanshu Bhardiya Apr 30 '16 at 05:43