title: Unable to cast object of type 'iTextSharp.text.pdf.PdfArray' to type 'iTextSharp.text.pdf.PRStream'
body: <p>I have to replace number "14-1" into "10-2". I am using following iText code but getting following type cast error. Can any one help me by modifying the program and remove the casting issue:</p>
  
  <p>I have many PDF's where i have to replace the numbers at same location. I also need to understand it logically to how to do this:</p>
  
  <pre><code>using System;
  using System.IO;
  using System.Text;
  using iTextSharp.text.io;
  using iTextSharp.text.pdf;
  
  using System.Windows.Forms;
  
  namespace iText5
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }
  
          public const string src = @"D:\test1\A.pdf";
          public const string dest = @"D:\test1\ENV1.pdf";
  
          private void button1_Click(object sender, EventArgs e)
          {
              FileInfo file = new FileInfo(dest);
              file.Directory.Create();
              manipulatePdf(src, dest);
          }
  
          public void manipulatePdf(String src, String dest)
          {
  
          PdfReader reader = new PdfReader(src);
          PdfDictionary dict = reader.GetPageN(1);
  
          PdfObject obj = dict.GetDirectObject(PdfName.CONTENTS);
  
          PRStream stream = (PRStream)obj;
  
          byte[] data = PdfReader.GetStreamBytes(stream);
          string xyz = Encoding.UTF8.GetString(data);
  
          byte[] newBytes = Encoding.UTF8.GetBytes(xyz.Replace("14-1", "10-2"));
          stream.SetData(newBytes);
  
          PdfStamper stamper = new PdfStamper(reader, new FileStream(dest, FileMode.Create));
          stamper.Close();
          reader.Close();
  
          }
  
      }
  }
  </code></pre>