//public Foxit.PDF.Merger.MergeDocument GenerateFirstPage(bool isCorporation, Guid pRef)
        //{
        //    Foxit.PDF.Merger.MergeDocument.AddLicense("FMG10NPSDF7PKOQYa7ujmP5EZVdhjEkHYGJFLFvhhZYIqipH+LYqgr1xvuMSJ0eLfVUjOkFtZ5XTe0rwWQg65rsmoU2AXhb6GdqQ");
        //    Foxit.PDF.Merger.MergeDocument doc = new Foxit.PDF.Merger.MergeDocument();
        //    doc.Creator = "Upsilab";
        //    doc.Author = "Upsideo";

        //    Page p = new Page();
        //    doc.Pages.Add(p);

        //    float y = 100;
        //    Add_Title_Center_CalibriBold_Label("LETTRE DE MISSION", y, p, 500, 100);
        //    if (isCorporation)
        //        Add_SubTitle_Center_CalibriBold_Label("PERSONNE MORALE", y += 100, p, 500, 20);
        //    else
        //        Add_SubTitle_Center_CalibriBold_Label("PERSONNE PHYSIQUE", y += 100, p, 500, 20);

        //    string[] rowContents = { string.Format("Le {0}", DateTime.Now.ToShortDateString()), //Date de maj ou Date de création
        //                               string.Format("Ref. LM-{0}",pRef) };
        //    LM_AddTableTitle(p, rowContents, 90, y += 80);

        //    return doc;
        //}

        public Byte[] GenerateLastPage(bool forceDownload)
        {
            Foxit.PDF.Document.AddLicense("FGN10NPSFJ3NIENDBQAhEYH7Lnw6aN3EPdVsY6K17yfDAMgA+J1aWeRq0RYcA5IzDqjZbvIixFuPLyBaVpLk9vcnyu1cg3ZrXmQA");
            Foxit.PDF.Document doc = new Foxit.PDF.Document();
            Page p = new Page();
            doc.Pages.Add(p);

            float y = 0;
            //Signature
            AddSubtitlePage(@"Signatures", p, 0);

            AddDefaultBoldTextPage(@"Signature de l'Etablissement", p, 100, 500, 20, 80);


            AddBlueBorderPage(130, p, 35, 200, 170);

            //Ne pas afficher si signature electronique
            if (forceDownload)
            {
                AddDefaultTextPage(@"J'ai lu et j'accepte les conditions générales.", p, 135, 200, 20, 40);
                AddDefaultTextPage(@"Lu et approuvé.", p, 145, 145, 20, 40);
                AddDefaultTextPage(@"Date:", p, 160, 145, 20, 40);
            }

            AddDefaultBoldTextPage(@"Signature du Client", p, 100, 500, 20, 340);
            AddBlueBorderPage(130, p, 280, 200, 170);

            if (forceDownload)
            {
                AddDefaultTextPage(@"J'ai lu et j'accepte les conditions générales.", p, 135, 200, 20, 285);
                AddDefaultTextPage(@"Lu et approuvé.", p, 145, 145, 20, 285);
                AddDefaultTextPage(@"Date:", p, 160, 145, 20, 285);
            }
            return doc.Draw();
        }
        public byte[] GenerateFirstPage(bool? isCorporation, Guid pRef, string logoPathFileName, DocumentType pType, string docTitle, string ownerName, string logoAlign)
        {
            Foxit.PDF.Document.AddLicense("FGN10NPSFJ3NIENDBQAhEYH7Lnw6aN3EPdVsY6K17yfDAMgA+J1aWeRq0RYcA5IzDqjZbvIixFuPLyBaVpLk9vcnyu1cg3ZrXmQA");
            Foxit.PDF.Document doc = new Foxit.PDF.Document();

            Page p = new Page();
            doc.Pages.Add(p);

            AddBackgroungImagePage(p);
            //Logo
            AddLogo(logoPathFileName, logoAlign, p);


            // float y = 260;
            float y = 380;
            switch (pType)
            {
                case DocumentType.LM:

                    AddWhiteTitlePage("LETTRE DE MISSION", p, y, 240, 60, 260, 20);
                    if (isCorporation.Value)
                        AddWhiteTitlePage("PERSONNE MORALE", p, y += 45, 500, 20, 0, 12);
                    else
                        AddWhiteTitlePage("PERSONNE PHYSIQUE", p, y += 45, 500, 20, 0, 12);
                    break;

                case DocumentType.RM:
                    AddWhiteTitlePage("RAPPORT DE MISSION", p, y, 240, 60, 260, 20);
                    break;

                case DocumentType.RTO:
                    AddWhiteTitlePage("Convention de Réception Transmission d’Ordres", p, y, 240, 80, 260, 14);
                    AddWhiteTitlePage("RTO", p, y += 15 * 2.3f, 500, 20, 0, 12);
                    break;

                case DocumentType.BS: //présentation de l'etablissement
                    AddWhiteTitlePage("Présentation de l'établissement", p, y, 240, 80, 260, 14);
                    break;

                case DocumentType.DER:
                    AddWhiteTitlePage("Document d'entrée en relation", p, y, 240, 80, 260, 14);
                    break;

                case DocumentType.AX:
                    AddWhiteTitlePage(docTitle, p, y, 240, 80, 260, 14);
                    break;

                case DocumentType.CPART:
                    AddWhiteTitlePage("Convention de Partenariat", p, y, 240, 80, 260, 14);
                    break;

                case DocumentType.CINT:
                    AddWhiteTitlePage("Convention Internet", p, y, 240, 80, 260, 14);
                    break;

                case DocumentType.CCOURT:
                    AddWhiteTitlePage("Convention de Co-Courtage", p, y, 240, 80, 260, 14);
                    break;

                case DocumentType.CCOMP:
                    AddWhiteTitlePage("Fiche de renseignement complémentaire", p, y, 240, 80, 260, 14);
                    break;

                case DocumentType.SF:
                    AddWhiteTitlePage("Bulletin de Souscription", p, y, 240, 80, 260, 14);
                    break;

            }
            
            AddWhiteBorderPage(y += 15 * 2f, p, 210, 290, 70);

            AddWhiteTitleLeftPage(DateTime.Now.ToShortDateString(), p, y += 10, 500, 11, 220, 10);
            AddWhiteTitleLeftPage(ownerName, p, y += 15, 500, 11, 220, 10);
            AddWhiteTitleLeftPage(string.Format("{0}-{1}", pType.ToString(), pRef), p, y += 15, 500, 11, 220, 10);


            //if (pType == DocumentType.LM || pType == DocumentType.RM)
            //{
            //    string[] rowContents = { string.Format("Le {0}", DateTime.Now.ToShortDateString()) //Date de maj ou Date de création
            //                            , string.Format("{0}-{1}", pType.ToString(), pRef) 
            //                            , name
            //                           };
            //    LM_AddTableTitle(p, rowContents, 90, y += 50);
            //}
            //else
            //{
            //    string[] rowContents = { string.Format("Le {0}", DateTime.Now.ToShortDateString()) //Date de maj ou Date de création
            //                             , string.Format("{0}-{1}", pType.ToString(), pRef) 
            //                           };
            //    LM_AddTableTitle(p, rowContents, 90, y += 50);
            //}

            //if (pType == DocumentType.LM || pType == DocumentType.RM)
            //{
            //    AddRecueil_Notes_Rectangle(y += 120, 105, 375, 30);
            //    AddReceuil_DetailText_Justify_Calibri_Label(name, y + 5, 300, 20, 120);
            //}

            return doc.Draw();
        }