예제 #1
0
        public string CreatePDFFromDatabase(string hourlyApplicationID)
        {
            SqlDataReader dr = dataacess.GetPDF(hourlyApplicationID);

            if (dr.HasRows == false)
            {
                return("/EVerify/I9Template.pdf");
            }
            Page1 page1 = Page1FromDataReader(dr);


            string src  = HttpContext.Current.Server.MapPath("/EVerify/I9Template.PDF");
            string dest = HttpContext.Current.Server.MapPath("/EVerify/" + page1.LastName + ".pdf");

            string FormI9_PDF = "/EVerify/" + page1.LastName + ".pdf";

            PdfDocument pdf = new PdfDocument(new PdfReader(src), new PdfWriter(dest));

            PdfAcroForm form = PdfAcroForm.GetAcroForm(pdf, true);

            System.Collections.Generic.IDictionary <string, iText.Forms.Fields.PdfFormField> fields = form.GetFormFields();

            var font  = iText.Kernel.Font.PdfFontFactory.CreateFont(iText.IO.Font.FontConstants.HELVETICA);
            var font2 = iText.Kernel.Font.PdfFontFactory.CreateFont(iText.IO.Font.FontConstants.ZAPFDINGBATS);
            var font3 = iText.Kernel.Font.PdfFontFactory.CreateFont(iText.IO.Font.FontConstants.HELVETICA_BOLD);

            foreach (KeyValuePair <string, iText.Forms.Fields.PdfFormField> item in fields)
            {
                //if (item.Key == "State") item.Value.SetValue("GA");
                item.Value.SetFont(font3);
            }

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> Last = fields.First(k => k.Key == "LastName");

            Last.Value.SetValue(page1.LastName);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> First = fields.First(k => k.Key == "FirstName");

            First.Value.SetValue(page1.FirstName);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> Middle = fields.First(k => k.Key == "Middle");

            Middle.Value.SetValue(page1.Middle);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> OtherName = fields.First(k => k.Key == "OtherName");

            OtherName.Value.SetValue(page1.otherName);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> Address = fields.First(k => k.Key == "Address");

            Address.Value.SetValue(page1.Address);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> Apt = fields.First(k => k.Key == "Apt");

            Apt.Value.SetValue(page1.AptNum);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> City = fields.First(k => k.Key == "City");

            City.Value.SetValue(page1.City);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> State = fields.First(k => k.Key == "State");

            State.Value.SetValue(page1.State);

            if (page1.Zip > 0)
            {
                KeyValuePair <string, iText.Forms.Fields.PdfFormField> Zip = fields.First(k => k.Key == "ZIP");
                Zip.Value.SetValue(page1.Zip.ToString());
            }

            if (page1.Birth > 0)
            {
                KeyValuePair <string, iText.Forms.Fields.PdfFormField> Birth = fields.First(k => k.Key == "Birth");
                Birth.Value.SetValue(formatIntToDateString(page1.Birth));
            }
            KeyValuePair <string, iText.Forms.Fields.PdfFormField> SSN1 = fields.First(k => k.Key == "SSN1");

            SSN1.Value.SetValue(page1.SSN.ToString().Substring(0, 3));

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> SSN2 = fields.First(k => k.Key == "SSN2");

            SSN2.Value.SetValue(page1.SSN.ToString().Substring(3, 2));

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> SSN3 = fields.First(k => k.Key == "SSN3");

            SSN3.Value.SetValue(page1.SSN.ToString().Substring(5, 4));

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> Email = fields.First(k => k.Key == "Email");

            Email.Value.SetValue(page1.Email);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> Phone = fields.First(k => k.Key == "Phone");

            Phone.Value.SetValue(page1.Phone.ToString());

            if (page1.Citizenship == "4")
            {
                KeyValuePair <string, iText.Forms.Fields.PdfFormField> Citizen = fields.First(k => k.Key == "chkCitizen");
                //float foo = 18;
                Citizen.Value.SetValue("X");
                //Citizen.Value.SetValue("3", font2, 18) ;
            }
            else if (page1.Citizenship == "5")
            {
                KeyValuePair <string, iText.Forms.Fields.PdfFormField> NonCitizen = fields.First(k => k.Key == "chkNonCitizen");
                NonCitizen.Value.SetValue("X");
            }
            else if (page1.Citizenship == "6")
            {
                KeyValuePair <string, iText.Forms.Fields.PdfFormField> Perm = fields.First(k => k.Key == "chkPerm");
                Perm.Value.SetValue("X");
            }
            else if (page1.Citizenship == "7")
            {
                KeyValuePair <string, iText.Forms.Fields.PdfFormField> Alien = fields.First(k => k.Key == "chkAlien");
                Alien.Value.SetValue("X");
            }

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> AlienNum1 = fields.First(k => k.Key == "AlienNum1");

            AlienNum1.Value.SetValue(page1.AlienNum1);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> AuthorizationExpDate = fields.First(k => k.Key == "AuthorizationExpDate");

            AuthorizationExpDate.Value.SetValue(formatIntToDateString(page1.AuthorizationExpDate));

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> AlienNum2 = fields.First(k => k.Key == "AlienNum2");

            AlienNum2.Value.SetValue(page1.AlienNum2);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> I94Num = fields.First(k => k.Key == "I94Num");

            I94Num.Value.SetValue(page1.I94Num);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> ForeignPPNum = fields.First(k => k.Key == "ForeignPPNum");

            ForeignPPNum.Value.SetValue(page1.ForeignPPNum);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> ForeignPPCountry = fields.First(k => k.Key == "ForeignPPCountry");

            ForeignPPCountry.Value.SetValue(page1.ForeignPPCountry);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> Signature = fields.First(k => k.Key == "Signature");

            Signature.Value.SetValue(page1.Signature);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> SignatureDate = fields.First(k => k.Key == "SignatureDate");

            //SignatureDate.Value.SetValue(formatIntToDateString(page1.SignatureDate));
            SignatureDate.Value.SetValue(DateTime.Now.ToShortDateString());
            if (assistTemp == true)
            {
                KeyValuePair <string, iText.Forms.Fields.PdfFormField> chkAssistYes = fields.First(k => k.Key == "AssistYes");
                chkAssistYes.Value.SetValue("X");
            }

            else if (assistTemp == false)
            {
                KeyValuePair <string, iText.Forms.Fields.PdfFormField> chkAssistNo = fields.First(k => k.Key == "AssistNo");
                chkAssistNo.Value.SetValue("X");
            }

            if (page1.SignatureCertifyEmp == true)
            {
                KeyValuePair <string, iText.Forms.Fields.PdfFormField> chkSignatureEmployee = fields.First(k => k.Key == "chkSignatureEmployee");
                chkSignatureEmployee.Value.SetValue("X");
                //chkSignatureEmployee.Value.SetValue("3", font2, 18);
            }

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> SignaturePrep = fields.First(k => k.Key == "SignaturePrep");

            SignaturePrep.Value.SetValue(page1.SignaturePrep);

            if (page1.SignatureCertifyPrep == true)
            {
                KeyValuePair <string, iText.Forms.Fields.PdfFormField> chkSignaturePrep = fields.First(k => k.Key == "chkSignaturePrep");
                chkSignaturePrep.Value.SetValue("X");
                //chkSignatureEmployee.Value.SetValue("3", font2, 18);
            }

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> SignaturePrepDate = fields.First(k => k.Key == "SignaturePrepDate");

            SignaturePrepDate.Value.SetValue(formatIntToDateString(page1.SignaturePrepDate));

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> PrepLastName = fields.First(k => k.Key == "PrepLastName");

            PrepLastName.Value.SetValue(page1.PrepLastName ?? "");

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> PrepFirstName = fields.First(k => k.Key == "PrepFirstName");

            PrepFirstName.Value.SetValue(page1.PrepFirstName ?? "");

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> PrepAddress = fields.First(k => k.Key == "PrepAddress");

            PrepAddress.Value.SetValue(page1.PrepAddress);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> PrepCity = fields.First(k => k.Key == "PrepCity");

            PrepCity.Value.SetValue(page1.PrepCity);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> PrepState = fields.First(k => k.Key == "PrepState");

            PrepState.Value.SetValue(page1.PrepState);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> PrepZip = fields.First(k => k.Key == "PrepZip");

            PrepZip.Value.SetValue(page1.PrepZip.ToString());

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> Barcode = fields.First(k => k.Key == "Barcode");

            Barcode.Value.SetValue(page1.AppID);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> IPEmployee = fields.First(k => k.Key == "IPEmployee");

            IPEmployee.Value.SetValue("1) " + page1.SignatureCertifyEmpIP);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> IPEmployer = fields.First(k => k.Key == "IPEmployer");

            IPEmployer.Value.SetValue("2) " + page1.CertifyCertifySignatureIP);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> LastName2 = fields.First(k => k.Key == "LastName2");

            LastName2.Value.SetValue(page1.LastName);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> FirstName2 = fields.First(k => k.Key == "FirstName2");

            FirstName2.Value.SetValue(page1.FirstName);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> Middle2 = fields.First(k => k.Key == "Middle2");

            Middle2.Value.SetValue(page1.Middle);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> Citizenship2 = fields.First(k => k.Key == "Citizenship2");

            if (page1.Citizenship == "4")
            {
                Citizenship2.Value.SetValue("Citizen");
            }
            else if (page1.Citizenship == "5")
            {
                Citizenship2.Value.SetValue("Non-citizen national");
            }
            else if (page1.Citizenship == "6")
            {
                Citizenship2.Value.SetValue("Permanent Resident");
            }
            else if (page1.Citizenship == "7")
            {
                Citizenship2.Value.SetValue("Authorized Alien");
            }

            //string tempDocTitle = "";
            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocA1Title = fields.First(k => k.Key == "DocA1Title");
            //if (page1.DocA1Title == "11") tempDocTitle = "Arrival / Departure Record(Form I - 94)";
            //else if (page1.DocA1Title == "13") tempDocTitle = "Permanent Resident Card or Alien Registration Receipt";
            //else if (page1.DocA1Title == "17") tempDocTitle = "Employment Authorization Document";
            //else if (page1.DocA1Title == "24") tempDocTitle = "Foreign Passport with I - 94";
            //else if (page1.DocA1Title == "25") tempDocTitle = "Foreign Passport with I - 551";
            //else if (page1.DocA1Title == "29") tempDocTitle = "U.S.Passport or Passport Card";
            //DocA1Title.Value.SetValue(tempDocTitle);

            //tempDocTitle = "";
            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocA2Title = fields.First(k => k.Key == "DocA2Title");
            //if (page1.DocA2Title == "11") tempDocTitle = "Arrival / Departure Record(Form I - 94)";
            //else if (page1.DocA2Title == "13") tempDocTitle = "Permanent Resident Card or Alien Registration Receipt";
            //else if (page1.DocA2Title == "17") tempDocTitle = "Employment Authorization Document";
            //else if (page1.DocA2Title == "24") tempDocTitle = "Foreign Passport with I - 94";
            //else if (page1.DocA2Title == "25") tempDocTitle = "Foreign Passport with I - 551";
            //else if (page1.DocA2Title == "29") tempDocTitle = "U.S.Passport or Passport Card";
            //DocA2Title.Value.SetValue(tempDocTitle);

            //tempDocTitle = "";
            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocA3Title = fields.First(k => k.Key == "DocA3Title");
            //if (page1.DocA3Title == "11") tempDocTitle = "Arrival / Departure Record(Form I - 94)";
            //else if (page1.DocA3Title == "13") tempDocTitle = "Permanent Resident Card or Alien Registration Receipt";
            //else if (page1.DocA3Title == "17") tempDocTitle = "Employment Authorization Document";
            //else if (page1.DocA3Title == "24") tempDocTitle = "Foreign Passport with I - 94";
            //else if (page1.DocA3Title == "25") tempDocTitle = "Foreign Passport with I - 551";
            //else if (page1.DocA3Title == "29") tempDocTitle = "U.S.Passport or Passport Card";
            //DocA3Title.Value.SetValue(tempDocTitle);

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocA1Issuer= fields.First(k => k.Key == "DocA1Issuer");
            //DocA1Issuer.Value.SetValue(page1.DocA1Issuer);
            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocA2Issuer = fields.First(k => k.Key == "DocA2Issuer");
            //DocA2Issuer.Value.SetValue(page1.DocA2Issuer);
            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocA3Issuer = fields.First(k => k.Key == "DocA3Issuer");
            //DocA3Issuer.Value.SetValue(page1.DocA3Issuer);

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocA1Num = fields.First(k => k.Key == "DocA1Num");
            //DocA1Num.Value.SetValue(page1.DocA1Num);
            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocA2Num = fields.First(k => k.Key == "DocA2Num");
            //DocA2Num.Value.SetValue(page1.DocA2Num);
            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocA3Num = fields.First(k => k.Key == "DocA3Num");
            //DocA3Num.Value.SetValue(page1.DocA3Num);

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocA1Date = fields.First(k => k.Key == "DocA1Date");
            //DocA1Date.Value.SetValue(formatIntToDateString(page1.DocA1Date));
            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocA2Date = fields.First(k => k.Key == "DocA2Date");
            //DocA2Date.Value.SetValue(formatIntToDateString(page1.DocA2Date));
            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocA3Date = fields.First(k => k.Key == "DocA3Date");
            //DocA3Date.Value.SetValue(formatIntToDateString(page1.DocA3Date));

            //tempDocTitle = "";
            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocBTitle = fields.First(k => k.Key == "DocBTitle");
            //if (page1.DocBTitle == "1") tempDocTitle = "Driver's license";
            //else if (page1.DocBTitle == "2") tempDocTitle = "ID Card";
            //else if (page1.DocBTitle == "3") tempDocTitle = "School ID card";
            //else if (page1.DocBTitle == "4") tempDocTitle = "Voter registration card";
            //else if (page1.DocBTitle == "5") tempDocTitle = "U.S. military card";
            //else if (page1.DocBTitle == "6") tempDocTitle = "Military dependent's ID card";
            //else if (page1.DocBTitle == "7") tempDocTitle = "U.S. Coast Guard Merchant Mariner Card";
            //else if (page1.DocBTitle == "8") tempDocTitle = "Native American tribal document";
            //else if (page1.DocBTitle == "9") tempDocTitle = "Canadian Driver's license";
            //else if (page1.DocBTitle == "10") tempDocTitle = "School record or report card";
            //else if (page1.DocBTitle == "11") tempDocTitle = "Doctor or hospital record";
            //else if (page1.DocBTitle == "12") tempDocTitle = "Day-care or nursery school record";
            //DocBTitle.Value.SetValue(tempDocTitle);

            //tempDocTitle = "";
            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocCTitle = fields.First(k => k.Key == "DocCTitle");
            //if (page1.DocCTitle == "13") tempDocTitle = "Social Security Card";
            //else if (page1.DocCTitle == "14") tempDocTitle = "Certification of Birth Abroad (Form FS-545)";
            //else if (page1.DocCTitle == "15") tempDocTitle = "Certification of Report of Birth (Form DS-1350)";
            //else if (page1.DocCTitle == "16") tempDocTitle = "U.S. birth certificate (original or certified copy)";
            //else if (page1.DocCTitle == "17") tempDocTitle = "Native American tribal document";
            //else if (page1.DocCTitle == "18") tempDocTitle = "U.S. Citizen ID Card (Form I-197)";
            //else if (page1.DocCTitle == "19") tempDocTitle = "ID Card for Use of Resident Citizen in the United States (Form I-179)";
            //else if (page1.DocCTitle == "20") tempDocTitle = "Employment authorization document issued by the U.S. Department of Homeland Security";
            //DocCTitle.Value.SetValue(tempDocTitle);

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocBIssuer = fields.First(k => k.Key == "DocBIssuer");
            //DocBIssuer.Value.SetValue(page1.DocBIssuer);
            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocCIssuer = fields.First(k => k.Key == "DocCIssuer");
            //DocCIssuer.Value.SetValue(page1.DocCIssuer);

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocBNum = fields.First(k => k.Key == "DocBNum");
            //DocBNum.Value.SetValue(page1.DocBNum);
            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocCNum = fields.First(k => k.Key == "DocCNum");
            //DocCNum.Value.SetValue(page1.DocCNum);

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocBDate = fields.First(k => k.Key == "DocBDate");
            //DocBDate.Value.SetValue(formatIntToDateString(page1.DocBDate));
            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocCDate = fields.First(k => k.Key == "DocCDate");
            //DocCDate.Value.SetValue(formatIntToDateString(page1.DocCDate));

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> DocsAdditional = fields.First(k => k.Key == "DocsAdditional");
            //DocsAdditional.Value.SetValue(page1.DocsAdditional);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> FirstWorkDate = fields.First(k => k.Key == "FirstWorkDate");

            FirstWorkDate.Value.SetValue(formatIntToDateString(page1.FirstWorkDate));

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> CertifySignature = fields.First(k => k.Key == "CertifySignature");
            //CertifySignature.Value.SetValue(page1.CertifySignature);

            //if (page1.CertifyCertifySignature == true)
            //{
            //    KeyValuePair<string, iText.Forms.Fields.PdfFormField> chkCertifySignature = fields.First(k => k.Key == "chkCertifySignature");
            //    chkCertifySignature.Value.SetValue("X");
            //    //chkSignatureEmployee.Value.SetValue("3", font2, 18);
            //}

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> CertifyDate = fields.First(k => k.Key == "CertifyDate");
            //CertifyDate.Value.SetValue(formatIntToDateString(page1.CertifyDate));

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> CertifyTitle = fields.First(k => k.Key == "CertifyTitle");
            //CertifyTitle.Value.SetValue(page1.CertifyTitle);

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> CertifyLastName = fields.First(k => k.Key == "CertifyLastName");
            //CertifyLastName.Value.SetValue(page1.CertifyLastName);

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> CertifyFirstName = fields.First(k => k.Key == "CertifyFirstName");
            //CertifyFirstName.Value.SetValue(page1.CertifyFirstName);

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> CertifyCompany = fields.First(k => k.Key == "CertifyCompany");
            //CertifyCompany.Value.SetValue(page1.CertifyCompany);

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> CertifyAddress = fields.First(k => k.Key == "CertifyAddress");
            //CertifyAddress.Value.SetValue(page1.CertifyAddress);

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> CertifyCity = fields.First(k => k.Key == "CertifyCity");
            //CertifyCity.Value.SetValue(page1.CertifyCity);

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> CertifyState = fields.First(k => k.Key == "CertifyState");
            //CertifyState.Value.SetValue(page1.CertifyState);

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> CertifyZip = fields.First(k => k.Key == "CertifyZip");
            //CertifyZip.Value.SetValue(page1.CertifyZip.ToString());

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> ReverifyLastName = fields.First(k => k.Key == "ReverifyLastName");
            //ReverifyLastName.Value.SetValue(page1.ReverifyLastName);

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> ReverifyFirstName = fields.First(k => k.Key == "ReverifyFirstName");
            //ReverifyFirstName.Value.SetValue(page1.ReverifyFirstName);

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> ReverifyMiddle = fields.First(k => k.Key == "ReverifyMiddle");
            //ReverifyMiddle.Value.SetValue(page1.ReverifyMiddle);

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> ReverifyRehireDate = fields.First(k => k.Key == "ReverifyRehireDate");
            //ReverifyRehireDate.Value.SetValue(formatIntToDateString(page1.ReverifyRehireDate));

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> ReverifyDocTitle = fields.First(k => k.Key == "ReverifyDocTitle");
            //ReverifyDocTitle.Value.SetValue(page1.ReverifyDocTitle);

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> ReverifyDocNum = fields.First(k => k.Key == "ReverifyDocNum");
            //ReverifyDocNum.Value.SetValue(page1.ReverifyDocNum);

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> ReverifyDocDate = fields.First(k => k.Key == "ReverifyDocDate");
            //ReverifyDocDate.Value.SetValue(formatIntToDateString(page1.ReverifyDocDate));

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> ReverifySignature = fields.First(k => k.Key == "ReverifySignature");
            //ReverifySignature.Value.SetValue(page1.ReverifySignature);

            //if (page1.ReverifySignatureCertify == true)
            //{
            //    KeyValuePair<string, iText.Forms.Fields.PdfFormField> chkReverifySignature = fields.First(k => k.Key == "chkReverifySignature");
            //    chkReverifySignature.Value.SetValue("X");
            //    //chkSignatureEmployee.Value.SetValue("3", font2, 18);
            //}
            ////chkReverifySignature
            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> ReverifyDate = fields.First(k => k.Key == "ReverifyDate");
            //ReverifyDate.Value.SetValue(formatIntToDateString(page1.ReverifyDate));

            //KeyValuePair<string, iText.Forms.Fields.PdfFormField> ReverifyName = fields.First(k => k.Key == "ReverifyName");
            //ReverifyName.Value.SetValue(page1.ReverifyName);

            form.FlattenFields();

            pdf.Close();

            return("/EVerify/" + page1.LastName + ".pdf");
        }
예제 #2
0
파일: i92.aspx.cs 프로젝트: rlandow/EVerify
        public void CreatePDF()
        {
            string src  = HttpContext.Current.Server.MapPath("/Forms/I9Template.PDF");
            string dest = HttpContext.Current.Server.MapPath("/Forms/" + txtLastName.Text + ".pdf");

            PdfDocument pdf = new PdfDocument(new PdfReader(src), new PdfWriter(dest));

            PdfAcroForm form = PdfAcroForm.GetAcroForm(pdf, true);

            System.Collections.Generic.IDictionary <string, iText.Forms.Fields.PdfFormField> fields = form.GetFormFields();

            var font = iText.Kernel.Font.PdfFontFactory.CreateFont(iText.IO.Font.FontConstants.HELVETICA);

            foreach (KeyValuePair <string, iText.Forms.Fields.PdfFormField> item in fields)
            {
                //if (item.Key == "State") item.Value.SetValue("GA");
                item.Value.SetFont(font);
            }

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> Last = fields.First(k => k.Key == "LastName");

            Last.Value.SetValue(txtLastName.Text);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> First = fields.First(k => k.Key == "FirstName");

            First.Value.SetValue(txtFirstName.Text);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> Middle = fields.First(k => k.Key == "Middle");

            Middle.Value.SetValue(txtMiddle.Text);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> OtherName = fields.First(k => k.Key == "OtherName");

            OtherName.Value.SetValue(txtOtherName.Text);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> Address = fields.First(k => k.Key == "Address");

            Address.Value.SetValue(txtAddress.Text);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> Apt = fields.First(k => k.Key == "Apt");

            Apt.Value.SetValue(txtAptNum.Text);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> City = fields.First(k => k.Key == "City");

            City.Value.SetValue(txtCity.Text);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> State = fields.First(k => k.Key == "State");

            State.Value.SetValue(txtState.Text);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> Zip = fields.First(k => k.Key == "ZIP");

            Zip.Value.SetValue(txtZip.Text);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> Birth = fields.First(k => k.Key == "Birth");

            Birth.Value.SetValue(txtBirth.Text);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> SSN1 = fields.First(k => k.Key == "SSN1");

            SSN1.Value.SetValue(txtSSN1.Text);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> SSN2 = fields.First(k => k.Key == "SSN2");

            SSN2.Value.SetValue(txtSSN2.Text);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> SSN3 = fields.First(k => k.Key == "SSN3");

            SSN3.Value.SetValue(txtSSN3.Text);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> Email = fields.First(k => k.Key == "Email");

            Email.Value.SetValue(txtEmail.Text);

            KeyValuePair <string, iText.Forms.Fields.PdfFormField> Phone = fields.First(k => k.Key == "Phone");

            Phone.Value.SetValue(txtPhone.Text);

            pdf.Close();



            //BaseFont font = BaseFont.CreateFont(BaseFont.HELVETICA, "Cp1252", true);
            //
            //
            //string src = HttpContext.Current.Server.MapPath("/Forms/i9newpaper.PDF");
            //
            //string destFile = HttpContext.Current.Server.MapPath("/Forms/") + txtLastName.Text + ".pdf";
            //
            //PdfReader reader = new PdfReader(src);
            //PdfStamper stamper = new PdfStamper(reader, new FileStream(destFile, FileMode.Create));
            //System.Text.Encoding encoding = System.Text.Encoding.UTF8;
            //
            //byte[] password = encoding.GetBytes("secret");
            //
            //stamper.SetEncryption(password, null, PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128 | PdfWriter.DO_NOT_ENCRYPT_METADATA);
            //
            //AcroFields pdfFormFields = stamper.AcroFields;
            //
            //foreach (string key in reader.AcroFields.Fields.Keys)
            //{
            //    string foo = key;
            //    pdfFormFields.SetFieldProperty(foo, "textfont", font, null);
            //    pdfFormFields.SetFieldProperty(foo, "textsize", 11f, null);
            //}
            //
            //pdfFormFields.SetField("LastName", page1.LastName);
            //pdfFormFields.SetField("FirstName", page1.FirstName);
            //pdfFormFields.SetField("Middle", page1.Middle);
            //pdfFormFields.SetField("Address", page1.Address);
            //pdfFormFields.SetField("City", page1.City);
            //pdfFormFields.SetField("State", page1.State);
            //pdfFormFields.SetField("Zip Code", page1.Zip.ToString());
            //pdfFormFields.SetField("SSN1", Convert.ToString(txtSSN1.Text));
            //pdfFormFields.SetField("SSN2", Convert.ToString(txtSSN2.Text));
            //pdfFormFields.SetField("SSN3", Convert.ToString(txtSSN3.Text));
            //pdfFormFields.SetField("Email", page1.Email);
            //pdfFormFields.SetField("Phone", page1.Phone.ToString());
            //
            //
            //stamper.FormFlattening = false;
            //
            //stamper.Close();

            return;
        }