Rajesh Kumar

Rajesh Kumar

  • NA
  • 222
  • 38.9k

Parameter is Not Valid Error

Dec 10 2020 8:53 PM
We are working on Integration project which will get information from SOAP and output getting in byte. now i am trying to write it into memory stream to convert to PDF, but i am getting error message as below
 
"Parameter is Not Valid"
 
  1. public string getimage(string s)  
  2.         {  
  3.             // var bytes = s;  
  4.   
  5.   
  6.             byte[] bytes = Convert.FromBase64String(s);  
  7.               Image image1;  
  8.             try  
  9.             {  
  10.                   using (var ms = new MemoryStream(bytes, 0, bytes.Length))  
  11.   
  12.                 {  
  13.   
  14.                     ms.Seek(0, SeekOrigin.Begin);  
  15.                     ms.Position = 0;  
  16.   
  17.                     using (image1 = Image.FromStream(ms, true))  
  18.                     {  
  19.   
  20.                       
  21.                     using (Image imageFile = image1)  
  22.                     {  
  23.                         FrameDimension frameDimensions = new FrameDimension(  
  24.                             imageFile.FrameDimensionsList[0]);  
  25.   
  26.                         int frameNum = imageFile.GetFrameCount(frameDimensions);  
  27.                         string[] jpegPaths = new string[frameNum];  
  28.                         PdfDocument doc = new PdfDocument();  
  29.                         for (int frame = 0; frame < frameNum; frame++)  
  30.                         {  
  31.                             imageFile.SelectActiveFrame(frameDimensions, frame);  
  32.                             doc.Pages.Add(new PdfPage());  
  33.                             XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[frame]);  
  34.                             using (Bitmap bmp = new Bitmap(imageFile))  
  35.                             {  
  36.                                 using (var ms11 = new MemoryStream())  
  37.                                 {  
  38.                                     bmp.Save(ms11, System.Drawing.Imaging.ImageFormat.Png);  
  39.                                     XImage img = XImage.FromStream(ms11);  
  40.   
  41.                                     PdfPage page = new PdfPage();  
  42.   
  43.                                     xgr.DrawImage(img, 0, 0, 595, 842);  
  44.                                 }  
  45.                             }  
  46.                         }  
  47.   
  48.                         byte[] fileContents = null;  
  49.                         using (MemoryStream stream = new MemoryStream())  
  50.                         {  
  51.                             doc.Save(stream, true);  
  52.                             fileContents = stream.ToArray();  
  53.                         }  
  54.   
  55.                         TempData["file"] = Convert.ToBase64String(fileContents);  
  56.                         doc.Close();  
  57.   
  58.                         return Convert.ToBase64String(fileContents);  
  59.                     }  
  60.                 }  
  61.                 }  
  62.             }  
  63.             catch (Exception ex)  
  64.             {  
  65.                 throw ex;  
  66.             }  
  67.   
  68.         }  
Can someone suggest me what is wrong here here is my code as well. Getting error in row number 10.
 

Answers (4)