How to recolor vector image/path?

Q:

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;
reader.Begin(clipartDoc.PageFind(1).Current());
while ((someElement = reader.Next()) != null) {

someElement.GetGState().SetFillColorSpace(pdftron.PDF.ColorSpace.CreateDeviceRGB());
  someElement.GetGState ().SetFillColor(new pdftron.PDF.ColorPt(0, 0,
1));
}
reader.End();
-----

A:

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
ElementWriter).

As an example of how to do this please take a look at ElementEdit
sample project:
  http://www.pdftron.com/net/samplecode.html#ElementEdit

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

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

reader.Begin(itr.Current());
writer.Begin(new_page);
while ((element = reader.Next()) != null) {
  if (element.GetType() == Element.Type.e_path) {
    GState gs = element.GetGState();
    gs.SetFillColorSpace(ColorSpace.CreateDeviceRGB());
    gs.SetFillColor(new ColorPt(0, 0, 1));
    // element.SetPathFill (true); // to enable fill filling for all
paths.
  }
  writer.WriteElement(element);
}

Q:
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().SetFillColorSpace(pdftron.PDF.ColorSpace.CreateDeviceRGB
());
        clipart.GetGState().SetFillColor(new pdftron.PDF.ColorPt(1, 0,
0));
        writer.WritePlacedElement(clipart);
        #endregion

        #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.ElementReader();
        pdftron.PDF.Element someElement;
        reader.Begin(clipartDoc.PageFind(1).Current());
        while ((someElement = reader.Next ()) != null) // Read
page contents
        {
            Response.Write(someElement.GetType() + "</br>");

someElement.GetGState().SetFillColorSpace(pdftron.PDF.ColorSpace.CreateDeviceRGB
() );

            someElement.GetGState().SetStrokeColor(new
pdftron.PDF.ColorPt(0, 0, 1));
            someElement.GetGState().SetFillColor(new
pdftron.PDF.ColorPt(0, 0, 1));
            writer.WritePlacedElement (someElement);

        }

        reader.End();
        #endregion
---
A:

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

You just need to add:

someElement.GetGState().SetFillColorSpace(pdftron.PDF.ColorSpace.CreateDeviceRGB
() );

in your 'for' loop.