private void ImagemRodape(PdfWriter writer, int numberPage) { BaseFont f_tr = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); PdfContentByte canvas = writer.DirectContent; //Classe do ItextSharp para instânciar uma imagem Image image1 = Image.GetInstance("..\\..\\Imagens\\imagem1.png"); image1.SetAbsolutePosition(40, 1); //Horizontal, vertical image1.ScaleAbsoluteHeight(60); image1.ScaleAbsoluteWidth(60); canvas.AddImage(image1); //Linha canvas.MoveTo(40, 60); canvas.LineTo(575, 60); canvas.SetLineWidth(2); canvas.Stroke(); //Rodapé PdfTemplate tmpFooter = canvas.CreateTemplate(540, 70); canvas.AddTemplate(tmpFooter, 50, 1); tmpFooter.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_BOLD, BaseFont.CP1252, false), 5); tmpFooter.BeginText(); tmpFooter.SetFontAndSize(f_tr, 8); tmpFooter.ShowTextAligned(1, "TextoTextoTextoTextoTextoTextoTextoTexto", 240, 30, 0); tmpFooter.ShowTextAligned(2, string.Format("Página {0}", numberPage), 520, 10, 0); tmpFooter.EndText(); }
//footer private PdfTemplate PdfFooter(PdfContentByte cb, int num1) { // kreiranje template PdfTemplate tmpFooter = cb.CreateTemplate(580, 70); // doljnji lijevi čošak stranice tmpFooter.MoveTo(1, 1); // dodavanje footera tmpFooter.Stroke(); // upisivanje u footer tmpFooter.BeginText(); // postavljanje formatea i veličine tmpFooter.SetFontAndSize(f_cb, 8); // Info tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Dobavljac", 0, 53, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Adresa", 0, 45, 0); tmpFooter.SetFontAndSize(f_cn, 8); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, crud.GetTrgovina[0], 50, 53, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, crud.GetUlicaTrg[0] + ", " + crud.GetMjesto[0], 50, 45, 0); //naslovi tmpFooter.SetFontAndSize(f_cb, 8); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Tel/Mob", 215, 53, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Mail", 400, 53, 0); // info tmpFooter.SetFontAndSize(f_cn, 8); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, crud.GetMob[0], 265, 53, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, crud.GetEmail[0], 450, 53, 0); // kraj tmpFooter.EndText(); // dodavanje linije iznad samog footera cb.SetLineWidth(0f); cb.MoveTo(30, 65); cb.LineTo(570, 65); cb.Stroke(); return(tmpFooter); }
public PdfTemplate AddPageFooter(int PageNumber) { PdfTemplate footerTemplate = cb.CreateTemplate(500, 55); footerTemplate.BeginText(); BaseFont bf2 = BaseFont.CreateFont(BaseFont.TIMES_ITALIC, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); footerTemplate.SetFontAndSize(bf2, 11); footerTemplate.SetColorStroke(BaseColor.DARK_GRAY); footerTemplate.SetColorFill(BaseColor.GRAY); int al = -200; footerTemplate.SetLineWidth(3); footerTemplate.LineTo(500, footerTemplate.YTLM); string texttoadd = "Page: " + PageNumber.ToString(); float widthoftext = 500.0f - bf2.GetWidthPoint(texttoadd, 11); footerTemplate.ShowTextAligned(al, texttoadd, widthoftext, 30, 0); footerTemplate.EndText(); return(footerTemplate); }
public PdfTemplate AddAddressFooter() { PdfTemplate footerTemplate = cb.CreateTemplate(500, (FooterLines.Count * 45 + 10)); footerTemplate.BeginText(); BaseFont bf2 = BaseFont.CreateFont(BaseFont.TIMES_ITALIC, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); footerTemplate.SetFontAndSize(bf2, 11); footerTemplate.SetColorStroke(BaseColor.DARK_GRAY); footerTemplate.SetColorFill(BaseColor.GRAY); int al = -200; int p = 0; // current line int v; // vertical positioning foreach (string FooterLine in FooterLines) { v = 45 - (15 * p); float widthoftext = 500.0f - bf2.GetWidthPoint(FooterLine, 11); footerTemplate.ShowTextAligned(al, FooterLine, widthoftext, v, 0); p++; } footerTemplate.EndText(); return(footerTemplate); }
public static void SignHashed(MemoryStream Source, string Target, SysX509.X509Certificate2 Certificate, string Reason, string Location, bool AddVisibleSign, Image img, int nroHojaFirma, string path, float h, string att_1, string att_2, string att_3, string url_terminos) { try { X509CertificateParser objCP = new X509CertificateParser(); X509Certificate[] objChain = new X509Certificate[] { objCP.ReadCertificate(Certificate.RawData) }; IExternalSignature externalSignature = new X509Certificate2Signature(Certificate, "SHA-1"); PdfReader objReader = new PdfReader(Source); //string[] msg = Certificate.SubjectName.Name.Split(','); //Document document = new Document(PageSize.A4, 50, 50, 150, 100); //PdfWriter pdfwritter = PdfWriter.GetInstance(document, new FileStream("C:\\Users\\Public\\terminos_condiciones.pdf", FileMode.OpenOrCreate)); using (PdfReader readerTerm = new PdfReader(url_terminos)) using (MemoryStream workStream = new MemoryStream()) { PdfStamper objStamper = PdfStamper.CreateSignature(objReader, new FileStream(Target, FileMode.OpenOrCreate, FileAccess.Write), '\0'); int nroPages = objReader.NumberOfPages + 1; Rectangle rectangle = readerTerm.GetPageSize(1); objStamper.InsertPage(nroPages, rectangle); PdfImportedPage bg = objStamper.GetImportedPage(readerTerm, 1); objStamper.GetUnderContent(nroPages).AddTemplate(bg, 0, 0); PdfSignatureAppearance objSA = objStamper.SignatureAppearance; img.ScaleAbsolute(120f, 60f); img.SetAbsolutePosition(0, 28); BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false); BaseFont bfBold = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, false); if (true) { objSA.SetVisibleSignature(new Rectangle(50, h - 120, 200, h), nroHojaFirma, "Firma Digital emitida por el sistema BV Digital"); } PdfTemplate n2Layer = objSA.GetLayer(2); n2Layer.BeginText(); n2Layer.SetFontAndSize(bfBold, 7); n2Layer.ShowTextAligned(Element.ALIGN_LEFT, "Inspectorate Services Perú S.A.C", 0, 100, 0); n2Layer.ShowTextAligned(Element.ALIGN_LEFT, "A Bureau Veritas Group Company", 0, 90, 0); n2Layer.EndText(); n2Layer.AddImage(img); n2Layer.BeginText(); n2Layer.SetFontAndSize(bf, 7); n2Layer.ShowTextAligned(Element.ALIGN_LEFT, "Firmado Digitalmente por", 0, 40, 0); //string user = msg[2].Substring(msg[2].IndexOf('=') + 1); //user += " " + msg[3].Substring(msg[3].IndexOf('=') + 1); n2Layer.ShowTextAligned(Element.ALIGN_LEFT, att_3, 0, 30, 0); n2Layer.ShowTextAligned(Element.ALIGN_LEFT, "Fecha: " + objSA.SignDate.ToString(), 0, 20, 0); n2Layer.ShowTextAligned(Element.ALIGN_LEFT, att_1, 0, 10, 0); n2Layer.ShowTextAligned(Element.ALIGN_LEFT, att_2, 0, 0, 0); n2Layer.EndText(); objSA.SignatureRenderingMode = PdfSignatureAppearance.RenderingMode.GRAPHIC_AND_DESCRIPTION; MakeSignature.SignDetached(objSA, externalSignature, objChain, null, null, null, 0, CryptoStandard.CMS); objStamper.SetFullCompression(); } } catch (Exception e) { Utility.log_err.save(null, e); } }
private PdfTemplate PdfFooter(PdfContentByte cb, DataRow drFoot) { // Create the template and assign height PdfTemplate tmpFooter = cb.CreateTemplate(580, 70); // Move to the bottom left corner of the template tmpFooter.MoveTo(1, 1); // Place the footer content tmpFooter.Stroke(); // Begin writing the footer tmpFooter.BeginText(); // Set the font and size tmpFooter.SetFontAndSize(f_cn, 8); // Write out details from the payee table tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, drFoot["supplier"].ToString(), 0, 53, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, drFoot["address1"].ToString(), 0, 45, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, drFoot["address2"].ToString(), 0, 37, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, drFoot["address3"].ToString(), 0, 29, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, drFoot["zip"].ToString() + " " + drFoot["city"].ToString() + " " + drFoot["country"].ToString(), 0, 21, 0); // Bold text for ther headers tmpFooter.SetFontAndSize(f_cb, 8); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Phone", 215, 53, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Mail", 215, 45, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Web", 215, 37, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Legal info", 400, 53, 0); // Regular text for infomation fields tmpFooter.SetFontAndSize(f_cn, 8); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, drFoot["phone"].ToString(), 265, 53, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, drFoot["mail"].ToString(), 265, 45, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, drFoot["web"].ToString(), 265, 37, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, drFoot["xtrainfo"].ToString(), 400, 45, 0); // End text tmpFooter.EndText(); // Stamp a line above the page footer cb.SetLineWidth(0f); cb.MoveTo(30, 60); cb.LineTo(570, 60); cb.Stroke(); // Return the footer template return(tmpFooter); }
private void A4Draw(Document document, PdfWriter writer, PdfReader reader, PdfContentByte cb, string pkgcate, int i, int j) { PdfImportedPage newPage; document.NewPage(); //PdfStamper stamp = new PdfStamper(reader, new FileStream("Finish.pdf", FileMode.Create)); newPage = writer.GetImportedPage(reader, 1); if (newPage.Height > newPage.Width) { cb.AddTemplate(newPage, 0, 0); } else { cb.AddTemplate(newPage, 0, 1, -1, 0, newPage.Height, 0); } cb.BeginText(); MarkLocation axis = DrumAxis("A4", 0); cb.SetFontAndSize(bf, 14); cb.SetTextMatrix(0, 1, -1, 0, axis.AsixX, axis.AsixY); //cb.ShowText("桶号:" + j + " " + "to " + Convert.ToInt32(textBox2.Text)); cb.ShowText(pkgcate + "号:" + j); cb.EndText(); int originX = int.Parse(AsixX.Text), originY = int.Parse(AsixY.Text); int MaxX = int.Parse(this.Resources["A4MaxX"].ToString()); int MinY = int.Parse(this.Resources["A4MinY"].ToString()); List <int> ActualX = new List <int>(); List <int> ActualY = new List <int>(); if ((bool)CustomMark.IsChecked) { //自定义文本标签外间距,内间距,尺寸 int x = 0, y = 0, tmx = 8, tmy = 20, w = 170, h = 80; if (CustomMarkText.Text.Length < 2) { w = w / 2; } PdfTemplate cut = cb.CreateTemplate(w, h); //cut.MoveTo(x, y); //cut.LineTo(w - x, 0 + y); //cut.LineTo(w - x, h - y); //cut.LineTo(x, h - y); //cut.LineTo(x, y); //cut.Stroke(); cut.BeginText(); cut.SetFontAndSize(bf, 90); cut.SetTextMatrix(tmx, tmy); cut.ShowTextAligned(1, CustomMarkText.Text, w / 2, 10, 0); //cut.ShowText(culabeltext.Text); cut.EndText(); float zoom = float.Parse(Zoom.Text) / 100; cb.AddTemplate(cut, 0, 1 * zoom, -1 * zoom, 0, originX + h * 1 * zoom, originY - cut.Width * 1 * zoom); ActualX.Add((int)(cut.Height * zoom) + 1); ActualY.Add((int)(cut.Width * zoom) + 2); originX += (int)(cut.Height * zoom) + 1; } if ((bool)StandardMark.IsChecked) { int tmx = 4, tmy = 10, w = 170, h = 30; PdfTemplate cut = cb.CreateTemplate(w, h); cut.BeginText(); cut.SetFontAndSize(bf, 15); cut.SetTextMatrix(tmx, tmy); cut.ShowTextAligned(1, "企业标准:" + StandardCB.Text, w / 2, 10, 0); cut.EndText(); cb.AddTemplate(cut, 0, 1, -1, 0, 500, 40); } if ((bool)Mark3C.IsChecked) { ///3C标签 iTextSharp.text.Image splitline = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\CCC.jpg"); splitline.RotationDegrees = 90; splitline.ScaleAbsolute(50, 50); if (originX + splitline.PlainWidth > MaxX) { originX = int.Parse(AsixX.Text); originY -= ActualY.Max(); } ActualX.Add((int)splitline.PlainHeight + 1); ActualY.Add((int)splitline.PlainWidth + 1); splitline.SetAbsolutePosition(originX, originY - splitline.PlainWidth); cb.AddImage(splitline); //document.Add(splitline); originX = originX + (int)splitline.PlainHeight; } if ((bool)MarkRohs.IsChecked) { iTextSharp.text.Image rohsl = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\rohs.jpg"); rohsl.RotationDegrees = 90; rohsl.ScaleAbsolute(100, 100); if (originX + rohsl.PlainWidth > MaxX) { originX = int.Parse(AsixX.Text); originY -= ActualY.Max(); } ActualX.Add((int)rohsl.PlainHeight + 1); ActualX.Add((int)rohsl.PlainWidth + 1); rohsl.SetAbsolutePosition(originX, originY - rohsl.PlainWidth); cb.AddImage(rohsl); //document.Add(rohsl); originX = originX + (int)rohsl.PlainHeight; } if ((bool)MarkQs.IsChecked) { iTextSharp.text.Image qsl = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\qs.jpg"); qsl.RotationDegrees = 90; qsl.ScaleAbsolute(45, 60); if (originX + qsl.PlainWidth > MaxX) { originX = int.Parse(AsixX.Text); originY -= ActualY.Max(); } ActualX.Add((int)qsl.PlainHeight + 1); ActualY.Add((int)qsl.PlainWidth + 1); qsl.SetAbsolutePosition(originX, originY - qsl.PlainWidth); cb.AddImage(qsl); //document.Add(qsl); originX = originX + (int)qsl.PlainHeight; } if ((bool)HideLogo.IsChecked) { iTextSharp.text.Image bi = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\blank.png"); bi.ScaleAbsolute(57, 76); bi.SetAbsolutePosition(26, 656); cb.AddImage(bi); } }
private void HalfA4Draw(Document document, PdfWriter writer, PdfReader reader, PdfContentByte cb, string pkgcate, int i, int j) { PdfImportedPage newPage; document.NewPage(); newPage = writer.GetImportedPage(reader, 1); cb.AddTemplate(newPage, 0, 0); if ((bool)drumno.IsChecked) { cb.BeginText(); BaseFont bf = BaseFont.CreateFont(@"c:\windows\fonts\SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); cb.SetFontAndSize(bf, 14); List <MarkLocation> axis = DrumAxisList("HalfA4"); cb.SetTextMatrix(axis[0].AsixX, axis[0].AsixY); cb.ShowText(pkgcate + "号:" + j); cb.SetTextMatrix(axis[1].AsixX, axis[1].AsixY); cb.ShowText(pkgcate + "号:" + (Convert.ToInt32(j) + Convert.ToInt32(0))); cb.EndText(); } int originX = 241; int[] originY = { 239, 649 }; if ((bool)Mark3C.IsChecked) { ///3C标签 iTextSharp.text.Image splitline = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\CCC.jpg"); splitline.ScaleAbsolute(50, 50); splitline.SetAbsolutePosition(originX - splitline.PlainWidth, originY[0] - splitline.PlainHeight); cb.AddImage(splitline); splitline.SetAbsolutePosition(originX - splitline.PlainWidth, originY[1] - splitline.PlainHeight); cb.AddImage(splitline); //originX = originX + (int)splitline.PlainHeight; } if ((bool)MarkRohs.IsChecked) { iTextSharp.text.Image rohsl = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\rohs.jpg"); rohsl.ScaleAbsolute(80, 80); rohsl.SetAbsolutePosition(originX - rohsl.ScaledWidth, originY[0] - rohsl.ScaledHeight); cb.AddImage(rohsl); rohsl.SetAbsolutePosition(originX - rohsl.ScaledWidth, originY[1] - rohsl.ScaledHeight); cb.AddImage(rohsl); //originX = originX + (int)rohsl.PlainHeight; } if ((bool)MarkQs.IsChecked) { iTextSharp.text.Image qsl = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\qs.jpg"); qsl.ScaleAbsolute(45, 60); qsl.SetAbsolutePosition(originX - qsl.ScaledWidth, originY[0] - qsl.ScaledHeight); cb.AddImage(qsl); qsl.SetAbsolutePosition(originX - qsl.ScaledWidth, originY[1] - qsl.ScaledHeight); cb.AddImage(qsl); //originX = originX + (int)qsl.PlainHeight; } if ((bool)HideLogo.IsChecked) { iTextSharp.text.Image bi = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\blank.png"); bi.ScaleAbsolute(63, 54); bi.SetAbsolutePosition(492, 351); cb.AddImage(bi); bi.SetAbsolutePosition(492, 762); cb.AddImage(bi); } if ((bool)CustomMark.IsChecked) { int tmx = 8, tmy = 20, w = 170, h = 80; if (CustomMarkText.Text.Length < 2) { w = w / 2; } PdfTemplate cut = cb.CreateTemplate(w, h); cut.BeginText(); cut.SetFontAndSize(bf, 55); cut.SetTextMatrix(tmx, tmy); cut.ShowTextAligned(1, CustomMarkText.Text, w / 2, 10, 0); cut.EndText(); cb.AddTemplate(cut, 1, 0, 0, 1, 180, 60); cb.AddTemplate(cut, 1, 0, 0, 1, 180, 471); } }
private PdfTemplate PdfFooter(PdfContentByte cb) { // Create the template and assign height PdfTemplate tmpFooter = cb.CreateTemplate(580, 70); // Move to the bottom left corner of the template tmpFooter.MoveTo(1, 1); // Place the footer content tmpFooter.Stroke(); // Begin writing the footer tmpFooter.BeginText(); // Set the font and size tmpFooter.SetFontAndSize(f_cn, 8); // Write out details from the payee table tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Politexniki Ltd", 0, 53, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Thessaloniki", 0, 45, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Menemeni", 0, 37, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "20", 0, 29, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "56123" + " " + "Thessaloniki" + " " + "Greece", 0, 21, 0); // Bold text for ther headers tmpFooter.SetFontAndSize(f_cb, 8); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Phone", 215, 53, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Mail", 215, 45, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Web", 215, 37, 0); //tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Legal info", 400, 53, 0); // Regular text for infomation fields tmpFooter.SetFontAndSize(f_cn, 8); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "456155616", 265, 53, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "*****@*****.**", 265, 45, 0); tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "www.politexniki.gr", 265, 37, 0); // End text tmpFooter.EndText(); // Stamp a line above the page footer cb.SetLineWidth(0f); cb.MoveTo(30, 60); cb.LineTo(560, 60); cb.Stroke(); // Return the footer template return(tmpFooter); }