Create a CMYK composite image (pdf) from individual color separations

Is it possible to take individual color separated image files and create a composite CMYK pdf using PDFTron?

Could you elaborate a bit more on what you are asking. It sounds like you want to take multiple CMYK images and make a PDF containing those CMYK images? Perhaps you can provide example inputs and an example (desired output).

Hi Ryan,

I would like to take a pdf that has been color separated and combine the 4 image separations (cyan, magenta, yellow, and black) back into a composite image (pdf). I’m thinking I would start with 4 grayscale pdfs (one for each separation), export each as an image, colorize, and then combine back into a new composite pdf.

I’m thinking I would start with 4 grayscale pdfs (one for each separation), export each as an image, colorize, and then combine back into a new composite pdf.
Since PDF uses simple painters algorithim, to have 4 separate images merge you would have to apply a transparency (at some percentage) and then pick an appropriate Blend mode (which there are at least 11 options).

Perhaps it is best to take a step back. Why is doing this important?
What are you trying to accomplish exacty?
Since you start and end with a PDF I take it you want to edit the PDF. Why not edit the PDF directly, instead of exporting/importing?

Ryan,

Sometimes a customer will provide 4 seperate grayscale pdf’s (one for each cmyk color) - extracted from a cmyk pdf that they have separated. For our proofing (visual) purposes, a composite pdf would be useful. Would this be fairly easy to accomplish applying a transparency and choosing the appropriate blending mode and then merging the 4 separate pdfs?

It would help if we could see something specific for your use case.

Do you have an example of the 4 separate grayscale pdf’s that you could send us?
If they are confidential you can send them directly to us through our website.
pdftron.com/form/request/

Here is an example of a color image that has been separated into 4 grayscale pages - one for each CMYK color. The object is to merge them together to create a composite CMYK image. Sometimes, there might be a spot color included as well.

separations_test.pdf (1.22 MB)

Is it possible to take individual color separated image files and create a composite CMYK pdf using PDFTron?

You could either extract just the image data from each page and make 4/5 channel image, where each page is the corresponding channel, and then make a new PDF page with that image.

Or if you also want the vector content that surrounds the image, then you could use our SDK to raster the entire page, and then repeat the step above.

Is that what you are looking to do?

Yes, this is what I’m trying to do. I have succeeded in rasterizing the initial grayscale pdfs (exporting as png), colorizing (with cyan, magenta, yellow), applying transparency (value of 1), and then adding them together to create a new pdf with the blend mode ‘darken’ (which is the only blend mode that gets me close to the final image) but the image is not quite right - the color is a bit off and not saturated enough…Is there a difference if I would make a new ‘multi-channel’ pdf? How would I create these new ‘channels’ from the initial grayscale pdfs?

colorizing (with cyan, magenta, yellow), applying transparency (value of 1), and then adding them together to create a new pdf with the blend mode ‘darken’

What are you using to do these steps?I assume you are using a third party tool?

Darken is actually not the most accurate blend, it should be Lighten.

We suspect the tool you are using is blending in RGB color space, you need to make sure blending is done in the CMYK color space and to use Lighten mode.

I’m using PDFTron. When I’m opening the exported png’s as new bitmaps, and colorizing, I’m using RGB color space. I will try to use the color space cmyk, colorize, and then use lighten mode. Why do you ask what I’m using to do these steps?

I can’t seem to get it to work properly after using a cmyk color space and then lighten blending mode. Here is the basic code in 3 sections;

'export grayscale pdfs as grayscale png’s
Using draw As PDFDraw = New PDFDraw()
For Each SeparationFile In Directory.GetFiles(inputPath)
Using doc As PDFDoc = New PDFDoc(SeparationFile)
Dim hint_set As ObjSet = New ObjSet
Dim gray_hint As Obj = hint_set.CreateDict()
gray_hint.PutName(“ColorSpace”, “Gray”)
Dim pg As Page = doc.GetPage(1)
draw.SetImageSize(1000, 1000)
draw.Export(pg, outputPath + Path.GetFileNameWithoutExtension(SeparationFile) + “.png”, “PNG”, gray_hint)
End Using
Next
End Using

'convert grayscale png’s to color png’s based on file name
For each separationPng In Directory.GetFiles(outputPath)
Dim bmp As New Bitmap(separationPng)
Dim x, y, r, g, b As Integer
For x = 0 To bmp.Width - 1
For y = 0 To bmp.Height - 1
r = bmp.GetPixel(x, y).R
g = bmp.GetPixel(x, y).G
b = bmp.GetPixel(x, y).B
If separationPng.Contains(“cyan”) Then bmp.SetPixel(x, y, Color.FromArgb(r, 255, 255))
If separationPng.Contains(“magenta”) Then bmp.SetPixel(x, y, Color.FromArgb(255, g, 255))
If separationPng.Contains(“yellow”) Then bmp.SetPixel(x, y, Color.FromArgb(255, 255, b))
If separationPng.Contains(“black”) Then bmp.SetPixel(x, y, Color.FromArgb((r + b + g) / 3, (r + b + g) / 3, (r + b + g) / 3))
Next y
Next x
If separationPng.Contains(“cyan”) Then
bmp.Save(outputPath + “001_cyan_final.png”)
bmp.Dispose()
File.Delete(separationPng)
Else If separationPng.Contains(“magenta”) Then
bmp.Save(outputPath + “002_magenta_final.png”)
bmp.Dispose()
File.Delete(separationPng)
Else If separationPng.Contains(“yellow”) Then
bmp.Save(outputPath + “003_yellow_final.png”)
bmp.Dispose()
File.Delete(separationPng)
Else If separationPng.Contains(“black”) Then
bmp.Save(outputPath + “004_black_final.png”)
bmp.Dispose()
File.Delete(separationPng)
End If
Next

'build new composite pdf with colorized png’s
Dim hintSet As ObjSet = New ObjSet
Using doc As New PDFDoc
Using builder As New ElementBuilder
Using writer As New ElementWriter
Dim page As Page = doc.PageCreate(New Rect(0, 0, 1000, 1000))
For Each SeparationFile In Directory.GetFiles(outputPath)
writer.Begin(page)
Dim cmyk_hint As Obj = hintSet.CreateDict()
cmyk_hint.PutName(“ColorSpace”, “CMYK”)
Dim img = Image.Create(doc, SeparationFile, cmyk_hint)
Dim element As Element = builder.CreateImage(img, 1, 1, img.GetImageWidth(), img.GetImageHeight())
element.GetGState().SetFillOpacity(1)
element.GetGState().SetBlendMode(GState.BlendMode.e_bl_lighten)
writer.WritePlacedElement(element)
writer.End()
File.Delete(SeparationFile)
Next
doc.PagePushBack(page)
End Using
End Using
doc.Save(outputPath + “composite.pdf”, SDF.SDFDoc.SaveOptions.e_remove_unused)
End Using