2

I am having some troubles while trying to insert images in a pdf while changing its colorspace. Right now I have a png monochrome image (8 bits, 1 bit depth) where the 1 is black and the 0 is transparent (something like a mask). I want to insert this image into a pdf file and change the colorspace to separation, because it needs to be printed using a spot color. Is there some way to do that?

Currently I tried this:

<</Type /XObject
/Subtype /Image
/Width 800
/Height 600
/ColorSpace <</CS0 6 0 R>>
/BitsPerComponent 1
/Filter /FlateDecode
/DecodeParms <</Predictor 15 /Colors 1 /BitsPerComponent 1 /Columns 800>>

Being this the separation colorspace:

6 0 obj
[/Separation /White 10 0 R
<<
/FunctionType 2
/N 1
/Range [0 1 0 1 0 1 0 1]
/C1 [1 0 0 0]
/Domain [0 1]
/C0 [0 0 0 0]

I also tried adding the colorspace definition inlined, but did not work.

KenS
  • 30,202
  • 3
  • 34
  • 51
trunco
  • 103
  • 11
  • 1
    In what way 'did not work' ? Your color space definition is really incomplete, you haven't closed the dictionary for the tint transform function or closed the color space array and you haven't said what object 10 is (I assume CMYK). I've removed the PostScript tag, because it doesn't seem in any way relevant. – KenS Jun 25 '18 at 20:51

1 Answers1

0

You are pretty close already. You missed the image attribute that will tell this to treat zero as transparent, and you made the alternate space for the separation color space a bit more complex than was needed. I would have expected what you wrote (if it were properly encoded) to display the graphic in cyan and white and to overlay any underlying material.

Add a Mask attribute to the image, saying that all values between 0 and 0 are to be masked. This will make zero bits transparent.

I would not use White as a separation color name, as it can lead to confusion, unless you really are drawing the 1 bits as white, and leaving the zero bits undrawn. This would be unusual, but I can see it happening. Unless the color you want to draw cannot be expressed in gray scale, I would use the very simple alternate color of device gray. You say the image is black and transparent, so using DeviceGray would be a good choice.

Converting from the separation color (0 is undrawn, 1 is black) to the alternate color space (DeviceGray) is as simple as inverting the value Input of 1, which becomes DeviceGray 0, and input 0 becomes DeviceGray 1. So a postscript function is the quickest to write. {1 sub} is all it takes.

<</Type /XObject
/Subtype /Image
/Width 800
/Height 600
/ColorSpace <<6 0 R>>
/BitsPerComponent 1
/Mask [0 0]
/Filter /FlateDecode
/DecodeParms <</Predictor 15 /Colors 1 /BitsPerComponent 1 /Columns 800>>
stream
………
endstream
endobj

6 0 obj
[/Separation /White /DeviceGray 7 0 R]
endobj

7 0 0bj
<< 
/FunctionType 4
/Range [0 1]
/Domain [0 1]
/length 7
>> 
Stream
{1 sub}
endstream
endobj
  • Hi, thanks for you answer! Actually you are 100% right about our intentions :) Because of requirements we need to show it as cyan but print the 1 bits as white. We were digging in the PDF specification and now we are making a test print with following code: https://nopaste.xyz/?a3ef25eaa79792ef#ywUaeniClyNAWr2V39v3s+uE4CTABhT5JVsoytmMy+w= We are trying to do something similar to your approach, because your solution looks cleaner. Again, thank you very much for your time! – trunco Jun 29 '18 at 07:31