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);
}