public ActionResult ChangeSignature()
        {
            try
            {
                if (!string.IsNullOrEmpty(Request.Params["idPage"]))
                {
                    int idPage = Convert.ToInt32(Request.Params["idPage"]);
                    string filePath = string.Empty;
                    string srcimagePath = string.Empty;
                    SessionManager.Get<string>(FilePathIdSessionKey, out filePath);
                    SessionManager.Get<string>(ImageIdSessionKey, out srcimagePath);

                    DirectoryInfo dir = new DirectoryInfo(srcimagePath);
                    foreach (FileInfo fi in dir.GetFiles().Where(f => f.Extension == ".png"))
                    {
                        fi.Delete();
                    }

                    string nomPage = string.Format("Image{0}.png", idPage.ToString());
                    string imagePath = Path.Combine(srcimagePath, nomPage);
                    RasterizerPDF pdf = new RasterizerPDF(filePath, imagePath, idPage);
                    pdf.Rasterize();

                }
                return Content("OK");
            }
            catch (Exception ex)
            {
                Business.Log.Log.AppendException(ex);
                return Content(ex.Message);
            }



        }
        public PartialViewResult SignaturePosition(string id, string doctype)
        {
            var pdfSigModel = new PdfSignatureModel();
            try
            {
                if (!string.IsNullOrEmpty(id))
                {
                    Guid idDocument = new Guid(id);
                    //
                    pdfSigModel.idDocument = id;
                    //get document with signatory 
                    Document document1 = DocumentBL.GetDocumentWithSignatoryById(idDocument);
                    pdfSigModel.LstSignatory = document1.SignatureTransaction.Signatory.ToList();
                    //get document with document signatory 
                    Document document2 = DocumentBL.GetDocumentWithDocumenSignatoryById(idDocument);
                    pdfSigModel.LstDocumentSignatory = document2.DocumentSignatory.ToList();

                    pdfSigModel.LstNewSignatory = new HashSet<Signatory>(pdfSigModel.LstSignatory.Select(u => u)).ToList();
                    pdfSigModel.DocType = doctype;

                    //current page
                    int currentPage = 1;
                    if (document1 != null && document1.PageCount > 0)
                    {
                        //cherche si la signature est déjà enregistrer
                        if (document2.DocumentSignatory != null && document2.DocumentSignatory.Count > 0)
                        {
                            DocumentSignatory docsignatory = document2.DocumentSignatory.FirstOrDefault();
                            if (docsignatory != null)
                            {
                                currentPage = docsignatory.Page;
                            }
                            //

                        }
                        //Rasterizer PDF
                        string filePath = Path.Combine(Server.MapPath("~/uploads"), document1.Location, document1.Name);
                        string srcimagePath = Path.Combine(Server.MapPath("~/uploads"), document1.Location);
                        string imagePath = Path.Combine(Server.MapPath("~/uploads"), document1.Location, "Image" + id + ".png");
                        string src = string.Format("{0}{1}", Url.Content("~/uploads/"), document1.Location.Replace("\\", "/"));
                        ViewBag.imgsrc = src;

                        var dir = new DirectoryInfo(srcimagePath);
                        foreach (FileInfo fi in dir.GetFiles().Where(f => f.Extension == ".png"))
                        {
                            fi.Delete();
                        }
                        var pdf = new RasterizerPDF(filePath, imagePath);
                        pdf.Rasterize();
                        //dropdownlist
                        var items = new List<SelectListItem>();
                        for (int i = 1; i <= document1.PageCount; i++)
                        {
                            items.Add(new SelectListItem { Text = i.ToString(), Value = i.ToString() });
                        }
                        ViewBag.SelectPage = items;
                        ViewBag.Selected = currentPage;
                        ViewBag.NombrePage = document1.PageCount;

                    }


                }
                return PartialView("SignaturePositionPartial", pdfSigModel);
            }
            catch (Exception ex)
            {
                Business.Log.Log.AppendException(ex);
                return PartialView("RetourPartial", ex.Message);
            }
        }
        public ActionResult SignaturePosition(string id)
        {
            PdfSignatureModel pdfSigModel = new PdfSignatureModel();
            try
            {
                if (!string.IsNullOrEmpty(id))
                {
                    Guid idDocument = new Guid(id);
                    SessionManager.Set<Guid>(DocumentIdSessionKey, idDocument);
                    //
                    pdfSigModel.idDocument = id;
                    //get document with signatory 
                    Document document1 = DocumentBL.GetDocumentWithSignatoryById(idDocument);
                    pdfSigModel.LstSignatory = document1.SignatureTransaction.Signatory.ToList();
                    //get document with document signatory 
                    Document document2 = DocumentBL.GetDocumentWithDocumenSignatoryById(idDocument);
                    pdfSigModel.LstDocumentSignatory = document2.DocumentSignatory.ToList();
                    //new signatory

                    //HAJA Update
                    //var list = from item1 in pdfSigModel.LstSignatory
                    //           where !(pdfSigModel.LstDocumentSignatory.Any(item2 => item2.idSignatory == item1.idSignatory))
                    //           select item1;
                    var list = from item1 in pdfSigModel.LstSignatory select item1;
                    //HAJA Update
                    pdfSigModel.LstNewSignatory = list.ToList<Signatory>();
                    //current page
                    int currentPage = 1;
                    if (document1 != null && document1.PageCount > 0)
                    {
                        //cherche si la signature est déjà enregistrer
                        if (document2.DocumentSignatory != null && document2.DocumentSignatory.Count > 0)
                        {
                            DocumentSignatory docsignatory = document2.DocumentSignatory.FirstOrDefault();
                            if (docsignatory != null)
                            {
                                currentPage = docsignatory.Page;
                            }
                            //

                        }
                        //Rasterizer PDF
                        string filePath = Path.Combine(Server.MapPath("~/uploads"), document1.Location, document1.Name);
                        string srcimagePath = Path.Combine(Server.MapPath("~/uploads"), document1.Location);
                        //string nomPage = string.Format("Image{0}.png", currentPage.ToString());
                        string imagePath = Path.Combine(Server.MapPath("~/uploads"), document1.Location, "Image" + id + ".png");
                        SessionManager.Set<string>(FilePathIdSessionKey, filePath);
                        SessionManager.Set<string>(ImageIdSessionKey, srcimagePath);
                        //string src = string.Format("/uploads/{0}", document.Location.Replace("\\", "/"));
                        string src = string.Format("{0}{1}", Url.Content("~/uploads/"), document1.Location.Replace("\\", "/"));
                        ViewBag.imgsrc = src;
                        DirectoryInfo dir = new DirectoryInfo(srcimagePath);
                        foreach (FileInfo fi in dir.GetFiles().Where(f => f.Extension == ".png"))
                        {
                            fi.Delete();
                        }
                        RasterizerPDF pdf = new RasterizerPDF(filePath, imagePath);
                        pdf.Rasterize();
                        //dropdownlist
                        List<SelectListItem> items = new List<SelectListItem>();
                        for (int i = 1; i <= document1.PageCount; i++)
                        {
                            items.Add(new SelectListItem { Text = i.ToString(), Value = i.ToString() });
                        }
                        ViewBag.SelectPage = items;
                        ViewBag.Selected = currentPage;
                        ViewBag.NombrePage = document1.PageCount;

                    }


                }
                return View("SignaturePosition", pdfSigModel);
            }
            catch (Exception ex)
            {
                Business.Log.Log.AppendException(ex);                
                TempData["DocumentError"] = ex.Message;
                return RedirectToAction("Transaction");
            }

        }