Mark Redman
Mark Redman

Reputation: 24515

Is it possible to modify spot color names in a PDF using iTextSharp in C#?

Is it possible to modify spot color names in a PDF using iTextSharp in C#, its just the Colour name that requires changing.

Upvotes: 1

Views: 1377

Answers (1)

Bruno Lowagie
Bruno Lowagie

Reputation: 77528

So you have an existing PDF that uses some spot colors, for instance a color named "ABC", and you want to manipulate that PDF so that the name is "XYZ".

This is possible, but it requires low-level PDF syntax manipulation.

You need to create a PdfReader instance, look for the dictionary that defines the spot color, change the name, then use PdfStamper to create a new file based on the altered PdfReader instance.

There is no "ready-made" example on how to answer your specific question (I doubt somebody else but the original developer of iText will answer a question like this), but you can get some inspiration by looking at the code samples from chapter 13 of the second edition of "iText in Action": http://itextpdf.com/book/chapter.php?id=13

See for instance the manipulatePdf() method in this example: http://itextpdf.com/examples/iia.php?id=239 In this example an URL is replaced by another one using the principle explained above.

You need to adapt this example so that you find the path to the place where the spot color name is stored, change that name, and persist the changes.

Hint: the Spot color name will be in an array of which the first element is a name (/Separation), the second entry will be the name you want to change (this is the one you want to replace with a new PdfName instance), and so on.

How to find this /Separation array? I would loop over the pages (the getPageN() method will give you the page dictionary), get the resources of every page (pageDict.getAsDict(PdfName.RESOURCES)), look for the existence of a /Colorspace dictionary, then look for all the /Separation colors in that dictionary. Replace the second element whenever you encounter a name you want to change.

The examples in chapter 13 in combination with ISO-32000-1 (can be downloaded from the Adobe.com site) will lead the way.

Upvotes: 4

Related Questions