title: "Parameter is not valid" error when extracting images using iTextSharp from a PDF containing JPXDecode filter
body: <p>I am trying to extract images from a PDF using the following code. It works well for some filters like DCTDecode , but is not working for JPXDEcode ."Parameter not valid " error occurs at the point image.GetDrawingImage() is called.</p>
  
  <pre><code> using System.Drawing.Imaging;
      using iTextSharp.text.pdf;
      using iTextSharp.text.pdf.parser;
      ...
      PdfReader pdf = new PdfReader(currfilename);
       PdfReaderContentParser parser = new PdfReaderContentParser(pdf);
       ImageRender listener = new ImageRender();
       for (int i = 1; i &lt;= pdf.NumberOfPages; i++)
       {
            try
            {
                parser.ProcessContent(i, listener);//calls RenderImage() at this point
  
             }
             catch (Exception e)
             {
                  Console.WriteLine(e);
             }
  
        }
  
  
      public void RenderImage(ImageRenderInfo renderInfo)
              {
                  PdfImageObject image = renderInfo.GetImage();
                  PdfName filter = image.Get(PdfName.FILTER) as PdfName;
  
  
                  if (renderInfo.GetRef() != null &amp;&amp; image != null)
                  {
                      using (System.Drawing.Image dotnetImg = image.GetDrawingImage())//exception occurs at this point
                      {
                          if (dotnetImg != null)
                          {
                              ImageNames.Add(string.Format("{0}.tiff", renderInfo.GetRef().Number));
                              using (MemoryStream ms = new MemoryStream())
                              {
                                  dotnetImg.Save(ms, ImageFormat.Tiff);
                                  Images.Add(ms.ToArray());
                              }
                          }
                      }
                  }
  
  
  
              }
  </code></pre>
  
  <p>I tried these links for a solution </p>
  
  <p><a href="https://stackoverflow.com/questions/802269/extract-images-using-itextsharp">Extract images using iTextSharp</a></p>
  
  <p><a href="https://stackoverflow.com/questions/10689382/extract-image-from-a-particular-page-in-pdf-using-itextsharp-4-0">Extract Image from a particular page in PDF</a></p>
  
  <p>and was able  to extract the raw image bytes using PdfReader.GetStreamBytesRaw() function but "Parameter not valid "exception always occurs at the point where  System.Drawing.Image.FromStream(memory stream) is called. </p>
  
  <p>I also checked this link <a href="https://stackoverflow.com/questions/3586878/parameter-is-not-valid-exception-from-system-drawing-image-fromstream-method">&quot;Parameter is not valid&quot; exception from System.Drawing.Image.FromStream() method</a>  , but could not find anything helpful.</p>
  
  <p>Please help</p>