0

If I want to convert a pdf to greyscale whats the best way to go about it. Im currently using tcpdf to convert html to pdf but I also need an option where I can convert it to greyscale. Whats the best way to go about doing this.

3
  • I think this is not going to be trivial, if possible at all. Is this about text or images as well? Can you use and install external tools? What platform is this on?
    – Pekka
    Commented Feb 23, 2011 at 11:58
  • Will you be using static CSS or will the HTML/CSS input be completely dynamic? In the first case you could just create a "grayscale" version of the CSS and provide the correct CSS data when processing the HTML (and will only have to convert images to grayscale). For the latter case you will have to preprocess the HTML/CSS to convert all colors & images to grayscale.
    – wimvds
    Commented Feb 23, 2011 at 12:46
  • Yeh It is a little awkward Im going to mess about with it and see what I can come up with, everyones comments I will take into account and I will post an answer up at some point on my findings.
    – Ian
    Commented Feb 23, 2011 at 14:19

2 Answers 2

4

If you have Imagick (imagemagick) installed, you can take your generated PDF and save another gray-scaled one.

$image = new Imagick('generatedPDF.pdf');
$image->setColorspace(imagick::COLORSPACE_GRAY);
$image->writeImage('newPic.pdf');
$image->clear();
$image->destroy();
0

I think the best way is to manipulate the HTML and images and make the HTML grayscale before converting to PDF.

You can run through all your images and pass them through GD to make them all gray http://php.about.com/od/gdlibrary/ss/grayscale_gd.htm

You will also need to probably create a separate css to use in case you have color applied to your page.

HTH

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.