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