예제 #1
0
        public static PdfDocument GeneratePdfForms(PdfDocument pdfDocument, IEnumerable <Applicant> applicants)
        {
            foreach (Applicant applicant in applicants)
            {
                ApplyForm singleApplyForm = new ApplyForm(applicant);

                var sap = new PdfDocument(new PdfReader(singleApplyForm.GetPage()));
                sap.CopyPagesTo(1, sap.GetNumberOfPages(), pdfDocument);
            }

            return(pdfDocument);
        }
예제 #2
0
        static void GenerateForm()
        {
GetCsv:
            Console.Write("CSV File: ");
            string applicantCsv = Console.ReadLine();

            if (string.IsNullOrEmpty(applicantCsv) || !File.Exists(applicantCsv))
            {
                goto GetCsv;
            }

            List <Applicant> applicants;

            using (var reader = new StreamReader(new FileStream(applicantCsv, FileMode.Open), Encoding.GetEncoding("GB2312")))
                using (var csv = new CsvReader(reader))
                {
                    applicants = csv.GetRecords <Applicant>().ToList();
                }

LoadTemplate:
            Console.Write("Template Form File[formtemplate.pdf]: ");
            string formTemplate = Console.ReadLine();

            if (string.IsNullOrEmpty(formTemplate))
            {
                formTemplate = "formtemplate.pdf";
            }
            if (!File.Exists(formTemplate))
            {
                goto LoadTemplate;
            }
            ApplyForm.TemplatePdf = formTemplate;

LoadFormConfig:
            Console.Write("Form Config File[formsettings.json]: ");
            string formSettings = Console.ReadLine();

            if (string.IsNullOrEmpty(formSettings))
            {
                formSettings = "formsettings.json";
            }
            if (!File.Exists(formSettings))
            {
                goto LoadFormConfig;
            }

            string       settingJson = File.ReadAllText(formSettings);
            FormSettings fs          = JsonConvert.DeserializeObject <FormSettings>(settingJson);

            ApplyForm.FormSettings = fs;

SavingPath:
            Console.Write("PDF Saving Path: ");
            string savingPath = Console.ReadLine();

            if (string.IsNullOrEmpty(savingPath))
            {
                goto SavingPath;
            }

            ApplyForm.GeneratePdfForms(savingPath, applicants);
        }