Example #1
0
        /// <summary>
        /// 利用itext7生成文字签名
        /// </summary>
        public void ConvertPdf1()
        {
            string sourcePath = $"C:\\test\\source.pdf";
            string targetPath = $"C:\\test\\target.pdf";
            string fontPath   = $"C:\\Windows\\Fonts\\simkai.ttf";

            string signPath1 = @"C:\Users\Administrator\Desktop\a.png";
            string signPath2 = @"C:\Users\Administrator\Desktop\b.png";
            string signPath3 = @"C:\Users\Administrator\Desktop\c.png";
            string signPath4 = @"C:\Users\Administrator\Desktop\d.png";


            //输入PDF
            using (iText.Kernel.Pdf.PdfReader reader = new iText.Kernel.Pdf.PdfReader(sourcePath))
            {
                //输出PDF
                using (iText.Kernel.Pdf.PdfWriter writer = new iText.Kernel.Pdf.PdfWriter(targetPath))
                {
                    //获取PDF对象
                    using (iText.Kernel.Pdf.PdfDocument pdfDocument = new iText.Kernel.Pdf.PdfDocument(reader, writer))
                    {
                        //获取Document对象
                        using (iText.Layout.Document document = new iText.Layout.Document(pdfDocument))
                        {
                            //从物理文件加载图片
                            iText.Layout.Element.Image image1 = new iText.Layout.Element.Image(iText.IO.Image.ImageDataFactory.Create(signPath1));
                            iText.Layout.Element.Image image2 = new iText.Layout.Element.Image(iText.IO.Image.ImageDataFactory.Create(signPath2));
                            iText.Layout.Element.Image image3 = new iText.Layout.Element.Image(iText.IO.Image.ImageDataFactory.Create(signPath3));
                            iText.Layout.Element.Image image4 = new iText.Layout.Element.Image(iText.IO.Image.ImageDataFactory.Create(signPath4));

                            //将图片绘制到PDF的绝对坐标上,同时缩放图片
                            //坐标与绘制文字的坐标几乎一致,稍微向左,向上一些
                            //缩放的宽度与后面的宽度一致,示例中是200
                            //缩放的高度计算两个签名之间的高度差,例如93-73=20
                            //注意示例采用的签名图片的尺寸是:400px * 150px,应当采取和它差不多的尺寸效果最佳
                            document.Add(image1.ScaleToFit(200, 20).SetFixedPosition(1, 3089, 93, 200));
                            document.Add(image2.ScaleToFit(200, 20).SetFixedPosition(1, 3089, 73, 200));
                            document.Add(image3.ScaleToFit(200, 20).SetFixedPosition(1, 3089, 53, 200));
                            document.Add(image4.ScaleToFit(200, 20).SetFixedPosition(1, 3089, 33, 200));

                            //加载字体
                            iText.Kernel.Font.PdfFont font = iText.Kernel.Font.PdfFontFactory.CreateFont(fontPath, iText.IO.Font.PdfEncodings.IDENTITY_H, true);

                            //添加文本
                            document.Add(new iText.Layout.Element.Paragraph("签名1").SetFont(font).SetFontSize(12).SetFixedPosition(1, 3090, 90, 200));
                            document.Add(new iText.Layout.Element.Paragraph("签名2").SetFont(font).SetFontSize(12).SetFixedPosition(1, 3090, 70, 200));
                            document.Add(new iText.Layout.Element.Paragraph("签名3").SetFont(font).SetFontSize(12).SetFixedPosition(1, 3090, 50, 200));
                            document.Add(new iText.Layout.Element.Paragraph("签名4").SetFont(font).SetFontSize(12).SetFixedPosition(1, 3090, 30, 200));
                        }
                    }
                }
            }
        }
Example #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            SaveFileDialog savefile = new SaveFileDialog();

            savefile.FileName = "bitacora_" + DateTime.Now.ToString("dd - MM - yyyy") + ".pdf";
            savefile.Filter   = "PDF files (*.pdf)|*.pdf";

            if (savefile.ShowDialog() == DialogResult.OK)
            {
                PdfWriter   writer   = new PdfWriter(savefile.FileName);
                PdfDocument pdf      = new PdfDocument(writer);
                Document    document = new Document(pdf, PageSize.LETTER);
                document.SetMargins(60, 20, 55, 20);


                iText.Kernel.Font.PdfFont fontCol  = iText.Kernel.Font.PdfFontFactory.CreateFont(iText.IO.Font.Constants.StandardFonts.HELVETICA_BOLD);
                iText.Kernel.Font.PdfFont fontText = iText.Kernel.Font.PdfFontFactory.CreateFont(iText.IO.Font.Constants.StandardFonts.HELVETICA);

                string[] columns = { i18n().GetString("log.list.user"), i18n().GetString("log.list.level"), i18n().GetString("log.list.functionality"), i18n().GetString("log.list.desc"), i18n().GetString("log.list.date") };

                float[] sizes = { 20, 20, 20, 20, 20 };
                Table   table = new Table(UnitValue.CreatePercentArray(sizes));
                table.SetWidth(UnitValue.CreatePercentValue(100));

                foreach (string col in columns)
                {
                    table.AddHeaderCell(new Cell().Add(new Paragraph(col)));
                }

                List <Bitacora> list = service.buscar(Bitacora.builder()
                                                      .Criticidad(this.comboBox1.SelectedItem != null ? this.comboBox1.SelectedItem.ToString() : null)
                                                      .Usuario((Usuario)this.userCombo.SelectedItem)
                                                      .Desde(this.dateTimePicker1.Value)
                                                      .Hasta(this.dateTimePicker2.Value).build());
                foreach (Bitacora b in list)
                {
                    table.AddCell(new Cell().Add(new Paragraph(b.Usuario.Username).SetFont(fontText)));
                    table.AddCell(new Cell().Add(new Paragraph(b.Criticidad).SetFont(fontText)));
                    table.AddCell(new Cell().Add(new Paragraph(b.Funcionalidad).SetFont(fontText)));
                    table.AddCell(new Cell().Add(new Paragraph(b.Descripcion).SetFont(fontText)));
                    table.AddCell(new Cell().Add(new Paragraph(b.Fecha.ToString("dd-MM-yyyy HH:mm:ss")).SetFont(fontText)));
                }
                document.Add(table);
                document.Close();

                showInfo(i18n().GetString("exportado"));
            }
        }
Example #3
0
        private void button3_Click(object sender, EventArgs e)
        {
            SaveFileDialog savefile = new SaveFileDialog();

            savefile.FileName = "reporteRentabilidad_" + DateTime.Now.ToString("dd - MM - yyyy") + ".pdf";
            savefile.Filter   = "PDF files (*.pdf)|*.pdf";

            if (savefile.ShowDialog() == DialogResult.OK)
            {
                PdfWriter   writer   = new PdfWriter(savefile.FileName);
                PdfDocument pdf      = new PdfDocument(writer);
                Document    document = new Document(pdf, PageSize.LETTER);
                document.SetMargins(60, 20, 55, 20);


                iText.Kernel.Font.PdfFont fontCol  = iText.Kernel.Font.PdfFontFactory.CreateFont(iText.IO.Font.Constants.StandardFonts.HELVETICA_BOLD);
                iText.Kernel.Font.PdfFont fontText = iText.Kernel.Font.PdfFontFactory.CreateFont(iText.IO.Font.Constants.StandardFonts.HELVETICA);


                string[] columns = { i18n().GetString("report.list.project"), i18n().GetString("report.list.estimated.hs"), i18n().GetString("report.list.insumidas.hs")
                                     ,                                        i18n().GetString("report.list.desvio.hs"), i18n().GetString("report.list.desvio.dinero") };

                float[] sizes = { 20, 20, 20, 20, 20 };
                Table   table = new Table(UnitValue.CreatePercentArray(sizes));
                table.SetWidth(UnitValue.CreatePercentValue(100));

                foreach (string col in columns)
                {
                    table.AddHeaderCell(new Cell().Add(new Paragraph(col)));
                }

                List <BE.ProyectoReporte> list = proyectoService.generarReporte(this.desdeField.Value, this.hastaField.Value);
                foreach (BE.ProyectoReporte r in list)
                {
                    table.AddCell(new Cell().Add(new Paragraph(r.Nombre).SetFont(fontText)));
                    table.AddCell(new Cell().Add(new Paragraph(r.HorasEstimadas.ToString()).SetFont(fontText)));
                    table.AddCell(new Cell().Add(new Paragraph(r.HorasInsumidas.ToString()).SetFont(fontText)));
                    table.AddCell(new Cell().Add(new Paragraph(r.DesvioHoras.ToString()).SetFont(fontText)));
                    table.AddCell(new Cell().Add(new Paragraph(r.DesvioDinero.ToString()).SetFont(fontText)));
                }
                document.Add(table);
                document.Close();

                showInfo(i18n().GetString("exportado"));
            }
        }
Example #4
0
        public static PdfAcroForm AddAcroForm(Document doc)
        {
            iText.Kernel.Font.PdfFont regular = iText.Kernel.Font.PdfFontFactory.CreateFont(iText.IO.Font.FontConstants.TIMES_ROMAN);
            iText.Kernel.Font.PdfFont bold    = iText.Kernel.Font.PdfFontFactory.CreateFont(iText.IO.Font.FontConstants.TIMES_BOLD);
            Paragraph TimeSignature           = new Paragraph("report prodused: " + DateTime.Now.ToString()).SetTextAlignment(TextAlignment.LEFT).SetFontSize(10);

            iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance("logo.png");
            logo.ScaleToFit(300f, 250f);
            logo.SpacingBefore = 50f;
            logo.SpacingAfter  = 10f;
            logo.Alignment     = iTextSharp.text.Element.ALIGN_CENTER;

            Paragraph title = new Paragraph("TWM Airlines").SetTextAlignment(TextAlignment.CENTER).SetFontSize
                                  (16).SetFont(regular).SetBold().SetUnderline();

            doc.Add(title);

            Paragraph par;

            par = new Paragraph("THIS AGREEMENT").SetFontSize(12).SetBold();
            par.Add(" made effective as of:").SetFontSize(12).SetFont(regular);
            doc.Add(par);
            doc.Add(new Paragraph("PARTIES").SetFontSize(12)).SetFont(regular).SetBold();
            doc.Add(new Paragraph("1.                                                       hereinafter referred to as the 'Employer'").SetFontSize(12)).SetFont(regular);
            doc.Add(new Paragraph("2.                                                       hereinafter referred to as the 'Employee'").SetFontSize(12)).SetFont(regular);
            doc.Add(new Paragraph("TERMS OF EMPLOYMENT").SetFontSize(12)).SetFont(regular).SetBold();
            doc.Add(new Paragraph("The terms of employment are as follows:").SetFontSize(12)).SetFont(regular);
            doc.Add(new Paragraph("1. Remuneration:").SetFontSize(12)).SetFont(regular).SetBold();
            doc.Add(new Paragraph("Your base salary is $                    . Generally, your salary will be reviewed annually, but the Firm reserves the right to change your compensation from time to time on reasonable notice").SetFontSize(12)).SetFont(regular);
            doc.Add(new Paragraph("2. Work hours:").SetFontSize(12)).SetFont(regular).SetBold();
            doc.Add(new Paragraph("Employee will be required to work         hours per week. At times, the needs of the business may require that you work overtime.It is essential that you be available for overtime work.").SetFontSize(12)).SetFont(regular);
            doc.Add(new Paragraph("3. Job description:").SetFontSize(12)).SetFont(regular).SetBold();
            doc.Add(new Paragraph("The Employee's job will be as follows:").SetFontSize(12)).SetFont(regular);
            doc.Add(new Paragraph("").SetFontSize(12));
            doc.Add(new Paragraph("").SetFontSize(12));
            doc.Add(new Paragraph("4. Employee Benefits:").SetFontSize(12)).SetFont(regular).SetBold();
            doc.Add(new Paragraph("The Employee will be granted:").SetFontSize(12)).SetFont(regular);
            doc.Add(new Paragraph("").SetFontSize(12));
            doc.Add(new Paragraph("").SetFontSize(12));
            doc.Add(new Paragraph("5. Essential Requirements for the Role:").SetFontSize(12)).SetFont(regular).SetBold();
            doc.Add(new Paragraph("   (a) Employee must be fluent in:").SetFontSize(12)).SetFont(regular);
            doc.Add(new Paragraph("   (b) Employee must be skilled in:").SetFontSize(12)).SetFont(regular);
            doc.Add(new Paragraph("CONTRACT EFFECTIVE BETWEEN THE DATES:").SetFontSize(12)).SetFont(regular).SetBold();
            doc.Add(new Paragraph("Effective Starting:               ").SetFontSize(12)).SetFont(regular);
            doc.Add(new Paragraph("Date of Termination:               ").SetFontSize(12)).SetFont(regular);
            doc.Add(new Paragraph("SIGNATURES").SetFontSize(12)).SetFont(regular).SetBold();
            doc.Add(new Paragraph("SIGNED by the Employee:").SetFontSize(12)).SetFont(regular);
            doc.Add(new Paragraph("SIGNED BY THE EMPLOYER").SetFontSize(12)).SetFont(regular);
            //Add acroform
            PdfAcroForm form = PdfAcroForm.GetAcroForm(doc.GetPdfDocument(), true);
            //Create text field
            PdfTextFormField nameField = PdfTextFormField.CreateText(doc.GetPdfDocument(), new Rectangle(250, 755, 200,
                                                                                                         15), "date", "");

            form.AddField(nameField);
            nameField = PdfTextFormField.CreateText(doc.GetPdfDocument(), new Rectangle(55, 703, 150,
                                                                                        15), "employerName", "");
            form.AddField(nameField);
            nameField = PdfTextFormField.CreateText(doc.GetPdfDocument(), new Rectangle(55, 678, 150,
                                                                                        15), "employeeName", "");
            form.AddField(nameField);


            nameField = PdfTextFormField.CreateText(doc.GetPdfDocument(), new Rectangle(170, 201, 150,
                                                                                        15), "contractEnds", "");
            form.AddField(nameField);
            return(form);
        }