简体   繁体   中英

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

是否可以使用C#中的iTextSharp修改PDF中的专色名称,它只是需要更改的颜色名称。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM