How to use WriteGStateChanges

,
PDFDoc doc(input_path.c_str());
PageIterator itr;
ElementReader page_reader;
for (itr = doc.GetPageIterator(); itr.HasNext(); itr.Next())
{
                page_reader.Begin(itr.Current());
		writer.Begin(itr.Current())
                for (Element element = page_reader.Next(); element; element = page_reader.Next()) 
		{
			switch (element.GetType())
			{
				case Element::e_path:						// Process path data...
				{
					
					GState gs = element.GetGState();
					gs.SetFillColorSpace(ColorSpace::CreatePattern());
					gs.SetFillColor(CreateImageTilingPattern(doc));
					element.SetPathFill(true);
					writer.WriteGStateChanges(element);
				}
				break;
				
				}
			}
			writer.End();	// Save the page
			page_reader.End();
}
doc.Save((output_path + "output.pdf").c_str(), SDFDoc::e_remove_unused, 0);

i just want to save gs changes. use as the code above will write nothing to the pdf file and get reader can not deconstruction error!