How do I edit a PDF page without creating a new page?

Q: I am looking at trying to use your new API (new in 5.0.2) to be
able to edit text on the page of a PDF without having to copy all of
the page content over to a new page.

I have been experimenting with using the element writer with the
replacement option and starting at the page that is already in the
PDF. The EditTextTest.cs appears to use the old method of changing
text.

2. Do you have a sample inline editing of content on a page?
3. I am trying to get to be able to change the colour of a text token
and all future text tokens being their original colour. Is this
possible? I believe I have this worked out – but am not sure I am
doing it correctly.
4. I am also trying to be able to split up a text token and change the
colour of one or more of the pieces of the original text tokens. I
cannot get this to work. The biggest problem is getting new pieces of
text to have the correct placement.
-------------------
A: > 1. Do you have a sample inline editing of content on a page?

Attached is the updated ElementEdit sample.

change the colour of a text token and all future text tokens being
their original colour. Is this possible?

Yes this is possible. You would need to change the color in the
subsequent element to the previous color (e.g. using a temporary
value).

4. I am also trying to be able to split up a text token and change
the colour of one or more of the pieces of the original text tokens.

You may want to take a look at the following sample
http://pdfnet-sdk.googlegroups.com/web/RecolorPDFText.zip.

Updated ElementEdit sample:

using System;
using pdftron;
using pdftron.Common;
using pdftron.Filters;
using pdftron.SDF;
using pdftron.PDF;

namespace ElementEditTestCS
{
  /// <summary>
  /// The sample code shows how to edit the page display list and how
to modify graphics state
  /// attributes on existing Elements. In particular the sample program
strips all images from
  /// the page and changes text color to blue.
  /// </summary>
  class ElementEditTest
  {
    // Helper function
    static void ProcessElements(ElementReader reader, ElementWriter
writer)
    {
      Element element;
      while ((element = reader.Next()) != null) // Read page contents
      {
        switch (element.GetType())
        {
          case Element.Type.e_path: break;
          case Element.Type.e_image:
          case Element.Type.e_inline_image:
            // remove all images by skipping them
            continue;
          case Element.Type.e_text: {
            // Set all text to blue color.
            GState gs = element.GetGState();
            gs.SetFillColorSpace(ColorSpace.CreateDeviceRGB());
            gs.SetFillColor(new ColorPt(0, 0, 1));
            break;
          }
          case Element.Type.e_form: {
            reader.FormBegin();
            ProcessElements(reader, writer);
            reader.End();
            break;
          }
        }

        writer.WriteElement(element);
      }
    }

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {
      PDFNet.Initialize();

      // Relative path to the folder containing test files.
      string input_path = "../../../../TestFiles/";
      string output_path = "../../../../TestFiles/Output/";

      try
      {
        PDFDoc doc = new PDFDoc(input_path + "newsletter.pdf");
        doc.InitSecurityHandler();

        int num_pages = doc.GetPageCount();

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

        for (int i = 1; i <= num_pages; ++i) {
          Page page = doc.GetPage(i);
          reader.Begin(page);
          writer.Begin(page, ElementWriter.WriteMode.e_replacement);
          ProcessElements(reader, writer);
          writer.End();
          reader.End();
        }

        writer.Dispose();
        reader.Dispose();
        doc.Save(output_path + "newsletter_edited.pdf",
SDFDoc.SaveOptions.e_remove_unused);
        doc.Close();
        Console.WriteLine("Done. Result saved in
newsletter_edited.pdf...");
      }
      catch (PDFNetException e)
      {
        Console.WriteLine(e.Message);
      }
    }
  }
}