0

I am able to scan the image using wia. After scanning I am trying to attach that scanned image. Below is the code but I am getting following error message:

microsoft.csharp.runtimebinder.runtimebinderexception:cannot perform runtime binding on a null reference.

 private async void Button_Click_3(object sender, RoutedEventArgs e)
 {
     lblLoading_Copy.Content = "Loading . . .";
     //lblLoading.Refresh();
     await Task.Delay(1000);
     try
     {
         using (var ms = new MemoryStream())
         {
             var document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0);
             iTextSharp.text.pdf.PdfWriter.GetInstance(document, ms).SetFullCompression();
             document.Open();

             foreach (System.Drawing.Image aa in obj)
             {
                 MemoryStream msimage = new MemoryStream();

                 aa.Save(msimage, ImageFormat.Jpeg);

                 var image = iTextSharp.text.Image.GetInstance(msimage.ToArray());
                 image.ScaleToFit(document.PageSize.Width, document.PageSize.Height);
                 document.Add(image);
             }
             document.Close();
             string Path = ConfigurationManager.AppSettings["uploadfolderpath"].ToString();//confige path

             string filename = "C3kycDMS" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf";

             //Save using drive name
             //File.WriteAllBytes(Path + filename, ms.ToArray());
             byte[] test = ms.ToArray();

             Service1.Service objService = new Service1.Service();
             string result = objService.SaveScanedDocument(test, filename, 0);

             if (result == "")
             {
                 MessageBox.Show("File Upload unsuccessfull", "Error!", MessageBoxButton.OKCancel);
                 lblLoading_Copy.Content = "";
             }
             else
             {
                 // MessageBox.Show("File Upload successfull", "Success!", MessageBoxButton.OKCancel);
                 lblLoading_Copy.Content = "";
             }
             pic_scan.Source = null;

             var hostScript = BrowserInteropHelper.HostScript;

             hostScript.document.ResponseData(filename);
             // return ms.ToArray();
         }
     }
     catch (Exception ex)
     {
         //MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OKCancel);
         lblLoading.Content = "";
     }
TheLethalCoder
  • 6,875
  • 6
  • 31
  • 58
NIRANJAN G
  • 69
  • 1
  • 9

0 Answers0