title: Extract an image (QR code image) from PDF file in c#
body: <p>I've taken this code from <a href="https://stackoverflow.com/questions/5945244/extract-image-from-pdf-using-itextsharp">Extract image from PDF using itextsharp</a> 
  but it did not work for me, i guess because of the iTextSharp version.</p>
  
  <p>Below is the code, ant it show me error at  <code>ImageRenderInfo imgRI = ImageRenderInfo.CreateForXObject(new Matrix(float.Parse(width), float.Parse(height)), (PRIndirectReference)obj, tg);</code> </p>
  
  <p>saying that:</p>
  
  <blockquote>
    <p>Argument1: cannot convert from iTextSharp.text.pdf.parser.Matrix to
    iTextSharp.text.pdf.parser.GraphicsState</p>
  </blockquote>
  
  <pre><code>    string imgPath = "";
      private void ExtractImage(string pdfFile)
      {
          PdfReader pdfReader = new PdfReader(@"");
          for (int pageNumber = 1; pageNumber &lt;= pdfReader.NumberOfPages; pageNumber++)
          {
              PdfReader pdf = new PdfReader(pdfFile);
              PdfDictionary pg = pdf.GetPageN(pageNumber);
              PdfDictionary res = (PdfDictionary)PdfReader.GetPdfObject(pg.Get(PdfName.RESOURCES));
              PdfDictionary xobj = (PdfDictionary)PdfReader.GetPdfObject(res.Get(PdfName.XOBJECT));
              foreach (PdfName name in xobj.Keys)
              {
                  PdfObject obj = xobj.Get(name);
                  if (obj.IsIndirect())
                  {
                      PdfDictionary tg = (PdfDictionary)PdfReader.GetPdfObject(obj);
                      string width = tg.Get(PdfName.WIDTH).ToString();
                      string height = tg.Get(PdfName.HEIGHT).ToString();
  
                      ImageRenderInfo imgRI = ImageRenderInfo.CreateForXObject(new Matrix(float.Parse(width), float.Parse(height)), (PRIndirectReference)obj, tg);
  
                      RenderImage(imgRI);
                  }
              }
          }
      }
      private void RenderImage(ImageRenderInfo renderInfo)
      {
          PdfImageObject image = renderInfo.GetImage();
          using (Dotnet dotnetImg = image.GetDrawingImage())
          {
              if (dotnetImg != null)
              {
                  using (MemoryStream ms = new MemoryStream())
                  {
                      dotnetImg.Save(ms, ImageFormat.Tiff);
                      Bitmap d = new Bitmap(dotnetImg);
                      d.Save(imgPath);
                  }
              }
          }
      }
  
      private void Form1_Load(object sender, System.EventArgs e)
      {
  
      }
  }
  </code></pre>
  
  <p>P.S: i'm a beginner in C# language (its syntax)</p>
  
  <p>Thanks, </p>