How to recolor vector image/path?


So far your library seems very good but I am having trouble
implementing one of the last features that I need.

Right now I am trying to open a pdf that contains a vector image and
recolor the image and add it to a new pdf. Everything is working
except for the color change. I looked at the sample that shows how to
do this for text and tried something similar but it did not work. Any
help would be appreciated.

Right now my code looks something like:

pdftron.PDF.ElementReader reader = new pdftron.PDF.ElementReader();

pdftron.PDF.Element someElement;
while ((someElement = reader.Next()) != null) {

  someElement.GetGState ().SetFillColor(new pdftron.PDF.ColorPt(0, 0,


Regarding color and content editing, it seems that you are using
ElementReader to read page content (Elements) and then you are
modifying the color space and fill color for (all elements). However
it seems that you are never writing content to a modified page (using

As an example of how to do this please take a look at ElementEdit
sample project:

The code for changing fill color on 'path' elements may look as

ElementWriter writer = new ElementWriter();
ElementReader reader = new ElementReader();
Element element;

while ((element = reader.Next()) != null) {
  if (element.GetType() == Element.Type.e_path) {
    GState gs = element.GetGState();
    gs.SetFillColor(new ColorPt(0, 0, 1));
    // element.SetPathFill (true); // to enable fill filling for all

I am still having trouble with the recoloring. The pdf that I want to
recolor is a vector image, usually 2 color, occasionally more. Here
are the methods I have tried. ( I sent you this sample earlier but as
you pointed out, I had things confused )

My end goal is to be able to do one of two things. Either arbitrarily
replace one color in the source image with another .. so change all
the black in the pdf to red. Or to be able to change all of the non
transparent color (or fill) into some specified color.

Again Thanks

#region Import Pdf
        //This works for importing the pdf but it does not change any
of the colors
        pdftron.PDF.Element clipart =
f.CreateForm(clipartDoc.PageFind(1).Current(), myNewPdf);
        clipart.GetGState().SetTransform(scale / 2, 0, 0, scale / 2,
20, 180);

        clipart.GetGState().SetFillColor(new pdftron.PDF.ColorPt(1, 0,

        #region Import Pdf 2
        //This method works and changes colors ... but some pdfs lose
pieces of the images .. in the parking pdf the outer circle disapears

        pdftron.PDF.ElementReader reader = new
        pdftron.PDF.Element someElement;
        while ((someElement = reader.Next ()) != null) // Read
page contents
            Response.Write(someElement.GetType() + "</br>");

() );

pdftron.PDF.ColorPt(0, 0, 1));
pdftron.PDF.ColorPt(0, 0, 1));
            writer.WritePlacedElement (someElement);



It seems that you modified the stroke colorant (assuming RGB) but your
didn't modify stroke color space.

You just need to add:

() );

in your 'for' loop.