public override void DrawLine(IPen pen, float x1, float y1, float x2, float y2) { if (pen == null) { return; } x1 = CheckVal(x1, false); y1 = CheckVal(y1, true); x2 = CheckVal(x2, false); y2 = CheckVal(y2, true); SetPen(pen); fCanvas.MoveTo(x1, y1); fCanvas.LineTo(x2, y2); fCanvas.Stroke(); }
void DrawElement(PdfContentByte cb) { try { IList <PathItem> translatedItems = Translate(path.PathItems); //loop over the items in the path foreach (PathItem item in translatedItems) { IList <float> numbers = item.Coordinates; if (item.IsMoveTo()) { cb.MoveTo(numbers[0], numbers[1]); } else if (item.IsLineTo()) { cb.LineTo(numbers[0], numbers[1]); } else if (item.IsCubicBezier()) { cb.CurveTo(numbers[0], numbers[1], numbers[2], numbers[3], numbers[4], numbers[5]); } else if (item.IsQuadraticBezier()) { cb.CurveTo(numbers[0], numbers[1], numbers[2], numbers[3]); } else if (item.IsArcTo()) { DrawArc(cb, numbers); } else if (item.IsClosePath()) { cb.ClosePath(); } else { //System.out.Println(item); } } } catch { //TODO } }
private static void Render_BackBase(PdfContentByte under) { // Y relative to card top, line width, <repeat> float[] measures = new[] { 37, 3f, 144, 1.5f }; under.SaveState(); for (int i = 0; i < measures.Length / 2; i++) { under.SetLineWidth(measures[i * 2 + 1]); under.MoveTo(0, CARD_HEIGHT - measures[i * 2]); under.LineTo(CARD_WIDTH, CARD_HEIGHT - measures[i * 2]); under.Stroke(); } under.SetFontAndSize(baseFont, 7); under.ShowTextAlignedKerned(Element.ALIGN_CENTER, "If found, please call KCSAR at (206) 205-8226", CARD_WIDTH / 2, 7, 0); under.RestoreState(); }
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); }
public override void OnStartPage(PdfWriter writer, Document document) { PdfContentByte cb = writer.DirectContent; cb.BeginText(); float height = writer.PageSize.Height, width = writer.PageSize.Width; float marginLeft = document.LeftMargin, marginTop = document.TopMargin, marginRight = document.RightMargin, marginBottom = document.BottomMargin; cb.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED), 8); #region JUDUL var judulY = height - marginTop + 10; cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "FORMAT STRUKTUR BIAYA PER UNIT", width / 2, judulY, 0); #endregion #region LINE cb.MoveTo(marginLeft + 200, height - marginTop + 5); cb.LineTo(width - marginRight - 200, height - marginTop + 5); cb.Stroke(); #endregion #region SUB JUDUL var subJudulY = height - marginTop - 5; cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "( DALAM US $ )", width / 2, subJudulY, 0); #endregion #region PRINTED //var printY = marginBottom - 10; //cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Waktu Cetak : " + DateTimeOffset.Now.ToOffset(new TimeSpan(_identityProvider.TimezoneOffset, 0, 0)).ToString("dd MMMM yyyy H:mm:ss zzz"), marginLeft, printY, 0); #endregion cb.EndText(); }
public void crearEncabezado(Document doc, PdfWriter writer) { doc.NewPage(); Image imagen = colocarImagenUCR(doc); imagen.Alignment = Image.TEXTWRAP | Image.LEFT_ALIGN; doc.Add(imagen); imagen = colocarImagenECCI(doc); imagen.Alignment = Image.TEXTWRAP | Image.RIGHT_ALIGN; doc.Add(imagen); Paragraph parrafo = new Paragraph(); parrafo = GenerarParrafo("Universidad de Costa Rica\nFacultad de Ingeniería\nEscuela de Ciencias de la Computación e\nInformática"); parrafo.Font.SetColor(0, 0, 255); doc.Add(parrafo); PdfContentByte cb = writer.DirectContent; cb.MoveTo(40, doc.PageSize.Height - 120); cb.LineTo(doc.PageSize.Width - 40, doc.PageSize.Height - 120); cb.Stroke(); }
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); }
public void crearPieDePagina(Document doc, PdfWriter writer) { BaseFont bf = basePie; PdfContentByte cb = writer.DirectContent; cb.MoveTo(40, 120); cb.LineTo(doc.PageSize.Width - 40, 120); cb.Stroke(); cb.BeginText(); cb.SetFontAndSize(bf, 10); cb.SetTextMatrix(doc.Left, 80); cb.ShowText("Teléfono: (506) 2511-8000"); cb.SetTextMatrix(doc.Left, 68); cb.ShowText("http://www.ecci.ucr.ac.cr"); cb.SetTextMatrix(doc.Right - 95, 80); cb.ShowText("Fax: (506) 2511-5527"); cb.EndText(); Image imagen = colocarImagenAcreditacion(doc); imagen.Alignment = Image.TEXTWRAP | Image.ALIGN_CENTER; doc.Add(imagen); }
public static bool gera(string arquivo, string nf, short seq) { FileStream fs = new FileStream(arquivo, FileMode.Create); Document doc = new Document(PageSize.LETTER); float altura = PageSize.LETTER.Height - doc.TopMargin - doc.BottomMargin; float largura = PageSize.LETTER.Width - doc.LeftMargin - doc.RightMargin; PdfWriter writer = PdfWriter.GetInstance(doc, fs); doc.Open(); GeraRecibo(doc, writer, nf, seq, PageSize.LETTER.Height - doc.TopMargin); PdfContentByte buf = writer.DirectContent; buf.SetLineDash(3f, 3f); buf.MoveTo(0, PageSize.LETTER.Height / 2); buf.LineTo(PageSize.LETTER.Width, PageSize.LETTER.Height / 2); buf.Stroke(); GeraRecibo(doc, writer, nf, seq, PageSize.LETTER.Height / 2 - 30); doc.Close(); return(true); }
/// <summary> /// The process drawings. /// </summary> /// <param name="drawings"> /// The drawings. /// </param> /// <param name="stamper"> /// The stamper. /// </param> /// <param name="reader"> /// The reader. /// </param> private void ProcessDrawings(IEnumerable <ATDrawing> drawings, PdfStamper stamper, PdfReader reader) { foreach (var dr in drawings) { PdfContentByte cb = stamper.GetOverContent(dr.Mark.PageIndex); var size = reader.GetPageSizeWithRotation(dr.Mark.PageIndex); var bc = GetColor(dr.Color); cb.SetColorStroke(bc); cb.SetLineWidth(2); var parsedPoints = this.ParseDrawing(dr.Points, size).ToList(); if (parsedPoints.Any()) { var firstPoint = parsedPoints.First(); cb.MoveTo(firstPoint.X, firstPoint.Y); foreach (var point in parsedPoints) { cb.LineTo(point.X, point.Y); } cb.Stroke(); } } }
/// <summary> /// Draws a horizontal line. /// </summary> /// <param name="canvas">the canvas to draw on</param> /// <param name="leftX">the left x coordinate</param> /// <param name="rightX">the right x coordindate</param> /// <param name="y">the y coordinate</param> public void DrawLine(PdfContentByte canvas, float leftX, float rightX, float y) { float w; if (Percentage < 0) { w = -Percentage; } else { w = (rightX - leftX) * Percentage / 100.0f; } float s; switch (Alignment) { case Element.ALIGN_LEFT: s = 0; break; case Element.ALIGN_RIGHT: s = rightX - leftX - w; break; default: s = (rightX - leftX - w) / 2; break; } canvas.SetLineWidth(LineWidth); if (LineColor != null) { canvas.SetColorStroke(LineColor); } canvas.MoveTo(s + leftX, y + Offset); canvas.LineTo(s + w + leftX, y + Offset); canvas.Stroke(); }
// write on end of each page public override void OnEndPage(PdfWriter writer, Document document) { base.OnEndPage(writer, document); PdfPTable tabFot = new PdfPTable(3); PdfPCell cellDate; PdfPCell cellCretedBy; PdfPCell cellPage; tabFot.TotalWidth = 700F; cellDate = new PdfPCell(new Phrase("Date : " + DateTime.Now.ToString("MM/dd/yyyy"))); cellCretedBy = new PdfPCell(new Phrase("Created By www.geesemed.com")); cellPage = new PdfPCell(new Phrase("Page." + writer.PageNumber)); tabFot.AddCell(cellDate); tabFot.AddCell(cellCretedBy); tabFot.AddCell(cellPage); cb.BeginText(); cb.SetFontAndSize(bf, 10); cb.SetTextMatrix(40f, document.PageSize.GetBottom(10)); cb.ShowText("Date : " + DateTime.Now.ToString("MM/dd/yyyy")); cb.SetTextMatrix(230f, document.PageSize.GetBottom(10)); cb.ShowText(" Created By www.geesemed.com"); cb.SetTextMatrix(520f, document.PageSize.GetBottom(10)); cb.ShowText("Page." + writer.PageNumber); cb.EndText(); float len = bf.GetWidthPoint("Date : " + DateTime.Now.ToString("MM/dd/yyyy"), 12); float len1 = bf.GetWidthPoint(" Created By www.geesemed.com", 12); float len2 = bf.GetWidthPoint("Page." + writer.PageNumber, 12); cb.AddTemplate(footerTemplate, 10f, document.PageSize.GetBottom(25)); // tabFot.WriteSelectedRows(0,-1, 40, document.Bottom, writer.DirectContent); //Move the pointer and draw line to separate footer section from rest of page cb.MoveTo(40, document.PageSize.GetBottom(25)); cb.LineTo(document.PageSize.Width - 40, document.PageSize.GetBottom(25)); cb.Stroke(); }
//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 override void OnStartPage(PdfWriter writer, Document document) { base.OnStartPage(writer, document); Rectangle pagesize = document.PageSize; Rectangle rect; if (Header != String.Empty) { cb.BeginText(); cb.SetFontAndSize(bf, 12); cb.SetTextMatrix(pagesize.GetLeft(40), pagesize.GetTop(30)); cb.ShowText(Header); cb.EndText(); cb.MoveTo(pagesize.GetLeft(40), pagesize.GetTop(35)); cb.LineTo(pagesize.GetRight(40), pagesize.GetTop(35)); cb.SetLineWidth(3f); cb.Stroke(); } if (Body != null) { cb = writer.DirectContent; //cb.BeginText(); cb.SetFontAndSize(bf, 100); rect = new Rectangle(pagesize.GetLeft(40), pagesize.GetTop(40), 100, 100); cb.Rectangle(rect); cb.Stroke(); ColumnText ct = new ColumnText(cb); ct.SetSimpleColumn(rect); ct.AddElement(new iTextSharp.text.Paragraph(Body)); ct.Go(); //cb.ShowText("hello"); //cb.EndText(); } }
public override void OnEndPage(iTextSharp.text.pdf.PdfWriter writer, iTextSharp.text.Document document) { base.OnEndPage(writer, document); iTextSharp.text.Font baseFontNormal = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 3f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK); iTextSharp.text.Font baseFontBig = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 5f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK); PdfPTable pdfTab = new PdfPTable(3); PdfPCell pdfCell1 = new PdfPCell(); PdfPCell pdfCell3 = new PdfPCell(); pdfCell1.HorizontalAlignment = Element.ALIGN_CENTER; pdfCell3.HorizontalAlignment = Element.ALIGN_CENTER; pdfCell3.VerticalAlignment = Element.ALIGN_MIDDLE; pdfCell1.Border = 0; pdfCell3.Border = 0; pdfTab.AddCell(pdfCell1); pdfTab.AddCell(pdfCell3); pdfTab.TotalWidth = document.PageSize.Width - 80f; pdfTab.WidthPercentage = 70; pdfTab.WriteSelectedRows(0, -1, -400, document.PageSize.Height - 350, writer.DirectContent); cb.MoveTo(40, document.PageSize.GetBottom(30)); cb.LineTo(document.PageSize.Width - 40, document.PageSize.GetBottom(30)); cb.Stroke(); }
public override void OnStartPage(PdfWriter writer, Document document) { PdfContentByte cb = writer.DirectContent; cb.BeginText(); BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED); float height = writer.PageSize.Height, width = writer.PageSize.Width; float marginLeft = document.LeftMargin - 10, marginTop = document.TopMargin, marginRight = document.RightMargin - 10; cb.SetFontAndSize(bf, 6); #region LEFT var branchOfficeY = height - marginTop + 50; cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "REPRESENTATIVE OFFICE :", marginLeft, branchOfficeY, 0); string[] branchOffices = { "Jl. CBD SELATAN RUKO PMP TEMATIK P/30", "CURUG SANGERANG, KELAPA DUA, TANGERANG", "TELP. : (+62 21) 29009777", }; for (int i = 0; i < branchOffices.Length; i++) { cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, branchOffices[i], marginLeft, branchOfficeY - 10 - (i * 8), 0); } #endregion #region CENTER var headOfficeX = width / 2 + 30; var headOfficeY = height - marginTop + 45; byte[] imageByte = Convert.FromBase64String(Base64ImageStrings.LOGO_NAME); Image image = Image.GetInstance(imageByte); if (image.Width > 160) { float percentage = 0.0f; percentage = 160 / image.Width; image.ScalePercent(percentage * 100); } image.SetAbsolutePosition(headOfficeX - (image.ScaledWidth / 2), headOfficeY); cb.AddImage(image, inlineImage: true); string[] headOffices = { "Head Office : KEL. BANARAN, KEC. GROGOL, KAB. SUKOHARJO, JAWA TENGAH - INDONESIA", "TELP. (+62 271) 719911, FAX. : (+62 271) 719911, ", }; for (int i = 0; i < headOffices.Length; i++) { cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, headOffices[i], headOfficeX, headOfficeY - image.ScaledHeight - (i * 10), 0); } #endregion #region RIGHT byte[] imageByteIso = Convert.FromBase64String(Base64ImageStrings.ISO); Image imageIso = Image.GetInstance(imageByteIso); if (imageIso.Width > 80) { float percentage = 0.0f; percentage = 80 / imageIso.Width; imageIso.ScalePercent(percentage * 100); } imageIso.SetAbsolutePosition(width - imageIso.ScaledWidth - marginRight, height - imageIso.ScaledHeight - marginTop + 60); cb.AddImage(imageIso, inlineImage: true); cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "CERTIFICATE ID09 / 01238", width - (imageIso.ScaledWidth / 2) - marginRight, height - imageIso.ScaledHeight - marginTop + 60 - 5, 0); #endregion #region LINE cb.MoveTo(marginLeft, height - marginTop); cb.LineTo(width - marginRight, height - marginTop - 1); cb.Stroke(); #endregion #region WATERMARK byte[] imageByteCenter = Convert.FromBase64String(Base64ImageStrings.LOGO_WATERMARK); Image imageCenter = Image.GetInstance(imageByteCenter); float percentageImageCenter = 0.0f; percentageImageCenter = 400 / imageCenter.Width; imageCenter.ScalePercent(percentageImageCenter * 100); imageCenter.SetAbsolutePosition((width / 2) - imageCenter.ScaledWidth / 2, (height / 2) - imageCenter.ScaledHeight / 2); //cb.AddImage(imageCenter); document.Add(imageCenter); #endregion cb.EndText(); }
/* a method that save the packing slip pdf */ public static void CreatePackingSlip(SearsValues value, int[] cancelIndex, bool preview) { // the case if all of the items in the order are cancelled -> don't need to print the packing slip if (cancelIndex.Length >= value.LineCount) { return; } // first check if the save directory exist -> if not create it if (!File.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } // print each item for packing slip for (int i = 0; i < value.LineCount; i++) { // check if the item is in cancel list bool cancelled = cancelIndex.Any(j => i == j); // the case if the item is not cancelled -> generate and export it if (!cancelled) { // initialize PdfWriter object Document doc = new Document(PageSize.LETTER, 0, 0, 0, 35); string file = SavePath + "\\" + value.TransactionId + '_' + (i + 1) + ".pdf"; PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(file, FileMode.Create)); // open the document doc.Open(); PdfContentByte contentByte = writer.DirectContent; #region Draw Line - Divided Half // drawline PdfContentByte draw = writer.DirectContent; draw.MoveTo(doc.PageSize.Width / 2, 0); draw.LineTo(doc.PageSize.Width / 2, doc.PageSize.Height); draw.Stroke(); #endregion // initialize local fields for text BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false); BaseFont boldFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, false); ColumnText ct = new ColumnText(draw); #region Shipping Address and Schedule // set bill to // title Phrase text = new Phrase("BILL TO/FACTURER A:", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 10f, 753f, 150f, 773f, 0f, Element.ALIGN_LEFT); ct.Go(); // bill recipient and address text = new Phrase(value.BillTo.Name + '\n' + value.BillTo.Address1 + '\n' + value.BillTo.Address2 + '\n' + value.BillTo.City, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 10f, 726f, 150f, 771f, 9f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.BillTo.State + '\n' + value.BillTo.PostalCode, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 120f, 704f, 170f, 744f, 9f, Element.ALIGN_LEFT); ct.Go(); // set ship to // title text = new Phrase("RECIPIENT/DESTINATAIRA:", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 10f, 693f, 150f, 713f, 0f, Element.ALIGN_LEFT); ct.Go(); // ship recipient and address text = new Phrase(value.Recipient.Name + '\n' + value.Recipient.Address1 + '\n' + value.Recipient.Address2 + '\n' + value.Recipient.City, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 10f, 666f, 150f, 711f, 9f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.Recipient.State + '\n' + value.Recipient.PostalCode, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 120f, 643f, 170f, 683f, 9f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.Recipient.DayPhone, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 10f, 645f, 150f, 655f, 0f, Element.ALIGN_LEFT); ct.Go(); // arrival date // title text = new Phrase("ARRIVAL DATE/D'ARRIVEE", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 208f, 745f, 308f, 765f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.OrderDate.ToString("MM/dd/yy"), new Font(baseFont, 10)); ct.SetSimpleColumn(text, 226f, 745f, 276f, 755f, 0f, Element.ALIGN_LEFT); ct.Go(); // schedule text = new Phrase("SCHEDULE", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 227f, 727f, 312f, 737f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.CustOrderDate.ToString("MM/dd/yy"), new Font(baseFont, 10)); ct.SetSimpleColumn(text, 226f, 717f, 279f, 727f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion // sku description text = new Phrase(value.Description[i] + '\n' + value.Description2[i], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 10f, 616f, 150f, 646f, 10f, Element.ALIGN_LEFT); ct.Go(); #region Top Left Boxes #region First Box // upper and lower line for sku box draw.MoveTo(15, 616); draw.LineTo(118, 616); draw.Stroke(); draw.MoveTo(15, 594); draw.LineTo(118, 594); draw.Stroke(); // straight lines for sku box draw.MoveTo(15, 616); draw.LineTo(15, 594); draw.Stroke(); draw.MoveTo(38, 616); draw.LineTo(38, 594); draw.Stroke(); draw.MoveTo(61, 616); draw.LineTo(61, 594); draw.Stroke(); draw.MoveTo(95, 616); draw.LineTo(95, 594); draw.Stroke(); draw.MoveTo(118, 616); draw.LineTo(118, 594); draw.Stroke(); // title in the first box text = new Phrase("D M I SKU", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 23f, 599f, 173f, 609f, 0f, Element.ALIGN_LEFT); ct.Go(); // data in the first box string merchantSku = value.TrxMerchantSku[i]; text = new Phrase(merchantSku.Remove(2), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 23f, 587f, 38f, 597f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("", new Font(baseFont, 9)); ct.SetSimpleColumn(text, 46f, 587f, 61f, 597f, 0f, Element.ALIGN_LEFT); ct.Go(); int index = 2; if (merchantSku[2] == ' ') { index = 3; } text = new Phrase(merchantSku.Substring(index, 5), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 65f, 587f, 118f, 597f, 0f, Element.ALIGN_LEFT); ct.Go(); index = index + 5; if (merchantSku.Length <= index) { merchantSku = ""; } else if (merchantSku[index] == ' ') { index++; merchantSku = merchantSku.Substring(index); } else { merchantSku = merchantSku.Substring(index); } text = new Phrase(merchantSku, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 99f, 587f, 118f, 597f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Second Box // upper and lower line for second box draw.MoveTo(15, 589); draw.LineTo(130, 589); draw.Stroke(); draw.MoveTo(15, 558); draw.LineTo(130, 558); draw.Stroke(); // straight lines for sku box draw.MoveTo(15, 589); draw.LineTo(15, 558); draw.Stroke(); draw.MoveTo(55, 589); draw.LineTo(55, 558); draw.Stroke(); draw.MoveTo(90, 589); draw.LineTo(90, 558); draw.Stroke(); draw.MoveTo(130, 589); draw.LineTo(130, 558); draw.Stroke(); // title in the second box text = new Phrase(" D REASON DATE\nM.U.C RAISON", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 24f, 553.5f, 174f, 603.5f, 21.5f, Element.ALIGN_LEFT); ct.Go(); #endregion #endregion #region Price // price titles text = new Phrase("MERCH. PRICE\nPRIX DE MARCH", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 622f, 247f, 637f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("DISCOUNT\nESCOMPTE", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 610f, 247f, 625f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("G.S.T./H.S.T.\nT.P.S./T.V.H.", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 598f, 247f, 613f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("P.S.T.\nT.V.P.", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 586f, 247f, 601f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("Total", new Font(boldFont, 7)); ct.SetSimpleColumn(text, 197f, 567f, 247f, 582f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("PRICE\nPRIX", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 546f, 247f, 561f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("DISCOUNT\nESCOMPTE", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 534f, 247f, 549f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("HANDLING\nMANUTENTION", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 522f, 247f, 537f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("ELEVY\nTAXE ENVIRO", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 510f, 247f, 525f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("DELIVERY\nLIVRAISON", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 498f, 247f, 513f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("G.S.T./H.S.T.\nT.P.S./T.V.H.", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 486f, 247f, 501f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("P.S.T.\nT.V.P.", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 474f, 247f, 489f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("Total", new Font(boldFont, 7)); ct.SetSimpleColumn(text, 197f, 455f, 247f, 470f, 0f, Element.ALIGN_LEFT); ct.Go(); // price number char temp; if (value.GstHstExtended[i] > 0 && value.PstExtended[i] > 0) { temp = 'B'; } else if (value.GstHstExtended[i] > 0) { temp = 'T'; } else if (value.PstExtended[i] > 0) { temp = 'P'; } else { temp = ' '; } text = new Phrase(value.UnitPrice[i] + " " + temp, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 252f, 613f, 292f, 628f, 0f, Element.ALIGN_LEFT); ct.Go(); string[] tempTax = new string[2]; switch (temp) { case 'B': tempTax[0] = value.GstHstExtended[i].ToString(CultureInfo.InvariantCulture); tempTax[1] = value.PstExtended[i].ToString(CultureInfo.InvariantCulture); break; case 'T': tempTax[0] = value.GstHstExtended[i].ToString(CultureInfo.InvariantCulture); tempTax[1] = string.Empty; break; case 'P': tempTax[0] = string.Empty; tempTax[1] = value.PstExtended[i].ToString(CultureInfo.InvariantCulture); break; default: tempTax[0] = string.Empty; tempTax[1] = string.Empty; break; } text = new Phrase(tempTax[0], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 252f, 589.5f, 292f, 604.5f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(tempTax[1], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 252f, 579f, 292f, 594f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase((value.UnitPrice[i] + value.GstHstExtended[i] + value.PstExtended[i]).ToString(CultureInfo.InvariantCulture), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 252f, 562f, 292f, 582f, 0f, Element.ALIGN_LEFT); ct.Go(); if (value.GstHstTotal[i] > 0 && value.PstTotal[i] > 0) { temp = 'B'; } else if (value.GstHstTotal[i] > 0) { temp = 'T'; } else if (value.PstTotal[i] > 0) { temp = 'P'; } else { temp = ' '; } switch (temp) { case 'B': tempTax[0] = value.GstHstTotal[i].ToString(CultureInfo.InvariantCulture); tempTax[1] = value.PstTotal[i].ToString(CultureInfo.InvariantCulture); break; case 'T': tempTax[0] = value.GstHstTotal[i].ToString(CultureInfo.InvariantCulture); tempTax[1] = string.Empty; break; case 'P': tempTax[0] = string.Empty; tempTax[1] = value.PstTotal[i].ToString(CultureInfo.InvariantCulture); break; default: tempTax[0] = string.Empty; tempTax[1] = string.Empty; break; } text = new Phrase(value.UnitPrice[i] + " " + temp, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 252f, 533f, 293f, 553f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.LineHandling[i].ToString(CultureInfo.InvariantCulture), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 252f, 513f, 293f, 528f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.LineShipping[i].ToString(CultureInfo.InstalledUICulture), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 252f, 490f, 293f, 505f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(tempTax[0], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 252f, 478f, 293f, 493f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(tempTax[1], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 252f, 466f, 293f, 481f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.LineBalanceDue[i].ToString(CultureInfo.InvariantCulture), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 252f, 455f, 292f, 470f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Left Unknown Region // Other things that I don't know what is this for :( text = new Phrase("SEARS CANADA / VI", new Font(baseFont, 9)); ct.SetSimpleColumn(text, 10f, 470f, 150f, 485f, 10f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("ORDER NO. DE COMMANDE", new Font(boldFont, 7)); ct.SetSimpleColumn(text, 10f, 457f, 150f, 472f, 10f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.CustOrderNumber, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 10f, 446f, 150f, 462f, 10f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("VENDOR SKU\n" + value.TrxVendorSku[i], new Font(boldFont, 13)); ct.SetSimpleColumn(text, 10f, 400f, 150f, 450f, 11f, Element.ALIGN_LEFT); ct.Go(); // sku title text = new Phrase("D M I Q C SKU G", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 10f, 413.5f, 250f, 428.5f, 10f, Element.ALIGN_LEFT); ct.Go(); // sku number merchantSku = value.TrxMerchantSku[i]; text = new Phrase(merchantSku.Remove(2), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 24f, 413.5f, 39f, 428.5f, 10f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("", new Font(baseFont, 9)); ct.SetSimpleColumn(text, 57f, 413.5f, 72f, 428.5f, 10f, Element.ALIGN_LEFT); ct.Go(); index = 2; if (merchantSku[2] == ' ') { index = 3; } text = new Phrase(merchantSku.Substring(index, 5), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 83f, 413.5f, 123f, 428.5f, 10f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.TrxQty[i].ToString(), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 143f, 413.5f, 158f, 428.5f, 10f, Element.ALIGN_LEFT); ct.Go(); index = index + 5; if (merchantSku.Length <= index) { merchantSku = string.Empty; } else if (merchantSku[index] == ' ') { index++; merchantSku = merchantSku.Substring(index); } else { merchantSku = merchantSku.Substring(index); } text = new Phrase(merchantSku, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 166f, 413.5f, 186f, 428.5f, 10f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Left Bottom Additional Info // some number text = new Phrase(value.PoNumber, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 10f, 357f, 150f, 367f, 0f, Element.ALIGN_LEFT); ct.Go(); // sears infomation text = new Phrase("CUSTOMER INQUIRY/DE CLIENT", new Font(boldFont, 7)); ct.SetSimpleColumn(text, 10f, 338f, 150f, 348f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("WWW.SEARS.CA", new Font(baseFont, 9)); ct.SetSimpleColumn(text, 10f, 328f, 150f, 338f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("1-800-267-3277", new Font(baseFont, 10)); ct.SetSimpleColumn(text, 10f, 318f, 150f, 328f, 0f, Element.ALIGN_LEFT); ct.Go(); // note text = new Phrase("THIS BILL OF SALE IS REQUIRED FOR RETURN OR ADJUSTMENT\nOF PURCHASE.\nCETTE FACTURE EST REQUISE POUR TOUT RETROU DE\nMARCHANDIS OU RECLAMATION.", new Font(boldFont, 9)); ct.SetSimpleColumn(text, 10f, 277f, 320f, 317f, 9f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Button Return Region // draw line first draw.MoveTo(10, 255); draw.LineTo(doc.PageSize.Width / 2, 255); draw.Stroke(); #region Left Box // horizontal lines draw.MoveTo(14, 245); draw.LineTo(129, 245); draw.Stroke(); draw.MoveTo(14, 229.5); draw.LineTo(129, 229.5); draw.Stroke(); draw.MoveTo(14, 214); draw.LineTo(129, 214); draw.Stroke(); // vertical lines draw.MoveTo(14, 245); draw.LineTo(14, 214); draw.Stroke(); draw.MoveTo(129, 245); draw.LineTo(129, 214); draw.Stroke(); // text text = new Phrase("REASON\n RAISON", new Font(baseFont, 11)); ct.SetSimpleColumn(text, 47f, 208f, 97f, 250f, 16f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Right Box // horizontal lines draw.MoveTo(139, 245); draw.LineTo(254, 245); draw.Stroke(); draw.MoveTo(139, 214); draw.LineTo(254, 214); draw.Stroke(); // vertical lines draw.MoveTo(139, 245); draw.LineTo(139, 214); draw.Stroke(); draw.MoveTo(179, 245); draw.LineTo(179, 214); draw.Stroke(); draw.MoveTo(214, 245); draw.LineTo(214, 214); draw.Stroke(); draw.MoveTo(254, 245); draw.LineTo(254, 214); draw.Stroke(); // text text = new Phrase(" D REASON DATE\n RAISON", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 148f, 214f, 254f, 259f, 21f, Element.ALIGN_LEFT); ct.Go(); #endregion #endregion #region Barcode Left Bottom #region Barcode One // barcode number text = new Phrase(value.EncodedPrice[i], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 16f, 177f, 176f, 192f, 0f, Element.ALIGN_LEFT); ct.Go(); // add barcode Barcode128 barcode128 = new Barcode128 { Code = value.EncodedPrice[i], StartStopText = false, Font = null, Extended = true }; Image image = barcode128.CreateImageWithBarcode(contentByte, BaseColor.BLACK, BaseColor.BLACK); image.ScaleAbsoluteHeight(43f); image.SetAbsolutePosition(24f, 145f); contentByte.AddImage(image); // bar code text under text = new Phrase(value.CustOrderDate.ToString("MM/dd/yy") + " " + value.LineBalanceDue[i], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 16f, 123f, 176f, 133f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Barcode Two string code = value.TrxMerchantSku[i].Replace(" ", string.Empty); if (code.Length % 2 != 0) { code += '0'; } BarcodeInter25 barcode25 = new BarcodeInter25 { Code = code, StartStopText = false, Font = null, Extended = true }; image = barcode25.CreateImageWithBarcode(contentByte, BaseColor.BLACK, BaseColor.BLACK); image.ScaleAbsoluteHeight(43f); image.SetAbsolutePosition(24f, 70f); contentByte.AddImage(image); // barcode text text = new Phrase(value.TrxMerchantSku[i] + '\n' + value.Description[i], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 16f, 48f, 156f, 68f, 9f, Element.ALIGN_LEFT); ct.Go(); // section description text = new Phrase("THIS BILL OF SALE IS\nREQUIRED FOR RETURN", new Font(boldFont, 9)); ct.SetSimpleColumn(text, 181f, 66f, 291f, 116f, 9f, Element.ALIGN_LEFT); ct.Go(); // useless stuff text = new Phrase("66", new Font(boldFont, 11)); ct.SetSimpleColumn(text, 200f, 61f, 220f, 71f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("V2C", new Font(boldFont, 13)); ct.SetSimpleColumn(text, 258f, 3f, 300f, 23f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion #endregion #region Right Ship To Address // title text = new Phrase("RECIPIENT/DESTINATAIRA:", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 318f, 753f, 418f, 773f, 0f, Element.ALIGN_LEFT); ct.Go(); // ship to recipient and address text = new Phrase(value.Recipient.Name + '\n' + value.Recipient.Address1 + '\n' + value.Recipient.Address2 + '\n' + value.Recipient.City, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 318f, 726f, 458f, 771f, 9f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.Recipient.State + '\n' + value.Recipient.PostalCode + '\n' + value.ExpectedShipDate[i].ToString("MM/dd/yy"), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 428f, 704f, 488f, 744f, 9f, Element.ALIGN_LEFT); ct.Go(); // ship to phone and total price text = new Phrase(value.Recipient.DayPhone + '\n' + value.LineBalanceDue[i], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 515f, 729f, 605f, 779f, 17f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Barcode Right Top // barcode number text = new Phrase(value.EncodedPrice[i], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 318f, 683f, 468f, 693f, 0f, Element.ALIGN_LEFT); ct.Go(); // add barcode barcode128 = new Barcode128 { Code = value.EncodedPrice[i], StartStopText = false, Font = null, Extended = true }; image = barcode128.CreateImageWithBarcode(contentByte, BaseColor.BLACK, BaseColor.BLACK); image.ScaleAbsoluteHeight(43f); image.SetAbsolutePosition(326f, 646f); contentByte.AddImage(image); // bar code text under text = new Phrase(value.CustOrderDate.ToString("MM/dd/yy") + " " + value.LineBalanceDue[i], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 318f, 625f, 488f, 635f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Top Right Box // upper and lower line for sku box draw.MoveTo(318, 611); draw.LineTo(421, 611); draw.Stroke(); draw.MoveTo(318, 589); draw.LineTo(421, 589); draw.Stroke(); // straight lines for sku box draw.MoveTo(318, 611); draw.LineTo(318, 589); draw.Stroke(); draw.MoveTo(341, 611); draw.LineTo(341, 589); draw.Stroke(); draw.MoveTo(364, 611); draw.LineTo(364, 589); draw.Stroke(); draw.MoveTo(398, 611); draw.LineTo(398, 589); draw.Stroke(); draw.MoveTo(421, 611); draw.LineTo(421, 589); draw.Stroke(); // title in the first box text = new Phrase(" D M I SKU", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 326f, 594f, 476f, 604f, 0f, Element.ALIGN_LEFT); ct.Go(); // data in the first box merchantSku = value.TrxMerchantSku[i]; text = new Phrase(merchantSku.Remove(2), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 326f, 582f, 349f, 592f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("", new Font(baseFont, 9)); ct.SetSimpleColumn(text, 350f, 582f, 365f, 592f, 0f, Element.ALIGN_LEFT); ct.Go(); index = 2; if (merchantSku[2] == ' ') { index = 3; } text = new Phrase(merchantSku.Substring(index, 5), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 368f, 582f, 400f, 592f, 0f, Element.ALIGN_LEFT); ct.Go(); index = index + 5; if (merchantSku.Length <= index) { merchantSku = string.Empty; } else if (merchantSku[index] == ' ') { index++; merchantSku = merchantSku.Substring(index); } else { merchantSku = merchantSku.Substring(index); } text = new Phrase(merchantSku, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 402f, 582f, 422f, 592f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion // sku description text = new Phrase(value.Description[i] + '\n' + value.Description2[i], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 318f, 560f, 458f, 585f, 10f, Element.ALIGN_LEFT); ct.Go(); #region Right Unknown Region // determine if the order is direct shipment string take = value.PartnerPersonPlaceId == "" ? "DIRECT" : value.PartnerPersonPlaceId; text = new Phrase(take, new Font(boldFont, 16)); ct.SetSimpleColumn(text, 318f, 519f, 418f, 539f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("CSU:", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 318f, 518f, 418f, 528f, 0f, Element.ALIGN_LEFT); ct.Go(); if (take != "DIRECT") { // strange address text = new Phrase(value.ShipTo.Name + '\n' + value.ShipTo.Address1 + '\n' + value.ShipTo.Address2 + '\n' + value.ShipTo.City, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 318f, 481f, 468f, 526f, 9f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.ShipTo.State + '\n' + value.ShipTo.PostalCode, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 428f, 459f, 488f, 499f, 9f, Element.ALIGN_LEFT); ct.Go(); // strange message text = new Phrase(value.PaymentMethod + " " + value.LineBalanceDue[i], new Font(baseFont, 13)); ct.SetSimpleColumn(text, 318f, 452f, 618f, 472f, 9f, Element.ALIGN_LEFT); ct.Go(); } // strange message continue text = new Phrase(value.PackSlipMessage, new Font(baseFont, 7)); ct.SetSimpleColumn(text, 318f, 441f, 418f, 451f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Buttom Right Ship To Address //title text = new Phrase("SHIP TO/EXPEDIER A:", new Font(boldFont, 10)); ct.SetSimpleColumn(text, 318f, 408f, 458f, 423f, 0f, Element.ALIGN_LEFT); ct.Go(); // address text = new Phrase(value.Recipient.Name + '\n' + value.ShipTo.Address1 + '\n' + value.ShipTo.Address2 + '\n' + value.ShipTo.City, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 318f, 375f, 468f, 420f, 9f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.ShipTo.State + '\n' + value.ShipTo.PostalCode, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 428f, 362f, 488f, 392f, 9f, Element.ALIGN_LEFT); ct.Go(); // freight info text = new Phrase("FREIGHE LANE/LIGNE DE FRET: SPUR/CONVOYEUR:", new Font(boldFont, 7)); ct.SetSimpleColumn(text, 318f, 348f, 568f, 358f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.FreightLane, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 318f, 348f, 358f, 358f, 9f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.Spur, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 465f, 348f, 495f, 358f, 9f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Right Buttom Barcode // barcode number text = new Phrase(value.ReceivingInstructions[i], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 318f, 306f, 468f, 316f, 0f, Element.ALIGN_LEFT); ct.Go(); // add barcode code = value.ReceivingInstructions[i].Replace(" ", string.Empty); if (code.Length % 2 != 0) { code += '0'; } barcode25 = new BarcodeInter25 { Code = code, StartStopText = false, Font = null, Extended = true }; image = barcode25.CreateImageWithBarcode(contentByte, BaseColor.BLACK, BaseColor.BLACK); image.ScaleAbsoluteHeight(43f); image.SetAbsolutePosition(326f, 269f); contentByte.AddImage(image); // a minor stuff text = new Phrase("V2C", new Font(boldFont, 30)); ct.SetSimpleColumn(text, 480f, 85f, 550f, 135f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion doc.Close(); if (!preview) { continue; } // start the pdf for previewing if (System.Diagnostics.Process.GetProcessesByName(file).Length < 1) { System.Diagnostics.Process.Start(file); } } } }
private void Btn_PDFGen_Click(object sender, EventArgs e) { //var m = new ITModel.ITModelContainer(); //var list = (from pp in m.PERSONNELs // select pp).ToList(); using (Document pdfDoc = new Document(PageSize.A4)) { _myFont = GetFont("Parastoo-Print", 14); _myFontBold = GetFont("Parastoo-Print", 16); PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, new FileStream("Test.pdf", FileMode.Create)); var readPassword = Encoding.UTF8.GetBytes(""); //it can be null. var editPassword = Encoding.UTF8.GetBytes("456"); int permissions = PdfWriter.ALLOW_PRINTING | PdfWriter.ALLOW_COPY; pdfWriter.SetEncryption(readPassword, editPassword, permissions, PdfWriter.STRENGTH128BITS); //pdfWriter.PageEvent = new PageEvents(); pdfDoc.Open(); pdfDoc.AddAuthor("AddAuthor"); pdfDoc.AddCreator("AddCreator"); pdfDoc.AddTitle("AddTitle"); pdfDoc.AddSubject("AddSubject"); pdfDoc.AddKeywords("iTextSharp,C#"); float[] widths = new float[] { 1.5f, 5f, 1.5f }; PdfPTable headerTb = new PdfPTable(widths) { RunDirection = PdfWriter.RUN_DIRECTION_RTL, WidthPercentage = 100, DefaultCell = { Border = Rectangle.NO_BORDER } }; //headerTb.DefaultCell.Border = Rectangle.NO_BORDER; #region Det PdfPTable formDetail = new PdfPTable(2) { RunDirection = PdfWriter.RUN_DIRECTION_RTL }; formDetail.AddCell(new PdfPCell() { Phrase = new Phrase(FixWeakCharacters("تاریخ: "), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER }); formDetail.AddCell(new PdfPCell() { Phrase = new Phrase(FixWeakCharacters("[date]"), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER }); formDetail.AddCell(new PdfPCell() { Phrase = new Phrase(FixWeakCharacters("شماره: "), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER }); formDetail.AddCell(new PdfPCell() { Phrase = new Phrase(FixWeakCharacters("[number]"), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER }); formDetail.AddCell(new PdfPCell() { Phrase = new Phrase(FixWeakCharacters("پیوست: "), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER }); formDetail.AddCell(new PdfPCell() { Phrase = new Phrase(FixWeakCharacters("[index]"), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER }); headerTb.AddCell(formDetail); #endregion #region Header headerTb.AddCell(new PdfPCell() { Phrase = new Phrase(FixWeakCharacters("بسمه تعالی"), _myFontBold), Padding = 5, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_BOTTOM, Border = Rectangle.NO_BORDER }); #endregion #region Logo iTextSharp.text.Image logoPng = iTextSharp.text.Image.GetInstance("logo.png"); logoPng.ScaleToFit(50f, 50f); logoPng.Alignment = Element.ALIGN_LEFT; headerTb.AddCell(new PdfPCell() { Padding = 5, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_CENTER, Image = logoPng, Border = Rectangle.NO_BORDER }); #endregion #region Parageraph string firstParaStr = "CompanyName" + " بیمهگذارِ بیمهنامه شماره " + "InsuranceNumber" + " اینجانب " + "ExpertName" + " نمایندگی " + "Namayandegi" + " کد " + "CodeNamayandegi" + " به اتفاق نماینده صاحب کالا به محل بارگیری محل بارگیری به نشانی " + "Address" + " مراجعه و از کالای آماده حمل با مشخصات زیر بازدید نمودم که نتیجه بازدید و نظر اینجانب به شرح ذیل میباشد:"; PdfPTable matnTb = new PdfPTable(1) { RunDirection = PdfWriter.RUN_DIRECTION_RTL, WidthPercentage = 100 }; matnTb.AddCell(new PdfPCell() { Phrase = new Phrase(FixWeakCharacters("گزارش بازدید اولیه، بیمه مسئولیت متصدیان حمل و نفل داخلی"), GetFont("Parastoo-Print", 16)), Padding = 5, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_TOP, BorderColorBottom = BaseColor.WHITE, Border = Rectangle.NO_BORDER }); matnTb.AddCell(new PdfPCell() { Phrase = new Phrase(FixWeakCharacters(" بازگشت به درخواست مورخ " + "date" + " شرکت حمل و نقل "), GetFont("Parastoo-Print", 15)), Padding = 5, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_TOP, Border = Rectangle.NO_BORDER }); matnTb.AddCell( new PdfPCell( new Paragraph(new Chunk(firstParaStr, _myFont).setLineHeight(25))) { Border = Rectangle.NO_BORDER, MinimumHeight = 150 }); #endregion #region CheckList PdfPTable checkListTb = new PdfPTable(2) { ExtendLastRow = true, RunDirection = PdfWriter.RUN_DIRECTION_RTL, WidthPercentage = 100, }; checkListTb.AddCell(new PdfPCell() { RunDirection = PdfWriter.RUN_DIRECTION_RTL, Phrase = new Phrase(FixWeakCharacters("نوع محموله: "), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER, FixedHeight = 40 }); checkListTb.AddCell(new PdfPCell() { RunDirection = PdfWriter.RUN_DIRECTION_RTL, Phrase = new Phrase(FixWeakCharacters("نام راننده: "), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER, FixedHeight = cellHeight }); checkListTb.AddCell(new PdfPCell() { RunDirection = PdfWriter.RUN_DIRECTION_RTL, Phrase = new Phrase(FixWeakCharacters("نوع بستهبندی: "), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER, FixedHeight = cellHeight }); checkListTb.AddCell(new PdfPCell() { RunDirection = PdfWriter.RUN_DIRECTION_RTL, Phrase = new Phrase(FixWeakCharacters("شماره گواهینامه راننده: "), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER, FixedHeight = cellHeight }); checkListTb.AddCell(new PdfPCell() { RunDirection = PdfWriter.RUN_DIRECTION_RTL, Phrase = new Phrase(FixWeakCharacters("وسیله حمل: "), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER, FixedHeight = cellHeight }); checkListTb.AddCell(new PdfPCell() { RunDirection = PdfWriter.RUN_DIRECTION_RTL, Phrase = new Phrase(FixWeakCharacters("شماره شهربانی: "), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER, FixedHeight = cellHeight }); checkListTb.AddCell(new PdfPCell() { RunDirection = PdfWriter.RUN_DIRECTION_RTL, Phrase = new Phrase(FixWeakCharacters("مسیر حرکت: "), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER, FixedHeight = cellHeight }); checkListTb.AddCell(new PdfPCell() { RunDirection = PdfWriter.RUN_DIRECTION_RTL, Phrase = new Phrase(FixWeakCharacters("محل بارگیری: "), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER, FixedHeight = cellHeight }); CustomDashedLineSeparator separator = new CustomDashedLineSeparator(); separator.SetDash(100); separator.Gap = 7; separator.LineWidth = 3; separator.Percentage = 100f; Chunk linebreak = new Chunk(separator); checkListTb.AddCell(new PdfPCell() { FixedHeight = 10, Colspan = 2, Border = Rectangle.NO_BORDER }); PdfContentByte cb = pdfWriter.DirectContent; cb.SetLineDash(3f, 3f); cb.MoveTo(30, pdfDoc.PageSize.Height / 3); cb.LineTo(pdfDoc.PageSize.Width - 30, pdfDoc.PageSize.Height / 3); cb.Stroke(); checkListTb.AddCell(new PdfPCell() { FixedHeight = 10, Colspan = 2, Border = Rectangle.NO_BORDER }); checkListTb.AddCell(new PdfPCell() { RunDirection = PdfWriter.RUN_DIRECTION_RTL, Phrase = new Phrase(FixWeakCharacters("شماره بارنامه: "), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER, FixedHeight = cellHeight }); checkListTb.AddCell(new PdfPCell() { RunDirection = PdfWriter.RUN_DIRECTION_RTL, Phrase = new Phrase(FixWeakCharacters("تاریخ صدور بارنامه: "), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER, FixedHeight = cellHeight }); checkListTb.AddCell(new PdfPCell() { RunDirection = PdfWriter.RUN_DIRECTION_RTL, Phrase = new Phrase(FixWeakCharacters("مبداء: "), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER, FixedHeight = cellHeight }); checkListTb.AddCell(new PdfPCell() { RunDirection = PdfWriter.RUN_DIRECTION_RTL, Phrase = new Phrase(FixWeakCharacters("مقصد: "), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER, FixedHeight = cellHeight }); checkListTb.AddCell(new PdfPCell() { RunDirection = PdfWriter.RUN_DIRECTION_RTL, Phrase = new Phrase(FixWeakCharacters("ساعت حرکت: "), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER, FixedHeight = cellHeight }); checkListTb.AddCell(new PdfPCell() { RunDirection = PdfWriter.RUN_DIRECTION_RTL, Phrase = new Phrase(FixWeakCharacters("ارزش کالا (طبق اظهار بیمهگذار): "), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER, FixedHeight = cellHeight }); checkListTb.AddCell(new PdfPCell() { RunDirection = PdfWriter.RUN_DIRECTION_RTL, Phrase = new Phrase(FixWeakCharacters("آدرس و تلفن راننده: "), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Colspan = 2, Border = Rectangle.NO_BORDER, FixedHeight = cellHeight }); checkListTb.AddCell(new PdfPCell() { RunDirection = PdfWriter.RUN_DIRECTION_RTL, Phrase = new Phrase(FixWeakCharacters("صحت و سلامت محموله تایید میگردد / تایید نمیگردد. "), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Colspan = 2, Border = Rectangle.NO_BORDER, FixedHeight = cellHeight }); checkListTb.AddCell(new PdfPCell() { RunDirection = PdfWriter.RUN_DIRECTION_RTL, Phrase = new Phrase(FixWeakCharacters("محل درج امضاء: "), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Colspan = 2, Border = Rectangle.NO_BORDER, FixedHeight = cellHeight }); checkListTb.AddCell(new PdfPCell() { RunDirection = PdfWriter.RUN_DIRECTION_RTL, Phrase = new Phrase( FixWeakCharacters("مراقبت فوق تایید میگردد." + Environment.NewLine + "امضاء فرستنده یا متصدی حمل"), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER, FixedHeight = cellHeight }); checkListTb.AddCell(new PdfPCell() { RunDirection = PdfWriter.RUN_DIRECTION_RTL, Phrase = new Phrase( FixWeakCharacters("مراقبت فوق تایید میگردد." + Environment.NewLine + "امضاء راننده"), _myFont), Padding = 5, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER, FixedHeight = cellHeight }); #endregion pdfDoc.Add(headerTb); pdfDoc.Add(matnTb); pdfDoc.Add(checkListTb); iTextSharp.text.Image wattermarkImg = iTextSharp.text.Image.GetInstance("EppadCo.jpg"); wattermarkImg.SetAbsolutePosition(pdfDoc.PageSize.Left + 30, pdfDoc.PageSize.Bottom + 30); pdfDoc.Add(wattermarkImg); } Process.Start("Test.pdf"); }
public void ReadAll() { if (meta.ReadInt() != unchecked ((int)0x9AC6CDD7)) { throw new DocumentException(MessageLocalization.GetComposedMessage("not.a.placeable.windows.metafile")); } meta.ReadWord(); left = meta.ReadShort(); top = meta.ReadShort(); right = meta.ReadShort(); bottom = meta.ReadShort(); inch = meta.ReadWord(); state.ScalingX = (float)(right - left) / (float)inch * 72f; state.ScalingY = (float)(bottom - top) / (float)inch * 72f; state.OffsetWx = left; state.OffsetWy = top; state.ExtentWx = right - left; state.ExtentWy = bottom - top; meta.ReadInt(); meta.ReadWord(); meta.Skip(18); int tsize; int function; cb.SetLineCap(1); cb.SetLineJoin(1); for (;;) { int lenMarker = meta.Length; tsize = meta.ReadInt(); if (tsize < 3) { break; } function = meta.ReadWord(); switch (function) { case 0: break; case META_CREATEPALETTE: case META_CREATEREGION: case META_DIBCREATEPATTERNBRUSH: state.AddMetaObject(new MetaObject()); break; case META_CREATEPENINDIRECT: { MetaPen pen = new MetaPen(); pen.Init(meta); state.AddMetaObject(pen); break; } case META_CREATEBRUSHINDIRECT: { MetaBrush brush = new MetaBrush(); brush.Init(meta); state.AddMetaObject(brush); break; } case META_CREATEFONTINDIRECT: { MetaFont font = new MetaFont(); font.Init(meta); state.AddMetaObject(font); break; } case META_SELECTOBJECT: { int idx = meta.ReadWord(); state.SelectMetaObject(idx, cb); break; } case META_DELETEOBJECT: { int idx = meta.ReadWord(); state.DeleteMetaObject(idx); break; } case META_SAVEDC: state.SaveState(cb); break; case META_RESTOREDC: { int idx = meta.ReadShort(); state.RestoreState(idx, cb); break; } case META_SETWINDOWORG: state.OffsetWy = meta.ReadShort(); state.OffsetWx = meta.ReadShort(); break; case META_SETWINDOWEXT: state.ExtentWy = meta.ReadShort(); state.ExtentWx = meta.ReadShort(); break; case META_MOVETO: { int y = meta.ReadShort(); System.Drawing.Point p = new System.Drawing.Point(meta.ReadShort(), y); state.CurrentPoint = p; break; } case META_LINETO: { int y = meta.ReadShort(); int x = meta.ReadShort(); System.Drawing.Point p = state.CurrentPoint; cb.MoveTo(state.TransformX(p.X), state.TransformY(p.Y)); cb.LineTo(state.TransformX(x), state.TransformY(y)); cb.Stroke(); state.CurrentPoint = new System.Drawing.Point(x, y); break; } case META_POLYLINE: { state.LineJoinPolygon = cb; int len = meta.ReadWord(); int x = meta.ReadShort(); int y = meta.ReadShort(); cb.MoveTo(state.TransformX(x), state.TransformY(y)); for (int k = 1; k < len; ++k) { x = meta.ReadShort(); y = meta.ReadShort(); cb.LineTo(state.TransformX(x), state.TransformY(y)); } cb.Stroke(); break; } case META_POLYGON: { if (IsNullStrokeFill(false)) { break; } int len = meta.ReadWord(); int sx = meta.ReadShort(); int sy = meta.ReadShort(); cb.MoveTo(state.TransformX(sx), state.TransformY(sy)); for (int k = 1; k < len; ++k) { int x = meta.ReadShort(); int y = meta.ReadShort(); cb.LineTo(state.TransformX(x), state.TransformY(y)); } cb.LineTo(state.TransformX(sx), state.TransformY(sy)); StrokeAndFill(); break; } case META_POLYPOLYGON: { if (IsNullStrokeFill(false)) { break; } int numPoly = meta.ReadWord(); int[] lens = new int[numPoly]; for (int k = 0; k < lens.Length; ++k) { lens[k] = meta.ReadWord(); } for (int j = 0; j < lens.Length; ++j) { int len = lens[j]; int sx = meta.ReadShort(); int sy = meta.ReadShort(); cb.MoveTo(state.TransformX(sx), state.TransformY(sy)); for (int k = 1; k < len; ++k) { int x = meta.ReadShort(); int y = meta.ReadShort(); cb.LineTo(state.TransformX(x), state.TransformY(y)); } cb.LineTo(state.TransformX(sx), state.TransformY(sy)); } StrokeAndFill(); break; } case META_ELLIPSE: { if (IsNullStrokeFill(state.LineNeutral)) { break; } int b = meta.ReadShort(); int r = meta.ReadShort(); int t = meta.ReadShort(); int l = meta.ReadShort(); cb.Arc(state.TransformX(l), state.TransformY(b), state.TransformX(r), state.TransformY(t), 0, 360); StrokeAndFill(); break; } case META_ARC: { if (IsNullStrokeFill(state.LineNeutral)) { break; } float yend = state.TransformY(meta.ReadShort()); float xend = state.TransformX(meta.ReadShort()); float ystart = state.TransformY(meta.ReadShort()); float xstart = state.TransformX(meta.ReadShort()); float b = state.TransformY(meta.ReadShort()); float r = state.TransformX(meta.ReadShort()); float t = state.TransformY(meta.ReadShort()); float l = state.TransformX(meta.ReadShort()); float cx = (r + l) / 2; float cy = (t + b) / 2; float arc1 = GetArc(cx, cy, xstart, ystart); float arc2 = GetArc(cx, cy, xend, yend); arc2 -= arc1; if (arc2 <= 0) { arc2 += 360; } cb.Arc(l, b, r, t, arc1, arc2); cb.Stroke(); break; } case META_PIE: { if (IsNullStrokeFill(state.LineNeutral)) { break; } float yend = state.TransformY(meta.ReadShort()); float xend = state.TransformX(meta.ReadShort()); float ystart = state.TransformY(meta.ReadShort()); float xstart = state.TransformX(meta.ReadShort()); float b = state.TransformY(meta.ReadShort()); float r = state.TransformX(meta.ReadShort()); float t = state.TransformY(meta.ReadShort()); float l = state.TransformX(meta.ReadShort()); float cx = (r + l) / 2; float cy = (t + b) / 2; float arc1 = GetArc(cx, cy, xstart, ystart); float arc2 = GetArc(cx, cy, xend, yend); arc2 -= arc1; if (arc2 <= 0) { arc2 += 360; } List <float[]> ar = PdfContentByte.BezierArc(l, b, r, t, arc1, arc2); if (ar.Count == 0) { break; } float[] pt = ar[0]; cb.MoveTo(cx, cy); cb.LineTo(pt[0], pt[1]); for (int k = 0; k < ar.Count; ++k) { pt = ar[k]; cb.CurveTo(pt[2], pt[3], pt[4], pt[5], pt[6], pt[7]); } cb.LineTo(cx, cy); StrokeAndFill(); break; } case META_CHORD: { if (IsNullStrokeFill(state.LineNeutral)) { break; } float yend = state.TransformY(meta.ReadShort()); float xend = state.TransformX(meta.ReadShort()); float ystart = state.TransformY(meta.ReadShort()); float xstart = state.TransformX(meta.ReadShort()); float b = state.TransformY(meta.ReadShort()); float r = state.TransformX(meta.ReadShort()); float t = state.TransformY(meta.ReadShort()); float l = state.TransformX(meta.ReadShort()); float cx = (r + l) / 2; float cy = (t + b) / 2; float arc1 = GetArc(cx, cy, xstart, ystart); float arc2 = GetArc(cx, cy, xend, yend); arc2 -= arc1; if (arc2 <= 0) { arc2 += 360; } List <float[]> ar = PdfContentByte.BezierArc(l, b, r, t, arc1, arc2); if (ar.Count == 0) { break; } float[] pt = ar[0]; cx = pt[0]; cy = pt[1]; cb.MoveTo(cx, cy); for (int k = 0; k < ar.Count; ++k) { pt = ar[k]; cb.CurveTo(pt[2], pt[3], pt[4], pt[5], pt[6], pt[7]); } cb.LineTo(cx, cy); StrokeAndFill(); break; } case META_RECTANGLE: { if (IsNullStrokeFill(true)) { break; } float b = state.TransformY(meta.ReadShort()); float r = state.TransformX(meta.ReadShort()); float t = state.TransformY(meta.ReadShort()); float l = state.TransformX(meta.ReadShort()); cb.Rectangle(l, b, r - l, t - b); StrokeAndFill(); break; } case META_ROUNDRECT: { if (IsNullStrokeFill(true)) { break; } float h = state.TransformY(0) - state.TransformY(meta.ReadShort()); float w = state.TransformX(meta.ReadShort()) - state.TransformX(0); float b = state.TransformY(meta.ReadShort()); float r = state.TransformX(meta.ReadShort()); float t = state.TransformY(meta.ReadShort()); float l = state.TransformX(meta.ReadShort()); cb.RoundRectangle(l, b, r - l, t - b, (h + w) / 4); StrokeAndFill(); break; } case META_INTERSECTCLIPRECT: { float b = state.TransformY(meta.ReadShort()); float r = state.TransformX(meta.ReadShort()); float t = state.TransformY(meta.ReadShort()); float l = state.TransformX(meta.ReadShort()); cb.Rectangle(l, b, r - l, t - b); cb.EoClip(); cb.NewPath(); break; } case META_EXTTEXTOUT: { int y = meta.ReadShort(); int x = meta.ReadShort(); int count = meta.ReadWord(); int flag = meta.ReadWord(); int x1 = 0; int y1 = 0; int x2 = 0; int y2 = 0; if ((flag & (MetaFont.ETO_CLIPPED | MetaFont.ETO_OPAQUE)) != 0) { x1 = meta.ReadShort(); y1 = meta.ReadShort(); x2 = meta.ReadShort(); y2 = meta.ReadShort(); } byte[] text = new byte[count]; int k; for (k = 0; k < count; ++k) { byte c = (byte)meta.ReadByte(); if (c == 0) { break; } text[k] = c; } string s; try { s = System.Text.Encoding.GetEncoding(1252).GetString(text, 0, k); } catch { s = System.Text.ASCIIEncoding.ASCII.GetString(text, 0, k); } OutputText(x, y, flag, x1, y1, x2, y2, s); break; } case META_TEXTOUT: { int count = meta.ReadWord(); byte[] text = new byte[count]; int k; for (k = 0; k < count; ++k) { byte c = (byte)meta.ReadByte(); if (c == 0) { break; } text[k] = c; } string s; try { s = System.Text.Encoding.GetEncoding(1252).GetString(text, 0, k); } catch { s = System.Text.ASCIIEncoding.ASCII.GetString(text, 0, k); } count = (count + 1) & 0xfffe; meta.Skip(count - k); int y = meta.ReadShort(); int x = meta.ReadShort(); OutputText(x, y, 0, 0, 0, 0, 0, s); break; } case META_SETBKCOLOR: state.CurrentBackgroundColor = meta.ReadColor(); break; case META_SETTEXTCOLOR: state.CurrentTextColor = meta.ReadColor(); break; case META_SETTEXTALIGN: state.TextAlign = meta.ReadWord(); break; case META_SETBKMODE: state.BackgroundMode = meta.ReadWord(); break; case META_SETPOLYFILLMODE: state.PolyFillMode = meta.ReadWord(); break; case META_SETPIXEL: { BaseColor color = meta.ReadColor(); int y = meta.ReadShort(); int x = meta.ReadShort(); cb.SaveState(); cb.SetColorFill(color); cb.Rectangle(state.TransformX(x), state.TransformY(y), .2f, .2f); cb.Fill(); cb.RestoreState(); break; } case META_DIBSTRETCHBLT: case META_STRETCHDIB: { int rop = meta.ReadInt(); if (function == META_STRETCHDIB) { /*int usage = */ meta.ReadWord(); } int srcHeight = meta.ReadShort(); int srcWidth = meta.ReadShort(); int ySrc = meta.ReadShort(); int xSrc = meta.ReadShort(); float destHeight = state.TransformY(meta.ReadShort()) - state.TransformY(0); float destWidth = state.TransformX(meta.ReadShort()) - state.TransformX(0); float yDest = state.TransformY(meta.ReadShort()); float xDest = state.TransformX(meta.ReadShort()); byte[] b = new byte[(tsize * 2) - (meta.Length - lenMarker)]; for (int k = 0; k < b.Length; ++k) { b[k] = (byte)meta.ReadByte(); } try { MemoryStream inb = new MemoryStream(b); Image bmp = BmpImage.GetImage(inb, true, b.Length); cb.SaveState(); cb.Rectangle(xDest, yDest, destWidth, destHeight); cb.Clip(); cb.NewPath(); bmp.ScaleAbsolute(destWidth * bmp.Width / srcWidth, -destHeight * bmp.Height / srcHeight); bmp.SetAbsolutePosition(xDest - destWidth * xSrc / srcWidth, yDest + destHeight * ySrc / srcHeight - bmp.ScaledHeight); cb.AddImage(bmp); cb.RestoreState(); } catch { // empty on purpose } break; } } meta.Skip((tsize * 2) - (meta.Length - lenMarker)); } state.Cleanup(cb); }
public static void DrawPieChart(this PdfContentByte canvas, PieChart chart, float x0, float y0, float r = 50f, Font font = null, bool showCaption = true) { if (chart.Values.Length != chart.Captions.Length) { return; } if (font == null) { font = FontFactory.GetFont(FontFactory.TIMES, 8); } canvas.SetLineWidth(0f); double _x1, _y1, _x2, _y2; float x1, y1, x2, y2; canvas.SetLineWidth(1f); float cRadius = (float)(r + 0.5); canvas.Circle(x0, y0, cRadius); canvas.SetColorStroke(BaseColor.GRAY); canvas.Stroke(); canvas.SetLineWidth(0f); float rectX1 = x0 - r; float rectY1 = y0 - r; float xPoint = x0 + r; float yPoint = y0 + r; //canvas.Rectangle(rectX1, rectY1, 2 * r, 2 * r); //canvas.Stroke(); double _startAngle = 0; double _endAngle = 0; float startAngle = 0; float endAngle = 0; float captionY = y0 + (chart.Values.Length - 1) * 6; double _percentage; string percentage; for (int counter = 0; counter < chart.Values.Length; counter++) { if (chart.TotalValues > 0) { _percentage = chart.Angles[counter] * 100 / 360; } else { _percentage = 0; } if (showCaption) { //captions from here canvas.SetColorStroke(chart.ChartColors[counter]); canvas.SetColorFill(chart.ChartColors[counter]); canvas.Rectangle(x0 + r + 10, captionY, 7, 7); canvas.ClosePathFillStroke(); percentage = string.Format("{0:N}", _percentage); ColumnText text2 = new ColumnText(canvas); Phrase phrase = new Phrase(string.Format("{0} ({1}%)", chart.Captions[counter], percentage), font); text2.SetSimpleColumn(phrase, x0 + r + 20, captionY, x0 + r + 200, captionY, 0f, 0); text2.Go(); captionY -= 12; if (_percentage == 0) { continue; } //end of caption } if (chart.TotalValues <= 0) { continue; } if (_percentage <= 50) { //get coordinate on circle _x1 = x0 + r * Math.Cos(_startAngle * Math.PI / 180); _y1 = y0 + r * Math.Sin(_startAngle * Math.PI / 180); x1 = (float)_x1; y1 = (float)_y1; _endAngle += chart.Angles[counter]; _x2 = x0 + r * Math.Cos(_endAngle * Math.PI / 180); _y2 = y0 + r * Math.Sin(_endAngle * Math.PI / 180); x2 = (float)_x2; y2 = (float)_y2; startAngle = (float)_startAngle; endAngle = (float)_endAngle; //set the colors to be used canvas.SetColorStroke(chart.ChartColors[counter]); canvas.SetColorFill(chart.ChartColors[counter]); //draw the triangle within the circle canvas.MoveTo(x0, y0); canvas.LineTo(x1, y1); canvas.LineTo(x2, y2); canvas.LineTo(x0, y0); canvas.ClosePathFillStroke(); //draw the arc canvas.Arc(rectX1, rectY1, xPoint, yPoint, startAngle, (float)chart.Angles[counter]); canvas.ClosePathFillStroke(); _startAngle += chart.Angles[counter]; } else { //DO THE FIRST PART //get coordinate on circle _x1 = x0 + r * Math.Cos(_startAngle * Math.PI / 180); _y1 = y0 + r * Math.Sin(_startAngle * Math.PI / 180); x1 = (float)_x1; y1 = (float)_y1; _endAngle += 180; _x2 = x0 + r * Math.Cos(_endAngle * Math.PI / 180); _y2 = y0 + r * Math.Sin(_endAngle * Math.PI / 180); x2 = (float)_x2; y2 = (float)_y2; startAngle = (float)_startAngle; endAngle = (float)_endAngle; //set the colors to be used canvas.SetColorStroke(chart.ChartColors[counter]); canvas.SetColorFill(chart.ChartColors[counter]); //draw the triangle within the circle canvas.MoveTo(x0, y0); canvas.LineTo(x1, y1); canvas.LineTo(x2, y2); canvas.LineTo(x0, y0); canvas.ClosePathFillStroke(); //draw the arc canvas.Arc(rectX1, rectY1, xPoint, yPoint, startAngle, 180); canvas.ClosePathFillStroke(); //DO THE SECOND PART //get coordinate on circle _x1 = x0 + r * Math.Cos((_startAngle + 180) * Math.PI / 180); _y1 = y0 + r * Math.Sin((_startAngle + 180) * Math.PI / 180); x1 = (float)_x1; y1 = (float)_y1; _endAngle += chart.Angles[counter] - 180; _x2 = x0 + r * Math.Cos(_endAngle * Math.PI / 180); _y2 = y0 + r * Math.Sin(_endAngle * Math.PI / 180); x2 = (float)_x2; y2 = (float)_y2; startAngle = (float)_startAngle; endAngle = (float)_endAngle; //set the colors to be used canvas.SetColorStroke(chart.ChartColors[counter]); canvas.SetColorFill(chart.ChartColors[counter]); //draw the triangle within the circle canvas.MoveTo(x0, y0); canvas.LineTo(x1, y1); canvas.LineTo(x2, y2); canvas.LineTo(x0, y0); canvas.ClosePathFillStroke(); //draw the arc canvas.Arc(rectX1, rectY1, xPoint, yPoint, startAngle + 180, (float)(chart.Angles[counter] - 180)); canvas.ClosePathFillStroke(); _startAngle += chart.Angles[counter]; } } }
protected void btnOmitir_Click(object sender, EventArgs e) { // Creamos el documento con el tamaño de página tradicional Document doc = new Document(PageSize.LETTER); // Indicamos donde vamos a guardar el documento string mdoc = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); // PdfWriter writer = PdfWriter.GetInstance(doc, // new FileStream(@"C:\Users\edu08\Downloads\prueba.pdf", FileMode.Create)); PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(@"C:\Users\Public\Downloads\prueba.pdf", FileMode.Create)); // Le colocamos el título y el autor // **Nota: Esto no será visible en el documento doc.AddTitle("Detalles de Reserva"); doc.AddCreator("STS"); // Abrimos el archivo doc.Open(); // Creamos el tipo de Font que vamos utilizar iTextSharp.text.Font _standardFont = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK); // Escribimos el encabezamiento en el documento Font fuenteT = new Font(); fuenteT.Size = 18; fuenteT.SetStyle(Font.BOLD | Font.UNDERLINE); doc.Add(new Paragraph("Detalles de Reserva", fuenteT)); doc.Add(Chunk.NEWLINE); doc.Add(Chunk.NEWLINE); //imagen string imageURL = Server.MapPath(".") + "/ccss/star-1-3/Static HTML/img/logo-dark.png"; iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(imageURL); img.ScaleToFit(125f, 60F); //Imagen - Movio en el eje de las Y img.SetAbsolutePosition(500, 750); doc.Add(img); // Creamos una tabla que contendrá el nombre, apellido y país // de nuestros visitante. PdfPTable tblPrueba = new PdfPTable(2); tblPrueba.WidthPercentage = 100; // Configuramos el título de las columnas de la tabla Font fuente = new Font(); fuente.Size = 15; fuente.SetStyle(Font.BOLD); PdfPCell clNombre = new PdfPCell(new Phrase("Alumno(a): ", fuente)); clNombre.BorderWidth = 0; clNombre.HorizontalAlignment = PdfPCell.ALIGN_CENTER; //clNombre.BorderWidthBottom = 0.75f; Font fuente2 = new Font(); fuente2.Size = 15; PdfPCell clApellido = new PdfPCell(new Phrase("", fuente2)); clApellido.BorderWidth = 0; clApellido.PaddingLeft = 30; //clApellido.BorderWidthBottom = 0.75f; // Añadimos las celdas a la tabla tblPrueba.AddCell(clNombre); tblPrueba.AddCell(clApellido); // Llenamos la tabla con información clNombre = new PdfPCell(new Phrase("Escuela: ", fuente)); clNombre.BorderWidth = 0; clNombre.HorizontalAlignment = PdfPCell.ALIGN_CENTER; // clNombre.HorizontalAlignment = PdfPCell.ALIGN_RIGHT; // clApellido = new PdfPCell(new Phrase("", fuente2)); clApellido.BorderWidth = 0; clApellido.PaddingLeft = 30; // Añadimos las celdas a la tabla tblPrueba.AddCell(clNombre); tblPrueba.AddCell(clApellido); // Llenamos la tabla con información clNombre = new PdfPCell(new Phrase("Nivel: ", fuente)); clNombre.BorderWidth = 0; clNombre.HorizontalAlignment = PdfPCell.ALIGN_CENTER; //clNombre.HorizontalAlignment = PdfPCell.ALIGN_RIGHT; tblPrueba.AddCell(clNombre); //Dato clApellido = new PdfPCell(new Phrase("", fuente2)); clApellido.BorderWidth = 0; clApellido.PaddingLeft = 30; tblPrueba.AddCell(clApellido); // Llenamos la tabla con información clNombre = new PdfPCell(new Phrase("Fecha: ", fuente)); clNombre.BorderWidth = 0; clNombre.HorizontalAlignment = PdfPCell.ALIGN_CENTER; // clNombre.HorizontalAlignment = PdfPCell.ALIGN_RIGHT; tblPrueba.AddCell(clNombre); //Dato clApellido = new PdfPCell(new Phrase("", fuente2)); clApellido.BorderWidth = 0; clApellido.PaddingLeft = 30; tblPrueba.AddCell(clApellido); // Llenamos la tabla con información clNombre = new PdfPCell(new Phrase("Hora: ", fuente)); clNombre.BorderWidth = 0; clNombre.HorizontalAlignment = PdfPCell.ALIGN_CENTER; // clNombre.HorizontalAlignment = PdfPCell.ALIGN_RIGHT; tblPrueba.AddCell(clNombre); //Dato clApellido = new PdfPCell(new Phrase("", fuente2)); clApellido.BorderWidth = 0; clApellido.PaddingLeft = 30; tblPrueba.AddCell(clApellido); // Llenamos la tabla con información clNombre = new PdfPCell(new Phrase("Instructor: ", fuente)); clNombre.BorderWidth = 0; clNombre.HorizontalAlignment = PdfPCell.ALIGN_CENTER; // clNombre.HorizontalAlignment = PdfPCell.ALIGN_RIGHT; tblPrueba.AddCell(clNombre); //Dato clApellido = new PdfPCell(new Phrase("", fuente2)); clApellido.BorderWidth = 0; clApellido.PaddingLeft = 30; tblPrueba.AddCell(clApellido); // Llenamos la tabla con información clNombre = new PdfPCell(new Phrase("Indumentaria: ", fuente)); clNombre.BorderWidth = 0; clNombre.HorizontalAlignment = PdfPCell.ALIGN_CENTER; // clNombre.HorizontalAlignment = PdfPCell.ALIGN_RIGHT; tblPrueba.AddCell(clNombre); //Dato clApellido = new PdfPCell(new Phrase("", fuente2)); clApellido.BorderWidth = 0; clApellido.PaddingLeft = 30; tblPrueba.AddCell(clApellido); // Llenamos la tabla con información clNombre = new PdfPCell(new Phrase("Ubicación: ", fuente)); clNombre.BorderWidth = 0; clNombre.HorizontalAlignment = PdfPCell.ALIGN_CENTER; // clNombre.HorizontalAlignment = PdfPCell.ALIGN_RIGHT; tblPrueba.AddCell(clNombre); //Dato clApellido = new PdfPCell(new Phrase("", fuente2)); clApellido.BorderWidth = 0; clApellido.PaddingLeft = 30; tblPrueba.AddCell(clApellido); // Finalmente, añadimos la tabla al documento PDF y cerramos el documento doc.Add(tblPrueba); //linea PdfContentByte cb = writer.DirectContent; cb.MoveTo(10, doc.Top - 280f); cb.LineTo(600, doc.Top - 280f); cb.Stroke(); // Font fuente4 = new Font(); fuente4.Size = 10; //tabla precio PdfPTable tblPrecio = new PdfPTable(2); tblPrueba.WidthPercentage = 50; // PdfPCell cldetalle = new PdfPCell(new Phrase("Lecciones: ", fuente4)); cldetalle.BorderWidth = 0; cldetalle.HorizontalAlignment = PdfPCell.ALIGN_RIGHT; // doc.Close(); writer.Close(); Response.ContentType = "application/pdf"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.AppendHeader("content-disposition", "attachment;filename=TestPage.pdf"); // Response.TransmitFile("C:/Users/edu08/Downloads/prueba.pdf"); Response.TransmitFile("C:/Users/Public/Downloads/prueba.pdf"); Response.End(); }
public override void OnEndPage(PdfWriter writer, Document document) { base.OnEndPage(writer, document); String textoPaginacao = writer.PageNumber + " / "; #region Adicionando pagina no cabeçalho if (_documentOptions.ShowPagingOnTop) { { cb.BeginText(); cb.SetFontAndSize(bf, 8f); cb.SetTextMatrix(document.PageSize.GetRight(60), document.PageSize.GetTop(55)); cb.ShowText(textoPaginacao); cb.EndText(); float len = bf.GetWidthPoint(textoPaginacao, 8f); //Adds "12" in Page 1 of 12 cb.AddTemplate(headerTemplate, document.PageSize.GetRight(60) + len, document.PageSize.GetTop(55)); } } #endregion #region Adicionando pagina do rodapé if (_documentOptions.ShowPagingOnBottom) { { cb.BeginText(); cb.SetFontAndSize(bf, 8f); cb.SetTextMatrix(document.PageSize.GetRight(100), document.PageSize.GetBottom(30)); cb.ShowText(textoPaginacao); cb.EndText(); float len = bf.GetWidthPoint(textoPaginacao, 8f); #region texto do rodapé if (_documentOptions.FooterOptions.ShowFooterText) { Paragraph paragrafoRodape1 = new Paragraph(new Chunk("Fundação para o Desenvolvimento da Educação", FontFactory.GetFont("Arial", 7f, Font.BOLD, BaseColor.BLACK))); Paragraph paragrafoRodape2 = new Paragraph(new Chunk("Avenida São Luís, 99 - República 01046-001 Tel. (11) 3158-4000", FontFactory.GetFont("Arial", 7f, Font.NORMAL, BaseColor.BLACK))); Paragraph paragrafoRodape3 = new Paragraph(new Chunk("www.fde.sp.gov.br", FontFactory.GetFont("Arial", 6f, Font.NORMAL, BaseColor.BLACK)).SetAnchor("http://www.fde.sp.gov.br/")); float dimInit = 35; ColumnText columnTextRodape1 = new ColumnText(cb); columnTextRodape1.AddText(paragrafoRodape1); if (_documentOptions.PageOrientation == PdfPageOrientation.Retrato) { columnTextRodape1.SetSimpleColumn(590, dimInit, 0, 0, 0, Element.ALIGN_CENTER); } else { columnTextRodape1.SetSimpleColumn(890, dimInit, 0, 0, 0, Element.ALIGN_CENTER); } columnTextRodape1.Go(); ColumnText columnTextRodape2 = new ColumnText(cb); columnTextRodape2.AddText(paragrafoRodape2); if (_documentOptions.PageOrientation == PdfPageOrientation.Retrato) { columnTextRodape2.SetSimpleColumn(590, (dimInit - 10f), 5, 0, 0, Element.ALIGN_CENTER); } else { columnTextRodape2.SetSimpleColumn(890, (dimInit - 10f), 5, 0, 0, Element.ALIGN_CENTER); } columnTextRodape2.Go(); ColumnText columnTextRodape3 = new ColumnText(cb); columnTextRodape3.AddText(paragrafoRodape3); if (_documentOptions.PageOrientation == PdfPageOrientation.Retrato) { columnTextRodape3.SetSimpleColumn(590, (dimInit - 20f), 0, 0, 0, Element.ALIGN_CENTER); } else { columnTextRodape3.SetSimpleColumn(890, (dimInit - 20f), 0, 0, 0, Element.ALIGN_CENTER); } columnTextRodape3.Go(); } #endregion cb.AddTemplate(footerTemplate, document.PageSize.GetRight(100) + len, document.PageSize.GetBottom(30)); } } #endregion #region Cabeçalho if (_documentOptions.ShowHeader) { float _HeaderHeight = 65f; PdfPTable tableHeader = new PdfPTable(1); tableHeader.WidthPercentage = 95f; tableHeader.DefaultCell.FixedHeight = 20f; tableHeader.TotalWidth = document.PageSize.Width - 80f; PdfPCell cellHeader = new PdfPCell(); cellHeader.Border = PdfPCell.NO_BORDER; cellHeader.FixedHeight = _HeaderHeight; // Retrato if (_documentOptions.PageOrientation == PdfPageOrientation.Retrato) { Paragraph paragrafoCabecalho1 = new Paragraph(new Chunk(_documentOptions.HeaderOptions?.HeaderTitleText, FontFactory.GetFont("Arial", 12f, Font.BOLD, BaseColor.BLACK))); Paragraph paragrafoCabecalho2 = new Paragraph(new Chunk(_documentOptions.HeaderOptions?.HeaderSubtitleText, FontFactory.GetFont("Arial", 9f, Font.BOLD, BaseColor.BLACK))); ColumnText columnTextCabecalho1 = new ColumnText(cb); columnTextCabecalho1.AddText(paragrafoCabecalho1); columnTextCabecalho1.SetSimpleColumn(34, 815, 540, 217, 10, Element.ALIGN_CENTER); columnTextCabecalho1.Go(); ColumnText columnTextCabecalho2 = new ColumnText(cb); columnTextCabecalho2.AddText(paragrafoCabecalho2); columnTextCabecalho2.SetSimpleColumn(34, 800, 540, 217, 10, Element.ALIGN_CENTER); columnTextCabecalho2.Go(); #region Imagem LOGO LEFT if (_documentOptions.HeaderOptions != null && _documentOptions.HeaderOptions.HeaderImageLeft != null) { MemoryStream mst = new MemoryStream(); _documentOptions.HeaderOptions.HeaderImageLeft.Save(mst, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] b = mst.ToArray(); //posicionando a imagem no arquivo iTextSharp.text.Image imageLogo = iTextSharp.text.Image.GetInstance(b); imageLogo.SetAbsolutePosition(document.PageSize.Width - 580f, document.PageSize.Height - 46f); imageLogo.ScalePercent(52f); document.Add(imageLogo); } #endregion #region Imagem LOGO RIGHT if (_documentOptions.HeaderOptions != null && _documentOptions.HeaderOptions.ShowImageRight && _documentOptions.HeaderOptions.HeaderImageRight != null) { MemoryStream mst = new MemoryStream(); _documentOptions.HeaderOptions.HeaderImageRight.Save(mst, System.Drawing.Imaging.ImageFormat.Png); byte[] b = mst.ToArray(); //posicionando a imagem no arquivo iTextSharp.text.Image imageLogo = iTextSharp.text.Image.GetInstance(b); imageLogo.SetAbsolutePosition(document.PageSize.Width - 125f, document.PageSize.Height - 46f); imageLogo.ScalePercent(35f); document.Add(imageLogo); } #endregion #region Data de impressão if (_documentOptions.ShowPrintDateTime) { Chunk chunkDataImpressaoText = new Chunk("Data de impressão: ", FontFactory.GetFont("Arial", 8f, Font.BOLD, BaseColor.BLACK)); Phrase phraseDataImpressaoText = new Phrase(); phraseDataImpressaoText.Add(chunkDataImpressaoText); Chunk chunkDataImpressaoData = new Chunk(PrintDateTime.ToString(), FontFactory.GetFont("Arial", 8f, BaseColor.BLACK)); Phrase phraseDataImpressaoData = new Phrase(); phraseDataImpressaoData.Add(chunkDataImpressaoData); Paragraph paragrafoTextDataImpressao = new Paragraph(); paragrafoTextDataImpressao.Add(chunkDataImpressaoText); paragrafoTextDataImpressao.Add(chunkDataImpressaoData); ColumnText columnTextDataImpressao = new ColumnText(cb); columnTextDataImpressao.AddText(paragrafoTextDataImpressao); columnTextDataImpressao.SetSimpleColumn(334, 775, 540, 217, 10, Element.ALIGN_RIGHT); columnTextDataImpressao.Go(); } #endregion tableHeader.AddCell(cellHeader); } else // Paisagem { Paragraph paragrafoCabecalho1 = new Paragraph(new Chunk(_documentOptions.HeaderOptions?.HeaderTitleText, FontFactory.GetFont("Arial", 12f, Font.BOLD, BaseColor.BLACK))); Paragraph paragrafoCabecalho2 = new Paragraph(new Chunk(_documentOptions.HeaderOptions?.HeaderSubtitleText, FontFactory.GetFont("Arial", 9f, Font.BOLD, BaseColor.BLACK))); ColumnText columnTextCabecalho1 = new ColumnText(cb); columnTextCabecalho1.AddText(paragrafoCabecalho1); columnTextCabecalho1.SetSimpleColumn(790, 578, 10, 0, 10, Element.ALIGN_CENTER); columnTextCabecalho1.Go(); ColumnText columnTextCabecalho2 = new ColumnText(cb); columnTextCabecalho2.AddText(paragrafoCabecalho2); columnTextCabecalho2.SetSimpleColumn(790, 558, 10, 0, 10, Element.ALIGN_CENTER); columnTextCabecalho2.Go(); #region Imagem LOGO LEFT if (_documentOptions.HeaderOptions != null && _documentOptions.HeaderOptions.HeaderImageLeft != null) { MemoryStream mst = new MemoryStream(); _documentOptions.HeaderOptions.HeaderImageLeft.Save(mst, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] b = mst.ToArray(); //posicionando a imagem no arquivo iTextSharp.text.Image imageLogo = iTextSharp.text.Image.GetInstance(b); imageLogo.SetAbsolutePosition(document.PageSize.Width - 822f, document.PageSize.Height - 46f); imageLogo.ScalePercent(52f); document.Add(imageLogo); } #endregion #region Imagem LOGO RIGHT if (_documentOptions.HeaderOptions != null && _documentOptions.HeaderOptions.ShowImageRight && _documentOptions.HeaderOptions.HeaderImageRight != null) { MemoryStream mst = new MemoryStream(); _documentOptions.HeaderOptions.HeaderImageRight.Save(mst, System.Drawing.Imaging.ImageFormat.Png); byte[] b = mst.ToArray(); //posicionando a imagem no arquivo iTextSharp.text.Image imageLogo = iTextSharp.text.Image.GetInstance(b); imageLogo.SetAbsolutePosition(document.PageSize.Width - 125f, document.PageSize.Height - 46f); imageLogo.ScalePercent(35f); document.Add(imageLogo); } #endregion #region Data de impressão if (_documentOptions.ShowPrintDateTime) { Chunk chunkDataImpressaoText = new Chunk("Data de impressão: ", FontFactory.GetFont("Arial", 8f, Font.BOLD, BaseColor.BLACK)); Phrase phraseDataImpressaoText = new Phrase(); phraseDataImpressaoText.Add(chunkDataImpressaoText); Chunk chunkDataImpressaoData = new Chunk(PrintDateTime.ToString(), FontFactory.GetFont("Arial", 8f, BaseColor.BLACK)); Phrase phraseDataImpressaoData = new Phrase(); phraseDataImpressaoData.Add(chunkDataImpressaoData); Paragraph paragrafoTextDataImpressao = new Paragraph(); paragrafoTextDataImpressao.Add(chunkDataImpressaoText); paragrafoTextDataImpressao.Add(chunkDataImpressaoData); ColumnText columnTextDataImpressao = new ColumnText(cb); columnTextDataImpressao.AddText(paragrafoTextDataImpressao); columnTextDataImpressao.SetSimpleColumn(790, 530, 10, 0, 10, Element.ALIGN_RIGHT); columnTextDataImpressao.Go(); } #endregion tableHeader.AddCell(cellHeader); } //chamar WriteSelectedRows da PdfTable. Este escreve linhas de PdfWriter em PdfTable. //Primeiro parâmetro é começar a linha. -1 indica que não há linha final e todas as linhas a serem incluídos para escrever //Parâmetro terceiro e quarto é x e y posição para começar a escrever tableHeader.WriteSelectedRows(0, -1, 40, document.PageSize.Height - 30, writer.DirectContent); } #endregion #region Linha em baixo (cabeçalho e rodapé) //Move o pointer e desenhar linha para separar seção de cabeçalho do resto da página if (_documentOptions.HeaderOptions.DrawHeaderLine) { cb.MoveTo(20, document.PageSize.GetTop(60)); cb.LineTo(document.PageSize.Width - 20, document.PageSize.GetTop(60)); cb.Stroke(); } //Move o pointer e desenhar linha para separar seção de rodapé do resto da página if (_documentOptions.FooterOptions.DrawFooterLine) { cb.MoveTo(20, document.PageSize.GetBottom(50)); cb.LineTo(document.PageSize.Width - 20, document.PageSize.GetBottom(50)); cb.Stroke(); } #endregion }
public void lineTo(Int64 x, Int64 y) { m_canvas.LineTo(dkw(x), dkh(y)); }
public override void OnEndPage(iTextSharp.text.pdf.PdfWriter writer, iTextSharp.text.Document document) { base.OnEndPage(writer, document); iTextSharp.text.Font baseFontSmall = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 10f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK); iTextSharp.text.Font baseFontNormal = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK); iTextSharp.text.Font baseFontBig = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK); string text = "Página " + writer.PageNumber + " de "; float right1 = 125; //Add paging to header { cb.BeginText(); cb.SetFontAndSize(bf, 12); cb.SetTextMatrix(document.PageSize.GetLeft(40), document.PageSize.GetTop(45)); cb.ShowText(this.TituloDoDocumento); cb.SetTextMatrix(document.PageSize.GetRight(right1), document.PageSize.GetTop(45)); cb.ShowText(text); cb.EndText(); float len = bf.GetWidthPoint(text, 12); //adcionando o total de páginas cb.AddTemplate(headerTemplate, document.PageSize.GetRight(right1) + len, document.PageSize.GetTop(45)); } //Add paging to footer //{ // cb.BeginText(); // cb.SetFontAndSize(bf, 12); // cb.SetTextMatrix(document.PageSize.GetRight(right1), document.PageSize.GetBottom(30)); // cb.ShowText(text); // cb.EndText(); // float len = bf.GetWidthPoint(text, 12); // //adcionando o total de páginas // cb.AddTemplate(footerTemplate, document.PageSize.GetRight(right1) + len, document.PageSize.GetBottom(30)); //} //Move the pointer and draw line to separate header section from rest of page cb.MoveTo(40, document.PageSize.GetTop(50)); cb.LineTo(document.PageSize.Width - 40, document.PageSize.GetTop(50)); cb.Stroke(); ////Move the pointer and draw line to separate footer section from rest of page //cb.MoveTo(40, document.PageSize.GetBottom(50)); //cb.LineTo(document.PageSize.Width - 40, document.PageSize.GetBottom(50)); //cb.Stroke(); Font _TH = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.WHITE); Font _TD = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK); if (!this.PageState.IsLastPage) { //colocando hash da assinatura PdfPTable tab1 = new PdfPTable(1); tab1.TotalWidth = document.PageSize.Width - 80f; tab1.WidthPercentage = 70; var cell = new PdfPCell(new Phrase("Hash do documento", _TH)); cell.BackgroundColor = iTextSharp.text.BaseColor.BLACK; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.Padding = 5f; cell.Colspan = 3; tab1.AddCell(cell); cell = new PdfPCell(new Phrase(this.Hash, _TD)); cell.BackgroundColor = iTextSharp.text.BaseColor.WHITE; cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.Padding = 5f; cell.Colspan = 3; tab1.AddCell(cell); tab1.WriteSelectedRows(0, -1, 40, 70, writer.DirectContent); } else { PdfPTable tab1 = new PdfPTable(3); tab1.TotalWidth = document.PageSize.Width - 80f; tab1.WidthPercentage = 70; tab1.HorizontalAlignment = Element.ALIGN_CENTER; tab1.SetWidths(new float[] { 100f, 100f, 100f }); var cell = new PdfPCell(new Phrase("Usuário", _TH)); cell.BackgroundColor = iTextSharp.text.BaseColor.BLACK; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.Padding = 5f; tab1.AddCell(cell); cell = new PdfPCell(new Phrase("CPF", _TH)); cell.BackgroundColor = iTextSharp.text.BaseColor.BLACK; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.Padding = 5f; tab1.AddCell(cell); cell = new PdfPCell(new Phrase("Data do aceite", _TH)); cell.BackgroundColor = iTextSharp.text.BaseColor.BLACK; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.Padding = 5f; tab1.AddCell(cell); cell = new PdfPCell(new Phrase(this.Nome, _TD)); cell.BackgroundColor = iTextSharp.text.BaseColor.WHITE; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.Padding = 5f; tab1.AddCell(cell); cell = new PdfPCell(new Phrase(this.CPF, _TD)); cell.BackgroundColor = iTextSharp.text.BaseColor.WHITE; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.Padding = 5f; tab1.AddCell(cell); cell = new PdfPCell(new Phrase(this.PrintTime.ToString("dd/MM/yyyy HH:mm"), _TD)); cell.BackgroundColor = iTextSharp.text.BaseColor.WHITE; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.Padding = 5f; tab1.AddCell(cell); cell = new PdfPCell(new Phrase("Hash do documento", _TH)); cell.BackgroundColor = iTextSharp.text.BaseColor.BLACK; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.Padding = 5f; cell.Colspan = 3; tab1.AddCell(cell); cell = new PdfPCell(new Phrase(this.Hash, _TD)); cell.BackgroundColor = iTextSharp.text.BaseColor.WHITE; cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.Padding = 5f; cell.Colspan = 3; tab1.AddCell(cell); tab1.WriteSelectedRows(0, -1, 40, 120, writer.DirectContent); } }
public MemoryStream CreatePDF(Comprobante comprobante) { try { MemoryStream outputStream = new MemoryStream(); Document document = new Document(PageSize.LETTER, 53.858267717f, 51.023622047f, 45.354330709f, 45.354330709f); PdfWriter writer = PdfWriter.GetInstance(document, outputStream); document.Open(); //Fonts string fontpath = HttpContext.Current.Server.MapPath(@"~/Content/fonts/Verdana/"); BaseFont Verdana = BaseFont.CreateFont(fontpath + "verdana.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); BaseFont VerdanaBold = BaseFont.CreateFont(fontpath + "verdanab.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font VerdanaBold7Color = new Font(VerdanaBold, 7f, Font.NORMAL, new Color(62, 84, 84)); Font VerdanaBold9Color = new Font(VerdanaBold, 8f, Font.NORMAL, new Color(62, 84, 84)); Font Verdana9 = new Font(Verdana, 7f, Font.NORMAL, new Color(0, 0, 0)); Font VerdanaBold10Color = new Font(VerdanaBold, 8f, Font.NORMAL, new Color(62, 84, 84)); Font Verdana5 = new Font(Verdana, 5f, Font.NORMAL, new Color(0, 0, 0)); PdfPTable MainTable = new PdfPTable(1); MainTable.TotalWidth = 507.401574803f; MainTable.LockedWidth = true; MainTable.DefaultCell.Border = 0; #region Header PdfPTable HeaderTable = new PdfPTable(3); HeaderTable.TotalWidth = 507.401574803f; HeaderTable.LockedWidth = true; float[] widhtsHeader = new float[] { 116.220472441f, 198.42519685f, 192.755905512f }; HeaderTable.SetWidths(widhtsHeader); HeaderTable.DefaultCell.Border = 0; //Logo de la empresa en Base64 Byte[] bytes = this.LoadLogoBase64(comprobante.Emisor.LogoUrl); Image logo = iTextSharp.text.Image.GetInstance(bytes); logo.ScalePercent(30f); PdfPCell HeaderLogo = new PdfPCell(logo); HeaderLogo.FixedHeight = 93.543307087f; HeaderLogo.HorizontalAlignment = Rectangle.ALIGN_CENTER; HeaderLogo.VerticalAlignment = Rectangle.ALIGN_MIDDLE; HeaderLogo.Border = 0; HeaderTable.AddCell(HeaderLogo); //Tabla Anidada con Datos de emisor PdfPTable DatosEmisor = new PdfPTable(1); DatosEmisor.DefaultCell.Border = 0; PdfPCell CorporateName = new PdfPCell(new Phrase(comprobante.Emisor.Nombre, VerdanaBold9Color)); //CorporateName.PaddingTop = 20; CorporateName.HorizontalAlignment = Rectangle.ALIGN_CENTER; CorporateName.Border = Rectangle.NO_BORDER; DatosEmisor.AddCell(CorporateName); PdfContentByte LineaDatosEmisor = writer.DirectContent; LineaDatosEmisor.MoveTo(175.748031496f, document.Top - 17.007874016f); LineaDatosEmisor.LineTo(360, document.Top - 17.007874016f); LineaDatosEmisor.SetRGBColorStroke(62, 84, 84); LineaDatosEmisor.Stroke(); PdfPTable TableCompanyData = new PdfPTable(1); PdfPCell CompanyRFC = new PdfPCell(new Phrase("R.F.C. " + comprobante.Emisor.RFC, Verdana9)); CompanyRFC.Border = 0; TableCompanyData.AddCell(CompanyRFC); PdfPCell CompanyCalle = new PdfPCell(new Phrase(comprobante.Emisor.DomicilioFiscal.Calle + " # " + comprobante.Emisor.DomicilioFiscal.NoExterior, Verdana9)); CompanyCalle.Border = 0; TableCompanyData.AddCell(CompanyCalle); PdfPCell CompanyColonia = new PdfPCell(new Phrase(comprobante.Emisor.DomicilioFiscal.Colonia + ", C.P. " + comprobante.Emisor.DomicilioFiscal.CodigoPostal, Verdana9)); CompanyColonia.Border = 0; TableCompanyData.AddCell(CompanyColonia); PdfPCell CompanyCiudad = new PdfPCell(new Phrase(comprobante.Emisor.DomicilioFiscal.Municipio + ", " + comprobante.Emisor.DomicilioFiscal.Estado + ". " + comprobante.Emisor.DomicilioFiscal.Pais, Verdana9)); CompanyCiudad.Border = 0; TableCompanyData.AddCell(CompanyCiudad); PdfPCell CompanyTelefono = new PdfPCell(new Phrase("TEL. " + comprobante.Emisor.Telefono, Verdana9)); CompanyTelefono.Border = 0; TableCompanyData.AddCell(CompanyTelefono); PdfPCell CompanyCorreo = new PdfPCell(new Phrase(comprobante.Emisor.Correo, Verdana9)); CompanyCorreo.Border = 0; TableCompanyData.AddCell(CompanyCorreo); PdfPCell CompanyRegimen = null; if (comprobante.Emisor.RegimenFiscal.Count > 0) { CompanyRegimen = new PdfPCell(new Phrase("Régimen Fiscal: " + comprobante.Emisor.RegimenFiscal[0].Regimen, Verdana9)); } else { CompanyRegimen = new PdfPCell(new Phrase("Régimen Fiscal: ", Verdana9)); } CompanyRegimen.Border = 0; TableCompanyData.AddCell(CompanyRegimen); PdfPCell CompanyData = new PdfPCell(TableCompanyData); CompanyData.HorizontalAlignment = Rectangle.ALIGN_LEFT; CompanyData.PaddingLeft = 20; CompanyData.Border = 0; DatosEmisor.AddCell(CompanyData); HeaderTable.AddCell(DatosEmisor); //Tabla Anidada con datos de control de la factura PdfPTable ControlDataInvoice = new PdfPTable(2); float[] WidthsControlDataInvoice = new float[] { 76.535433071f, 116.220472441f }; ControlDataInvoice.SetWidths(WidthsControlDataInvoice); PdfPCell TextFactura = new PdfPCell(new Phrase("Factura: " + comprobante.Serie + comprobante.Folio, VerdanaBold10Color)); TextFactura.Colspan = 2; TextFactura.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextFactura.Border = 0; ControlDataInvoice.AddCell(TextFactura); PdfContentByte LineaDatosFactura = writer.DirectContent; LineaDatosFactura.MoveTo(374.842519685f, document.Top - 15.007874016f); LineaDatosFactura.LineTo(554.763779528f, document.Top - 15.007874016f); LineaDatosFactura.SetRGBColorStroke(62, 84, 84); LineaDatosFactura.SetLineWidth(1); LineaDatosFactura.Stroke(); PdfPCell TextEmision = new PdfPCell(new Phrase("Emisión", Verdana9)); TextEmision.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextEmision.Border = 0; ControlDataInvoice.AddCell(TextEmision); PdfPCell FechaEmision = new PdfPCell(new Phrase(comprobante.Fecha.ToString("dd/MM/yyyy HH:mm:ss"), Verdana9)); FechaEmision.HorizontalAlignment = Rectangle.ALIGN_CENTER; FechaEmision.Border = 0; ControlDataInvoice.AddCell(FechaEmision); PdfPCell TextFolio = new PdfPCell(new Phrase("Folio Fiscal", Verdana9)); TextFolio.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextFolio.Border = 0; ControlDataInvoice.AddCell(TextFolio); string PhraseUUID = ""; if (comprobante.Status.Equals("A")) { foreach (var complemento in comprobante.Complementos) { if (complemento is TimbreFiscalDigital) { TimbreFiscalDigital timbre = (TimbreFiscalDigital)complemento; if (!String.IsNullOrEmpty(timbre.UUID)) { PhraseUUID = timbre.UUID.ToString(); } } } //if (!String.IsNullOrEmpty(comprobante .Complemento.TimbreFiscalDigital.UUID)) { // PhraseUUID = comprobante.Complemento.TimbreFiscalDigital.UUID.ToString(); //} } PdfPCell Folio = new PdfPCell(new Phrase(PhraseUUID, Verdana9)); Folio.HorizontalAlignment = Rectangle.ALIGN_CENTER; Folio.Border = 0; ControlDataInvoice.AddCell(Folio); PdfPCell TextNoOrden = new PdfPCell(new Phrase("No. de Orden", Verdana9)); TextNoOrden.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextNoOrden.Border = 0; ControlDataInvoice.AddCell(TextNoOrden); PdfPCell NoOrden = new PdfPCell(new Phrase(comprobante.ExtendedIntValue1.ToString(), Verdana9)); NoOrden.HorizontalAlignment = Rectangle.ALIGN_CENTER; NoOrden.Border = 0; ControlDataInvoice.AddCell(NoOrden); PdfPCell TextCliente = new PdfPCell(new Phrase("Cliente", Verdana9)); TextCliente.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextCliente.Border = 0; ControlDataInvoice.AddCell(TextCliente); PdfPCell Cliente = new PdfPCell(new Phrase(comprobante.ExtendedIntValue2.ToString(), Verdana9)); Cliente.HorizontalAlignment = Rectangle.ALIGN_CENTER; Cliente.Border = 0; ControlDataInvoice.AddCell(Cliente); PdfPCell TextTransporte = new PdfPCell(new Phrase("Transporte", Verdana9)); TextTransporte.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextTransporte.Border = 0; ControlDataInvoice.AddCell(TextTransporte); PdfPCell Transporte = new PdfPCell(new Phrase("CLIENTE", Verdana9)); Transporte.HorizontalAlignment = Rectangle.ALIGN_CENTER; Transporte.Border = 0; ControlDataInvoice.AddCell(Transporte); PdfPCell TextMetodoPago = new PdfPCell(new Phrase("Método de Pago", Verdana9)); TextMetodoPago.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextMetodoPago.Border = 0; ControlDataInvoice.AddCell(TextMetodoPago); PdfPCell MetodoPago = new PdfPCell(new Phrase(comprobante.MetodoDePago, Verdana9)); MetodoPago.HorizontalAlignment = Rectangle.ALIGN_CENTER; MetodoPago.Border = 0; ControlDataInvoice.AddCell(MetodoPago); if (comprobante.MetodoDePago != null && (comprobante.MetodoDePago.ToString().Equals("Cheque") || comprobante.MetodoDePago.ToString().Equals("Tarjeta de Crédito") || comprobante.MetodoDePago.ToString().Equals("Tarjeta de Débito"))) { PdfPCell TextNoCuenta = new PdfPCell(new Phrase("Número de Cuenta", Verdana9)); TextNoCuenta.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextNoCuenta.Border = 0; ControlDataInvoice.AddCell(TextNoCuenta); PdfPCell Cuenta = new PdfPCell(new Phrase(comprobante.NumCtaPago, Verdana9)); Cuenta.HorizontalAlignment = Rectangle.ALIGN_CENTER; Cuenta.Border = 0; ControlDataInvoice.AddCell(Cuenta); } PdfPCell ContentDatosFactura = new PdfPCell(ControlDataInvoice); ContentDatosFactura.BorderColor = new Color(62, 84, 84); ContentDatosFactura.BorderWidth = 2; PdfPCell EspacioTablas = new PdfPCell(); EspacioTablas.Colspan = 2; EspacioTablas.Border = 0; ControlDataInvoice.AddCell(EspacioTablas); HeaderTable.AddCell(ContentDatosFactura); MainTable.AddCell(HeaderTable); PdfPCell EspacioTablas1 = new PdfPCell(); EspacioTablas1.Colspan = 2; EspacioTablas1.Border = 0; EspacioTablas1.FixedHeight = 7.086614173f; MainTable.AddCell(EspacioTablas1); #endregion #region DatosFacturacion PdfPTable DatosReceptor = new PdfPTable(3); DatosReceptor.TotalWidth = 507.401574803f; DatosReceptor.LockedWidth = true; float[] WidthsDatosReceptor = new float[] { 250.866141732f, 5.669291339f, 250.866141732f }; DatosReceptor.SetWidths(WidthsDatosReceptor); PdfPTable DatosFacturacion = new PdfPTable(2); DatosFacturacion.TotalWidth = 250.866141732f; float[] WidthsDatosFacturacion = new float[] { 70.866141732f, 180f }; DatosFacturacion.SetWidths(WidthsDatosFacturacion); PdfPCell TextDatosFacturacion = new PdfPCell(new Phrase("Datos de Facturación", VerdanaBold9Color)); TextDatosFacturacion.Colspan = 2; TextDatosFacturacion.Border = Rectangle.BOTTOM_BORDER; TextDatosFacturacion.BorderColor = new Color(62, 84, 84); TextDatosFacturacion.BorderWidth = 1.3f; TextDatosFacturacion.HorizontalAlignment = Rectangle.ALIGN_CENTER; DatosFacturacion.AddCell(TextDatosFacturacion); PdfPCell TextoRFC = new PdfPCell(new Phrase("RFC", Verdana9)); TextoRFC.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextoRFC.Border = 0; DatosFacturacion.AddCell(TextoRFC); PdfPCell RFC = new PdfPCell(new Phrase(comprobante.Receptor.RFC, Verdana9)); RFC.HorizontalAlignment = Rectangle.ALIGN_CENTER; RFC.Border = 0; DatosFacturacion.AddCell(RFC); PdfPCell TextoNombre = new PdfPCell(new Phrase("Nombre", Verdana9)); TextoNombre.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextoNombre.Border = 0; DatosFacturacion.AddCell(TextoNombre); PdfPCell Nombre = new PdfPCell(new Phrase(comprobante.Receptor.Nombre, Verdana9)); Nombre.Border = 0; Nombre.HorizontalAlignment = Rectangle.ALIGN_CENTER; DatosFacturacion.AddCell(Nombre); PdfPCell TextDireccionFiscal = new PdfPCell(new Phrase("Dirección Fiscal", VerdanaBold9Color)); TextDireccionFiscal.Colspan = 2; TextDireccionFiscal.Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER; TextDireccionFiscal.BorderColor = new Color(62, 84, 84); TextDireccionFiscal.BorderWidth = 1.3f; TextDireccionFiscal.HorizontalAlignment = Rectangle.ALIGN_CENTER; DatosFacturacion.AddCell(TextDireccionFiscal); PdfPCell TextoCalle = new PdfPCell(new Phrase("Calle", Verdana9)); TextoCalle.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextoCalle.Border = 0; DatosFacturacion.AddCell(TextoCalle); PdfPCell Calle = new PdfPCell(new Phrase(comprobante.Receptor.Domicilio.Calle + " # " + comprobante.Receptor.Domicilio.NoExterior, Verdana9)); Calle.HorizontalAlignment = Rectangle.ALIGN_CENTER; Calle.Border = 0; DatosFacturacion.AddCell(Calle); PdfPCell TextoColonia = new PdfPCell(new Phrase("Colonia", Verdana9)); TextoColonia.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextoColonia.Border = 0; DatosFacturacion.AddCell(TextoColonia); PdfPCell Colonia = new PdfPCell(new Phrase(comprobante.Receptor.Domicilio.Colonia, Verdana9)); Colonia.HorizontalAlignment = Rectangle.ALIGN_CENTER; Colonia.Border = 0; DatosFacturacion.AddCell(Colonia); PdfPCell TextoMunicipio = new PdfPCell(new Phrase("Municipio", Verdana9)); TextoMunicipio.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextoMunicipio.Border = 0; DatosFacturacion.AddCell(TextoMunicipio); PdfPCell Municipio = new PdfPCell(new Phrase(comprobante.Receptor.Domicilio.Municipio, Verdana9)); Municipio.HorizontalAlignment = Rectangle.ALIGN_CENTER; Municipio.Border = 0; DatosFacturacion.AddCell(Municipio); PdfPCell TextoEstado = new PdfPCell(new Phrase("Estado", Verdana9)); TextoEstado.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextoEstado.Border = 0; DatosFacturacion.AddCell(TextoEstado); PdfPCell Estado = new PdfPCell(new Phrase(comprobante.Receptor.Domicilio.Estado, Verdana9)); Estado.HorizontalAlignment = Rectangle.ALIGN_CENTER; Estado.Border = 0; DatosFacturacion.AddCell(Estado); PdfPCell TextoPais = new PdfPCell(new Phrase("País", Verdana9)); TextoPais.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextoPais.Border = 0; DatosFacturacion.AddCell(TextoPais); PdfPCell Pais = new PdfPCell(new Phrase(comprobante.Receptor.Domicilio.Pais, Verdana9)); Pais.HorizontalAlignment = Rectangle.ALIGN_CENTER; Pais.Border = 0; DatosFacturacion.AddCell(Pais); PdfPCell TextoCP = new PdfPCell(new Phrase("Código Postal", Verdana9)); TextoCP.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextoCP.Border = 0; DatosFacturacion.AddCell(TextoCP); PdfPCell CP = new PdfPCell(new Phrase("C.P. " + comprobante.Receptor.Domicilio.CodigoPostal, Verdana9)); CP.HorizontalAlignment = Rectangle.ALIGN_CENTER; CP.Border = 0; DatosFacturacion.AddCell(CP); PdfPCell CellDatosFacturacion = new PdfPCell(DatosFacturacion); CellDatosFacturacion.BorderColor = new Color(62, 84, 84); CellDatosFacturacion.BorderWidth = 2; CellDatosFacturacion.PaddingRight = 4; CellDatosFacturacion.PaddingLeft = 4; CellDatosFacturacion.PaddingBottom = 4; DatosReceptor.AddCell(CellDatosFacturacion); PdfPCell Espacio = new PdfPCell(); Espacio.Border = 0; DatosReceptor.AddCell(Espacio); PdfPTable DatosDestinatario = new PdfPTable(2); DatosDestinatario.TotalWidth = 250.866141732f; DatosDestinatario.SetWidths(WidthsDatosFacturacion); PdfPCell TextDestinatarioHeader = new PdfPCell(new Phrase("Destinatario", VerdanaBold9Color)); TextDestinatarioHeader.Colspan = 2; TextDestinatarioHeader.Border = Rectangle.BOTTOM_BORDER; TextDestinatarioHeader.BorderColor = new Color(62, 84, 84); TextDestinatarioHeader.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextDestinatarioHeader.BorderWidth = 1.3f; DatosDestinatario.AddCell(TextDestinatarioHeader); PdfPCell TextoDestinatario = new PdfPCell(new Phrase("Destinatario", Verdana9)); TextoDestinatario.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextoDestinatario.Border = 0; DatosDestinatario.AddCell(TextoDestinatario); PdfPCell Destinatario = new PdfPCell(new Phrase(comprobante.Receptor.Nombre, Verdana9)); Destinatario.HorizontalAlignment = Rectangle.ALIGN_CENTER; Destinatario.Border = 0; DatosDestinatario.AddCell(Destinatario); PdfPCell TextDireccion = new PdfPCell(new Phrase("Dirección", VerdanaBold9Color)); TextDireccion.Colspan = 2; TextDireccion.Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER; TextDireccion.BorderColor = new Color(62, 84, 84); TextDireccion.BorderWidth = 1.3f; TextDireccion.HorizontalAlignment = Rectangle.ALIGN_CENTER; DatosDestinatario.AddCell(TextDireccion); DatosDestinatario.AddCell(TextoCalle); PdfPCell CalleDireccion = new PdfPCell(new Phrase(comprobante.Receptor.Domicilio.Calle + " # " + comprobante.Receptor.Domicilio.NoExterior, Verdana9)); CalleDireccion.HorizontalAlignment = Rectangle.ALIGN_CENTER; CalleDireccion.Border = 0; DatosDestinatario.AddCell(CalleDireccion); DatosDestinatario.AddCell(TextoColonia); PdfPCell ColoniaDireccion = new PdfPCell(new Phrase(comprobante.Receptor.Domicilio.Colonia, Verdana9)); ColoniaDireccion.HorizontalAlignment = Rectangle.ALIGN_CENTER; ColoniaDireccion.Border = 0; DatosDestinatario.AddCell(ColoniaDireccion); DatosDestinatario.AddCell(TextoMunicipio); PdfPCell MunicipioDireccion = new PdfPCell(new Phrase(comprobante.Receptor.Domicilio.Municipio, Verdana9)); MunicipioDireccion.HorizontalAlignment = Rectangle.ALIGN_CENTER; MunicipioDireccion.Border = 0; DatosDestinatario.AddCell(MunicipioDireccion); DatosDestinatario.AddCell(TextoEstado); PdfPCell EstadoDireccion = new PdfPCell(new Phrase(comprobante.Receptor.Domicilio.Estado, Verdana9)); EstadoDireccion.HorizontalAlignment = Rectangle.ALIGN_CENTER; EstadoDireccion.Border = 0; DatosDestinatario.AddCell(EstadoDireccion); DatosDestinatario.AddCell(TextoPais); PdfPCell PaisDireccion = new PdfPCell(new Phrase(comprobante.Receptor.Domicilio.Pais, Verdana9)); PaisDireccion.HorizontalAlignment = Rectangle.ALIGN_CENTER; PaisDireccion.Border = 0; DatosDestinatario.AddCell(PaisDireccion); DatosDestinatario.AddCell(TextoCP); PdfPCell CPDireccion = new PdfPCell(new Phrase("C.P. " + comprobante.Receptor.Domicilio.CodigoPostal, Verdana9)); CPDireccion.HorizontalAlignment = Rectangle.ALIGN_CENTER; CPDireccion.Border = 0; DatosDestinatario.AddCell(CPDireccion); PdfPCell CellDatosDestinatario = new PdfPCell(DatosDestinatario); CellDatosDestinatario.BorderColor = new Color(62, 84, 84); CellDatosDestinatario.BorderWidth = 2; CellDatosDestinatario.PaddingRight = 4; CellDatosDestinatario.PaddingLeft = 4; CellDatosDestinatario.PaddingBottom = 4; DatosReceptor.AddCell(CellDatosDestinatario); MainTable.AddCell(DatosReceptor); #endregion PdfPCell TableDivision = new PdfPCell(); TableDivision.FixedHeight = 7.086614173f; TableDivision.Border = 0; MainTable.AddCell(TableDivision); #region Conceptos PdfPTable Conceptos = new PdfPTable(1); Conceptos.TotalWidth = 507.401574803f; Conceptos.LockedWidth = true; PdfPTable TableConceptos = new PdfPTable(9); float[] WidhtsTableConceptos = new float[] { 51.023622047f, 2.834645669f, 63.779527559f, 2.834645669f, 246.614173228f, 2.834645669f, 62.362204724f, 2.834645669f, 65.196850394f }; TableConceptos.SetWidths(WidhtsTableConceptos); TableConceptos.SplitRows = true;//.SpacingAfter = 50f; PdfPCell TextoCantidad = new PdfPCell(new Phrase("Cantidad", VerdanaBold9Color)); TextoCantidad.Border = Rectangle.BOTTOM_BORDER; TextoCantidad.BorderWidth = 1.3f; TextoCantidad.BorderColor = new Color(62, 84, 84); TextoCantidad.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextoCantidad.PaddingBottom = 4; TableConceptos.AddCell(TextoCantidad); PdfPCell Espacio1 = new PdfPCell(); Espacio1.Border = 0; TableConceptos.AddCell(Espacio1); PdfPCell TextoClave = new PdfPCell(new Phrase("Clave", VerdanaBold9Color)); TextoClave.Border = Rectangle.BOTTOM_BORDER; TextoClave.BorderWidth = 1.3f; TextoClave.BorderColor = new Color(62, 84, 84); TextoClave.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextoClave.PaddingBottom = 4; TableConceptos.AddCell(TextoClave); TableConceptos.AddCell(Espacio1); PdfPCell TextoDescripción = new PdfPCell(new Phrase("Descripción", VerdanaBold9Color)); TextoDescripción.Border = Rectangle.BOTTOM_BORDER; TextoDescripción.BorderWidth = 1.3f; TextoDescripción.BorderColor = new Color(62, 84, 84); TextoDescripción.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextoDescripción.PaddingBottom = 4; TableConceptos.AddCell(TextoDescripción); TableConceptos.AddCell(Espacio1); PdfPCell TextoPUnitario = new PdfPCell(new Phrase("P. Unitario", VerdanaBold9Color)); TextoPUnitario.Border = Rectangle.BOTTOM_BORDER; TextoPUnitario.BorderWidth = 1.3f; TextoPUnitario.BorderColor = new Color(62, 84, 84); TextoPUnitario.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextoPUnitario.PaddingBottom = 4; TableConceptos.AddCell(TextoPUnitario); TableConceptos.AddCell(Espacio1); PdfPCell TextoImporte = new PdfPCell(new Phrase("Importe", VerdanaBold9Color)); TextoImporte.Border = Rectangle.BOTTOM_BORDER; TextoImporte.BorderWidth = 1.3f; TextoImporte.BorderColor = new Color(62, 84, 84); TextoImporte.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextoImporte.PaddingBottom = 4; TableConceptos.AddCell(TextoImporte); foreach (Concepto concepto in comprobante.Conceptos) { PdfPCell conceptoCantidad = new PdfPCell(new Phrase(concepto.Cantidad.ToString("0.00"), Verdana9)); conceptoCantidad.HorizontalAlignment = Element.ALIGN_CENTER; conceptoCantidad.Border = 0; TableConceptos.AddCell(conceptoCantidad); TableConceptos.AddCell(Espacio1); PdfPCell conceptoClave = new PdfPCell(new Phrase(concepto.NoIdentificacion, Verdana9)); conceptoClave.HorizontalAlignment = Element.ALIGN_CENTER; conceptoClave.Border = 0; TableConceptos.AddCell(conceptoClave); TableConceptos.AddCell(Espacio1); PdfPCell conceptoDescripcion = new PdfPCell(new Phrase(concepto.Descripcion, Verdana9)); conceptoDescripcion.HorizontalAlignment = Element.ALIGN_CENTER; conceptoDescripcion.Border = 0; TableConceptos.AddCell(conceptoDescripcion); TableConceptos.AddCell(Espacio1); PdfPCell conceptoPUnitario = new PdfPCell(new Phrase("$" + concepto.ValorUnitario.ToString("#,##0.00"), Verdana9)); conceptoPUnitario.HorizontalAlignment = Element.ALIGN_CENTER; conceptoPUnitario.Border = 0; TableConceptos.AddCell(conceptoPUnitario); TableConceptos.AddCell(Espacio1); PdfPCell conceptoImporte = new PdfPCell(new Phrase("$" + concepto.Importe.ToString("#,##0.00"), Verdana9)); conceptoImporte.HorizontalAlignment = Element.ALIGN_CENTER; conceptoImporte.Border = 0; TableConceptos.AddCell(conceptoImporte); } PdfPCell CellConceptos = new PdfPCell(TableConceptos); CellConceptos.BorderWidth = 2; CellConceptos.BorderColor = new Color(62, 84, 84); CellConceptos.PaddingRight = 4; CellConceptos.PaddingLeft = 4; CellConceptos.MinimumHeight = 184.251968504f; Conceptos.AddCell(CellConceptos); MainTable.AddCell(Conceptos); #endregion MainTable.AddCell(TableDivision); PdfPTable FooterContent = new PdfPTable(1); FooterContent.TotalWidth = 507.401574803f; FooterContent.LockedWidth = true; FooterContent.DefaultCell.Border = 0; PdfPTable Footer = new PdfPTable(2); Footer.DefaultCell.Border = 0; float[] WidthsFooter = new float[] { 86.456692913f, 420.94488189f }; Footer.TotalWidth = 507.401574803f; Footer.LockedWidth = true; Footer.SetWidths(WidthsFooter); //CIF empresa en Base64 Byte[] bytes2 = LoadCIFBase64(comprobante.Emisor.CifUrl); Image CIFImage = iTextSharp.text.Image.GetInstance(bytes2); CIFImage.ScaleAbsoluteWidth(76.535433071f); CIFImage.ScaleAbsoluteHeight(155.905511811f); PdfPCell CIF = new PdfPCell(CIFImage); CIF.HorizontalAlignment = Rectangle.ALIGN_CENTER; CIF.VerticalAlignment = Rectangle.ALIGN_MIDDLE; CIF.Border = Rectangle.RIGHT_BORDER; CIF.BorderColor = new Color(62, 84, 84); CIF.BorderWidth = 1.3f; Footer.AddCell(CIF); PdfPTable FooterRight = new PdfPTable(1); FooterRight.DefaultCell.Border = 0; PdfPTable TableFooterTop = new PdfPTable(2); TableFooterTop.DefaultCell.Border = 0; float[] WidhtsFooterTop = new float[] { 198.42519685f, 222.519685039f }; TableFooterTop.SetWidths(WidhtsFooterTop); PdfPTable FooterTopLeft = new PdfPTable(1); FooterTopLeft.DefaultCell.Border = 0; Font CamposSAT = new Font(); CamposSAT = FontFactory.GetFont("Arial", 8.0f, Font.NORMAL, new Color(0, 0, 0)); PdfPTable TableCertificacion = new PdfPTable(1); string PhraseFechaCertificacion = ""; if (comprobante.Status.Equals("A")) { foreach (var complemento in comprobante.Complementos) { if (complemento is TimbreFiscalDigital) { TimbreFiscalDigital timbre = (TimbreFiscalDigital)complemento; //if (!String.IsNullOrEmpty(timbre.FechaTimbrado)) { PhraseUUID = timbre.FechaTimbrado.ToString("dd/MM/yyyy HH:mm:ss"); //} } } //if (!String.IsNullOrEmpty(comprobante.Complemento.TimbreFiscalDigital.FechaTimbrado.ToString())) { // PhraseFechaCertificacion = comprobante.Complemento.TimbreFiscalDigital.FechaTimbrado.ToString("dd/MM/yyyy HH:mm:ss"); //} } PdfPCell Certificacion = new PdfPCell(new Phrase("Certificación: " + PhraseFechaCertificacion + "\n", VerdanaBold9Color)); Certificacion.HorizontalAlignment = Rectangle.ALIGN_CENTER; Certificacion.VerticalAlignment = Rectangle.ALIGN_CENTER; Certificacion.Border = 0; TableCertificacion.AddCell(Certificacion); TableCertificacion.AddCell(Espacio1); PdfPCell CadenaSAT = new PdfPCell(new Phrase("Cadena SAT", VerdanaBold9Color)); CadenaSAT.FixedHeight = 14.173228346f; CadenaSAT.HorizontalAlignment = Rectangle.ALIGN_CENTER; CadenaSAT.VerticalAlignment = Rectangle.ALIGN_CENTER; CadenaSAT.Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER; CadenaSAT.BorderColor = new Color(62, 84, 84); CadenaSAT.BorderWidth = 1.3f; TableCertificacion.AddCell(CadenaSAT); string cadenaSAT = comprobante.GetCadenaOriginal(); // .CadenaOriginal; //if (comprobante.Version.Equals("3.2")) cadenaSAT = comprobante.GetCadenaSAT(); // .CadenaSAT; PdfPCell Cadena = new PdfPCell(new Phrase(cadenaSAT, Verdana5)); Cadena.HorizontalAlignment = Rectangle.ALIGN_CENTER; Cadena.VerticalAlignment = Rectangle.ALIGN_MIDDLE; Cadena.Border = 0; TableCertificacion.AddCell(Cadena); PdfPCell CellCertificacion = new PdfPCell(TableCertificacion); CellCertificacion.Padding = 3; CellCertificacion.Border = Rectangle.BOTTOM_BORDER; CellCertificacion.BorderColor = new Color(62, 84, 84); CellCertificacion.BorderWidth = 1.3f; FooterTopLeft.AddCell(CellCertificacion); PdfPCell CellFooterTopLeft = new PdfPCell(FooterTopLeft); CellFooterTopLeft.Border = 0; CellFooterTopLeft.MinimumHeight = 68.031496063f; TableFooterTop.AddCell(CellFooterTopLeft); PdfPTable FooterTopRight = new PdfPTable(2); FooterTopRight.DefaultCell.Border = 0; float[] WidthsFooterTopRight = new float[] { 53.858267717f, 167.244094488f }; FooterTopRight.SetWidths(WidthsFooterTopRight); PdfPCell TextoSubtotal = new PdfPCell(new Phrase("Subtotal", Verdana9)); TextoSubtotal.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextoSubtotal.VerticalAlignment = Rectangle.ALIGN_MIDDLE; TextoSubtotal.Border = 0; FooterTopRight.AddCell(TextoSubtotal); PdfPCell Subtotal = new PdfPCell(new Phrase("$" + comprobante.SubTotal.ToString("#,##0.00"), Verdana9)); Subtotal.HorizontalAlignment = Rectangle.ALIGN_CENTER; Subtotal.VerticalAlignment = Rectangle.ALIGN_MIDDLE; Subtotal.Border = 0; FooterTopRight.AddCell(Subtotal); PdfPCell TextoIVA = new PdfPCell(new Phrase("16 % IVA", Verdana9)); TextoIVA.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextoIVA.VerticalAlignment = Rectangle.ALIGN_MIDDLE; TextoIVA.Border = 0; FooterTopRight.AddCell(TextoIVA); PdfPCell IVA = new PdfPCell(new Phrase("$" + comprobante.Impuestos.TotalImpuestosTrasladados.Value.ToString("#,##0.00"), Verdana9)); IVA.HorizontalAlignment = Rectangle.ALIGN_CENTER; IVA.VerticalAlignment = Rectangle.ALIGN_MIDDLE; IVA.Border = 0; FooterTopRight.AddCell(IVA); PdfPCell TextoTotal = new PdfPCell(new Phrase("Total", Verdana9)); TextoTotal.HorizontalAlignment = Rectangle.ALIGN_CENTER; TextoTotal.VerticalAlignment = Rectangle.ALIGN_MIDDLE; TextoTotal.Border = 0; FooterTopRight.AddCell(TextoTotal); PdfPCell Total = new PdfPCell(new Phrase("$" + comprobante.Total.ToString("#,##0.00"), Verdana9)); Total.HorizontalAlignment = Rectangle.ALIGN_CENTER; Total.VerticalAlignment = Rectangle.ALIGN_MIDDLE; Total.Border = 0; FooterTopRight.AddCell(Total); PdfPTable TableTotalLetra = new PdfPTable(2); CantidadEnLetraConverter letraConverter = new CantidadEnLetraConverter(); letraConverter.Numero = comprobante.Total; //this.TotalLetra = letraConverter.letra(); //PdfPCell CellTableLetra = new PdfPCell(new Phrase(SATManager.GetImporteConLetra(comprobante.Total) + " M.N", VerdanaBold7Color)); PdfPCell CellTableLetra = new PdfPCell(new Phrase(letraConverter.letra() + " M.N", VerdanaBold7Color)); CellTableLetra.Colspan = 2; CellTableLetra.HorizontalAlignment = Rectangle.ALIGN_CENTER; CellTableLetra.VerticalAlignment = Rectangle.ALIGN_MIDDLE; CellTableLetra.Border = Rectangle.TOP_BORDER; CellTableLetra.BorderColor = new Color(62, 84, 84); CellTableLetra.BorderWidth = 1.3f; TableTotalLetra.AddCell(CellTableLetra); PdfPCell TotalLetra = new PdfPCell(TableTotalLetra); TotalLetra.Border = Rectangle.BOTTOM_BORDER; TotalLetra.BorderColor = new Color(62, 84, 84); TotalLetra.BorderWidth = 1.3f; TotalLetra.Colspan = 2; TotalLetra.PaddingTop = 3; TotalLetra.PaddingLeft = 3; FooterTopRight.AddCell(TotalLetra); PdfPCell CellFooterTopRight = new PdfPCell(FooterTopRight); CellFooterTopRight.MinimumHeight = 68.031496063f; CellFooterTopRight.Border = Rectangle.LEFT_BORDER; CellFooterTopRight.BorderColor = new Color(62, 84, 84); CellFooterTopRight.BorderWidth = 1.3f; TableFooterTop.AddCell(CellFooterTopRight); FooterRight.AddCell(TableFooterTop); PdfPTable TableFooterBottom = new PdfPTable(2); float[] WidhtsFooterBottom = new float[] { 92.125984252f, 328.818897638f }; TableFooterBottom.SetWidths(WidhtsFooterBottom); PdfPTable FooterBottomLeft = new PdfPTable(1); ///QRCODE /// if (!String.IsNullOrEmpty(comprobante.GetQrCode())) { Byte[] QRCODEBase64 = Convert.FromBase64String(comprobante.GetQrCode()); Image QRCODEImage = iTextSharp.text.Image.GetInstance(QRCODEBase64); QRCODEImage.ScaleAbsoluteWidth(76.535433071f); QRCODEImage.ScaleAbsoluteHeight(76.535433071f); PdfPCell CellFooterBottomLeft = new PdfPCell(QRCODEImage, false); CellFooterBottomLeft.MinimumHeight = 85.039370079f; CellFooterBottomLeft.HorizontalAlignment = Rectangle.ALIGN_CENTER; CellFooterBottomLeft.VerticalAlignment = Rectangle.ALIGN_MIDDLE; CellFooterBottomLeft.Border = Rectangle.RIGHT_BORDER; CellFooterBottomLeft.BorderColor = new Color(62, 84, 84); CellFooterBottomLeft.BorderWidth = 1.3f; TableFooterBottom.AddCell(CellFooterBottomLeft); } else { TableFooterBottom.AddCell(""); } PdfPTable TableRightFooter = new PdfPTable(1); string PhraseCertificadoSAT = ""; if (comprobante.Status.Equals("A")) { foreach (var complemento in comprobante.Complementos) { if (complemento is TimbreFiscalDigital) { TimbreFiscalDigital timbre = (TimbreFiscalDigital)complemento; if (!String.IsNullOrEmpty(timbre.NoCertificadoSAT)) { PhraseCertificadoSAT = timbre.NoCertificadoSAT.ToString(); } } } //if (!String.IsNullOrEmpty(comprobante.Complemento.TimbreFiscalDigital.NoCertificadoSAT)) //{ // PhraseCertificadoSAT = comprobante.Complemento.TimbreFiscalDigital.NoCertificadoSAT.ToString(); //} } PdfPCell Certificado = new PdfPCell(new Phrase("Certificado SAT: " + PhraseCertificadoSAT, VerdanaBold9Color)); Certificado.HorizontalAlignment = Rectangle.ALIGN_CENTER; Certificado.VerticalAlignment = Rectangle.ALIGN_CENTER; Certificado.Border = 0; Certificado.PaddingTop = 0; TableRightFooter.AddCell(Certificado); TableRightFooter.AddCell(Espacio1); PdfPCell Sellos = new PdfPCell(new Phrase("Sellos Digitales", VerdanaBold9Color)); Sellos.HorizontalAlignment = Rectangle.ALIGN_CENTER; Sellos.VerticalAlignment = Rectangle.ALIGN_MIDDLE; Sellos.Padding = 3; Sellos.Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER; Sellos.BorderColor = new Color(62, 84, 84); Sellos.BorderWidth = 1.3f; TableRightFooter.AddCell(Sellos); PdfPCell SelloCFD = new PdfPCell(new Phrase("Sello CFDI: " + comprobante.Sello, Verdana5)); SelloCFD.HorizontalAlignment = Rectangle.ALIGN_CENTER; SelloCFD.VerticalAlignment = Rectangle.ALIGN_MIDDLE; SelloCFD.Padding = 3; SelloCFD.Border = 0; TableRightFooter.AddCell(SelloCFD); string PhraseSelloSat = ""; if (comprobante.Status.Equals("A")) { foreach (var complemento in comprobante.Complementos) { if (complemento is TimbreFiscalDigital) { TimbreFiscalDigital timbre = (TimbreFiscalDigital)complemento; if (!String.IsNullOrEmpty(timbre.SelloSAT)) { PhraseSelloSat = timbre.SelloSAT.ToString(); } } } } PdfPCell SelloSAT = new PdfPCell(new Phrase("Sello SAT: " + PhraseSelloSat, Verdana5)); SelloSAT.HorizontalAlignment = Rectangle.ALIGN_CENTER; SelloSAT.VerticalAlignment = Rectangle.ALIGN_MIDDLE; SelloSAT.Padding = 3; SelloSAT.Border = Rectangle.BOTTOM_BORDER; SelloSAT.BorderColor = new Color(62, 84, 84); SelloSAT.BorderWidth = 1.3f; TableRightFooter.AddCell(SelloSAT); TableRightFooter.AddCell(Espacio1); PdfPCell Leyenda = new PdfPCell(new Phrase("Este documento es una representación impresa de un CFDI.", VerdanaBold9Color)); Leyenda.HorizontalAlignment = Rectangle.ALIGN_CENTER; Leyenda.VerticalAlignment = Rectangle.ALIGN_MIDDLE; Leyenda.Padding = 0; Leyenda.Border = 0; TableRightFooter.AddCell(Leyenda); PdfPCell CellFooterBottomRight = new PdfPCell(TableRightFooter); CellFooterBottomRight.Padding = 4; CellFooterBottomRight.Border = 0; CellFooterTopRight.MinimumHeight = 68.031496063f; TableFooterBottom.AddCell(CellFooterBottomRight); FooterRight.AddCell(TableFooterBottom); Footer.AddCell(FooterRight); PdfPCell CellFooter = new PdfPCell(Footer); CellFooter.BorderColor = new Color(62, 84, 84); CellFooter.BorderWidth = 2; MainTable.AddCell(CellFooter); document.Add(MainTable); if (comprobante.Status.ToString().Equals("C")) { string urlImage = HttpContext.Current.Server.MapPath("~/Content/Invoice/cancelado.png"); Image watermark2 = Image.GetInstance(urlImage); watermark2.SetAbsolutePosition(120, 300); document.Add(watermark2); } writer.CloseStream = false; document.Close(); outputStream.Flush(); outputStream.Position = 0; return(outputStream); //throw new NotImplementedException(); } catch (Exception ex) { ex.Message.ToString(); return(null); } }
/** * Draws a horizontal line. * @param canvas the canvas to draw on * @param leftX the left x coordinate * @param rightX the right x coordindate * @param y the y coordinate */ virtual public void DrawLine(PdfContentByte canvas, float leftX, float rightX, float y) { float w; if (Percentage < 0) w = -Percentage; else w = (rightX - leftX) * Percentage / 100.0f; float s; switch (Alignment) { case Element.ALIGN_LEFT: s = 0; break; case Element.ALIGN_RIGHT: s = rightX - leftX - w; break; default: s = (rightX - leftX - w) / 2; break; } canvas.SetLineWidth(LineWidth); if (LineColor != null) canvas.SetColorStroke(LineColor); canvas.MoveTo(s + leftX, y + offset); canvas.LineTo(s + w + leftX, y + offset); canvas.Stroke(); }
/// <summary> /// Takes care of the page header and footer. Updates the paging information if needed. /// </summary> /// <param name="writer"></param> /// <param name="document"></param> public override void OnEndPage(PdfWriter writer, Document document) { base.OnEndPage(writer, document); Phrase p1Header = new Phrase(m_cfg.HeaderText, m_cfg.HeaderBigFont); if (m_cfg.HasLogo()) { // Here add a possibility for the configuration to have the logo as a memory image // I think the automated builder will require it m_logo = Image.GetInstance(m_cfg.LogoUrl); if (m_logo != null) { m_logo.ScaleToFit(150, 100); } } // paging String pagingText = "Page " + writer.PageNumber + " of "; float pagingFixedLen = m_cfg.HeaderPagingFont.GetWidthPoint(pagingText, m_cfg.PagingFontSize); float paging999Len = m_cfg.HeaderPagingFont.GetWidthPoint("999", m_cfg.PagingFontSize); if (m_cfg.PagingInHeader) { // adds "nn" in "Page 1 of nn" float x = document.PageSize.GetRight(document.RightMargin + pagingFixedLen + paging999Len); float y = document.PageSize.GetTop(45); m_cb.BeginText(); m_cb.SetFontAndSize(m_cfg.HeaderPagingFont, m_cfg.PagingFontSize); m_cb.SetTextMatrix(x, y); m_cb.ShowText(pagingText); m_cb.EndText(); m_cb.AddTemplate(m_headerTemplate, x + pagingFixedLen, y); } if (m_cfg.PagingInFooter) { // adds "nn" in "Page 1 of nn" float x = document.LeftMargin; float y = document.PageSize.GetBottom(30); m_cb.BeginText(); m_cb.SetFontAndSize(m_cfg.HeaderPagingFont, m_cfg.PagingFontSize); m_cb.SetTextMatrix(x, y); m_cb.ShowText(pagingText); m_cb.EndText(); m_cb.AddTemplate(m_footerTemplate, x + pagingFixedLen, y); } // header row 1 PdfPCell cell1Logo = m_logo != null ? new PdfPCell(m_logo) : new PdfPCell(); PdfPCell cell2Header = new PdfPCell(p1Header); PdfPCell cell3 = new PdfPCell(); // header row 2 PdfPCell cell456Subheader = new PdfPCell(new Phrase(m_cfg.SubheaderText, m_cfg.HeaderNormalFont)); // header row 3 PdfPCell cell7Date = new PdfPCell(); PdfPCell cell8 = new PdfPCell(new Phrase("Created on: " + m_cfg.ReportCreationDateTime.ToString(CultureInfo.InvariantCulture), m_cfg.HeaderDateFont)); PdfPCell cell9Time = new PdfPCell(); // set the alignment of all three cells and set border to 0 cell1Logo.HorizontalAlignment = Element.ALIGN_LEFT; cell2Header.HorizontalAlignment = Element.ALIGN_CENTER; cell3.HorizontalAlignment = Element.ALIGN_RIGHT; cell456Subheader.HorizontalAlignment = Element.ALIGN_CENTER; cell7Date.HorizontalAlignment = Element.ALIGN_LEFT; cell8.HorizontalAlignment = Element.ALIGN_CENTER; cell9Time.HorizontalAlignment = Element.ALIGN_RIGHT; cell2Header.VerticalAlignment = Element.ALIGN_BOTTOM; cell3.VerticalAlignment = Element.ALIGN_MIDDLE; cell456Subheader.VerticalAlignment = Element.ALIGN_TOP; cell7Date.VerticalAlignment = Element.ALIGN_MIDDLE; cell8.VerticalAlignment = Element.ALIGN_MIDDLE; cell9Time.VerticalAlignment = Element.ALIGN_MIDDLE; cell456Subheader.Colspan = 3; cell1Logo.Border = 0; cell2Header.Border = 0; cell3.Border = 0; cell456Subheader.Border = 0; cell7Date.Border = 0; cell8.Border = 0; cell9Time.Border = 0; // add all cells into the header table PdfPTable headerTable = new PdfPTable(3); headerTable.AddCell(cell1Logo); headerTable.AddCell(cell2Header); headerTable.AddCell(cell3); headerTable.AddCell(cell456Subheader); // full row headerTable.AddCell(cell7Date); headerTable.AddCell(cell8); headerTable.AddCell(cell9Time); headerTable.TotalWidth = document.PageSize.Width - 80f; float[] colWidths = new float[] { 50, 80, 50 }; headerTable.SetWidths(colWidths); //headerTable.WidthPercentage = 70; //pdfTab.HorizontalAlignment = Element.ALIGN_CENTER; // This writes rows from PdfWriter in PdfTable // The first param is start row. -1 indicates there is no end row and all the rows to be included to write // Third and fourth params are x and y position to start writing headerTable.WriteSelectedRows(0, -1, 40, document.PageSize.Height - 30, writer.DirectContent); //// add all cells into the footer table //PdfPTable footerTable = new PdfPTable(1); //footerTable.TotalWidth = document.PageSize.Width - 80f; //PdfPCell cellrundate = new PdfPCell(new Phrase("Run Date: xxxxxx")); //cellrundate.VerticalAlignment = Element.ALIGN_MIDDLE; //cellrundate.HorizontalAlignment = Element.ALIGN_RIGHT; //footerTable.AddCell(cellrundate); //footerTable.WriteSelectedRows(0, -1, 40, document.PageSize.GetBottom(50), writer.DirectContent); if (m_cfg.TopSeparatorLine) { // moves the pointer and draws a line to separate header section from rest of page m_cb.MoveTo(40, document.PageSize.Height - 100); //was 100 m_cb.LineTo(document.PageSize.Width - 40, document.PageSize.Height - 100); //was100 m_cb.Stroke(); } if (m_cfg.BottomSeparatorLine) { // moves the pointer and draws a line to separate footer section from rest of page m_cb.MoveTo(40, document.PageSize.GetBottom(50)); m_cb.LineTo(document.PageSize.Width - 40, document.PageSize.GetBottom(50)); m_cb.Stroke(); } }
public static void PageShapes(Document pdf, PdfWriter writer) { PdfContentByte cb = writer.DirectContent; // LINES var title = new Paragraph("Lines", new Font(Font.HELVETICA, 20, Font.BOLD + Font.UNDERLINE)); pdf.Add(title); cb.SetLineWidth(5); cb.SetColorStroke(new BaseColor(0, 140, 180)); cb.MoveTo(40f, InverseY(120f)); cb.LineTo(200f, InverseY(120f)); cb.Stroke(); cb.SetColorStroke(new BaseColor(10, 180, 80)); cb.SetLineDash(20f, 10f); cb.MoveTo(40f, InverseY(140f)); cb.LineTo(200f, InverseY(140f)); cb.Stroke(); // Reset cb.SetLineWidth(1); cb.SetLineDash(0); cb.SetColorStroke(new BaseColor(0, 0, 0)); // SHAPES ColumnText ct = new ColumnText(cb); Phrase ctitle = new Phrase("Shapes", new Font(Font.HELVETICA, 20, Font.BOLD + Font.UNDERLINE)); ct.SetSimpleColumn(ctitle, 40f, 0, 580, InverseY(170f), 15, Element.ALIGN_LEFT); //lower-left-x //lower-left-y //upper-right-x(llx + width) //upper-right-y(lly + height) //leading(The amount of blank space between lines of print) ct.Go(); //title = new Paragraph("Shapes", new Font(Font.HELVETICA, 20, Font.BOLD + Font.UNDERLINE)); //pdf.Add(title); cb.Rectangle(40f, InverseY(200f), 120f, -50f); cb.Stroke(); cb.SetColorStroke(BaseColor.Red); cb.Circle(200f, InverseY(230f), 30f); cb.Stroke(); cb.SaveState(); { PdfGState gs = new PdfGState(); gs.FillOpacity = 0.5f; cb.SetGState(gs); cb.SetColorFill(BaseColor.Green); cb.Circle(220f, InverseY(240f), 30f); cb.Fill(); } cb.RestoreState(); cb.SetColorStroke(BaseColor.Blue); cb.Arc(300f, InverseY(220f), 360f, InverseY(280f), 45, 270); cb.Stroke(); // }
/** * Writes a text line to the document. It takes care of all the attributes. * <P> * Before entering the line position must have been established and the * <CODE>text</CODE> argument must be in text object scope (<CODE>beginText()</CODE>). * @param line the line to be written * @param text the <CODE>PdfContentByte</CODE> where the text will be written to * @param graphics the <CODE>PdfContentByte</CODE> where the graphics will be written to * @param currentValues the current font and extra spacing values * @param ratio * @throws DocumentException on error */ internal void WriteLineToContent(PdfLine line, PdfContentByte text, PdfContentByte graphics, Object[] currentValues, float ratio) { PdfFont currentFont = (PdfFont)(currentValues[0]); float lastBaseFactor = (float)currentValues[1]; //PdfChunk chunkz; int numberOfSpaces; int lineLen; bool isJustified; float hangingCorrection = 0; float hScale = 1; float lastHScale = float.NaN; float baseWordSpacing = 0; float baseCharacterSpacing = 0; float glueWidth = 0; numberOfSpaces = line.NumberOfSpaces; lineLen = line.GetLineLengthUtf32(); // does the line need to be justified? isJustified = line.HasToBeJustified() && (numberOfSpaces != 0 || lineLen > 1); int separatorCount = line.GetSeparatorCount(); if (separatorCount > 0) { glueWidth = line.WidthLeft / separatorCount; } else if (isJustified) { if (line.NewlineSplit && line.WidthLeft >= (lastBaseFactor * (ratio * numberOfSpaces + lineLen - 1))) { if (line.RTL) { text.MoveText(line.WidthLeft - lastBaseFactor * (ratio * numberOfSpaces + lineLen - 1), 0); } baseWordSpacing = ratio * lastBaseFactor; baseCharacterSpacing = lastBaseFactor; } else { float width = line.WidthLeft; PdfChunk last = line.GetChunk(line.Size - 1); if (last != null) { String s = last.ToString(); char c; if (s.Length > 0 && hangingPunctuation.IndexOf((c = s[s.Length - 1])) >= 0) { float oldWidth = width; width += last.Font.Width(c) * 0.4f; hangingCorrection = width - oldWidth; } } float baseFactor = width / (ratio * numberOfSpaces + lineLen - 1); baseWordSpacing = ratio * baseFactor; baseCharacterSpacing = baseFactor; lastBaseFactor = baseFactor; } } int lastChunkStroke = line.LastStrokeChunk; int chunkStrokeIdx = 0; float xMarker = text.XTLM; float baseXMarker = xMarker; float yMarker = text.YTLM; bool adjustMatrix = false; float tabPosition = 0; // looping over all the chunks in 1 line foreach (PdfChunk chunk in line) { Color color = chunk.Color; hScale = 1; if (chunkStrokeIdx <= lastChunkStroke) { float width; if (isJustified) { width = chunk.GetWidthCorrected(baseCharacterSpacing, baseWordSpacing); } else { width = chunk.Width; } if (chunk.IsStroked()) { PdfChunk nextChunk = line.GetChunk(chunkStrokeIdx + 1); if (chunk.IsSeparator()) { width = glueWidth; Object[] sep = (Object[])chunk.GetAttribute(Chunk.SEPARATOR); IDrawInterface di = (IDrawInterface)sep[0]; bool vertical = (bool)sep[1]; float fontSize = chunk.Font.Size; float ascender = chunk.Font.Font.GetFontDescriptor(BaseFont.ASCENT, fontSize); float descender = chunk.Font.Font.GetFontDescriptor(BaseFont.DESCENT, fontSize); if (vertical) { di.Draw(graphics, baseXMarker, yMarker + descender, baseXMarker + line.OriginalWidth, ascender - descender, yMarker); } else { di.Draw(graphics, xMarker, yMarker + descender, xMarker + width, ascender - descender, yMarker); } } if (chunk.IsTab()) { Object[] tab = (Object[])chunk.GetAttribute(Chunk.TAB); IDrawInterface di = (IDrawInterface)tab[0]; tabPosition = (float)tab[1] + (float)tab[3]; float fontSize = chunk.Font.Size; float ascender = chunk.Font.Font.GetFontDescriptor(BaseFont.ASCENT, fontSize); float descender = chunk.Font.Font.GetFontDescriptor(BaseFont.DESCENT, fontSize); if (tabPosition > xMarker) { di.Draw(graphics, xMarker, yMarker + descender, tabPosition, ascender - descender, yMarker); } float tmp = xMarker; xMarker = tabPosition; tabPosition = tmp; } if (chunk.IsAttribute(Chunk.BACKGROUND)) { float subtract = lastBaseFactor; if (nextChunk != null && nextChunk.IsAttribute(Chunk.BACKGROUND)) subtract = 0; if (nextChunk == null) subtract += hangingCorrection; float fontSize = chunk.Font.Size; float ascender = chunk.Font.Font.GetFontDescriptor(BaseFont.ASCENT, fontSize); float descender = chunk.Font.Font.GetFontDescriptor(BaseFont.DESCENT, fontSize); Object[] bgr = (Object[])chunk.GetAttribute(Chunk.BACKGROUND); graphics.SetColorFill((Color)bgr[0]); float[] extra = (float[])bgr[1]; graphics.Rectangle(xMarker - extra[0], yMarker + descender - extra[1] + chunk.TextRise, width - subtract + extra[0] + extra[2], ascender - descender + extra[1] + extra[3]); graphics.Fill(); graphics.SetGrayFill(0); } if (chunk.IsAttribute(Chunk.UNDERLINE)) { float subtract = lastBaseFactor; if (nextChunk != null && nextChunk.IsAttribute(Chunk.UNDERLINE)) subtract = 0; if (nextChunk == null) subtract += hangingCorrection; Object[][] unders = (Object[][])chunk.GetAttribute(Chunk.UNDERLINE); Color scolor = null; for (int k = 0; k < unders.Length; ++k) { Object[] obj = unders[k]; scolor = (Color)obj[0]; float[] ps = (float[])obj[1]; if (scolor == null) scolor = color; if (scolor != null) graphics.SetColorStroke(scolor); float fsize = chunk.Font.Size; graphics.SetLineWidth(ps[0] + fsize * ps[1]); float shift = ps[2] + fsize * ps[3]; int cap2 = (int)ps[4]; if (cap2 != 0) graphics.SetLineCap(cap2); graphics.MoveTo(xMarker, yMarker + shift); graphics.LineTo(xMarker + width - subtract, yMarker + shift); graphics.Stroke(); if (scolor != null) graphics.ResetGrayStroke(); if (cap2 != 0) graphics.SetLineCap(0); } graphics.SetLineWidth(1); } if (chunk.IsAttribute(Chunk.ACTION)) { float subtract = lastBaseFactor; if (nextChunk != null && nextChunk.IsAttribute(Chunk.ACTION)) subtract = 0; if (nextChunk == null) subtract += hangingCorrection; text.AddAnnotation(new PdfAnnotation(writer, xMarker, yMarker, xMarker + width - subtract, yMarker + chunk.Font.Size, (PdfAction)chunk.GetAttribute(Chunk.ACTION))); } if (chunk.IsAttribute(Chunk.REMOTEGOTO)) { float subtract = lastBaseFactor; if (nextChunk != null && nextChunk.IsAttribute(Chunk.REMOTEGOTO)) subtract = 0; if (nextChunk == null) subtract += hangingCorrection; Object[] obj = (Object[])chunk.GetAttribute(Chunk.REMOTEGOTO); String filename = (String)obj[0]; if (obj[1] is String) RemoteGoto(filename, (String)obj[1], xMarker, yMarker, xMarker + width - subtract, yMarker + chunk.Font.Size); else RemoteGoto(filename, (int)obj[1], xMarker, yMarker, xMarker + width - subtract, yMarker + chunk.Font.Size); } if (chunk.IsAttribute(Chunk.LOCALGOTO)) { float subtract = lastBaseFactor; if (nextChunk != null && nextChunk.IsAttribute(Chunk.LOCALGOTO)) subtract = 0; if (nextChunk == null) subtract += hangingCorrection; LocalGoto((String)chunk.GetAttribute(Chunk.LOCALGOTO), xMarker, yMarker, xMarker + width - subtract, yMarker + chunk.Font.Size); } if (chunk.IsAttribute(Chunk.LOCALDESTINATION)) { float subtract = lastBaseFactor; if (nextChunk != null && nextChunk.IsAttribute(Chunk.LOCALDESTINATION)) subtract = 0; if (nextChunk == null) subtract += hangingCorrection; LocalDestination((String)chunk.GetAttribute(Chunk.LOCALDESTINATION), new PdfDestination(PdfDestination.XYZ, xMarker, yMarker + chunk.Font.Size, 0)); } if (chunk.IsAttribute(Chunk.GENERICTAG)) { float subtract = lastBaseFactor; if (nextChunk != null && nextChunk.IsAttribute(Chunk.GENERICTAG)) subtract = 0; if (nextChunk == null) subtract += hangingCorrection; Rectangle rect = new Rectangle(xMarker, yMarker, xMarker + width - subtract, yMarker + chunk.Font.Size); IPdfPageEvent pev = writer.PageEvent; if (pev != null) pev.OnGenericTag(writer, this, rect, (String)chunk.GetAttribute(Chunk.GENERICTAG)); } if (chunk.IsAttribute(Chunk.PDFANNOTATION)) { float subtract = lastBaseFactor; if (nextChunk != null && nextChunk.IsAttribute(Chunk.PDFANNOTATION)) subtract = 0; if (nextChunk == null) subtract += hangingCorrection; float fontSize = chunk.Font.Size; float ascender = chunk.Font.Font.GetFontDescriptor(BaseFont.ASCENT, fontSize); float descender = chunk.Font.Font.GetFontDescriptor(BaseFont.DESCENT, fontSize); PdfAnnotation annot = PdfFormField.ShallowDuplicate((PdfAnnotation)chunk.GetAttribute(Chunk.PDFANNOTATION)); annot.Put(PdfName.RECT, new PdfRectangle(xMarker, yMarker + descender, xMarker + width - subtract, yMarker + ascender)); text.AddAnnotation(annot); } float[] paramsx = (float[])chunk.GetAttribute(Chunk.SKEW); object hs = chunk.GetAttribute(Chunk.HSCALE); if (paramsx != null || hs != null) { float b = 0, c = 0; if (paramsx != null) { b = paramsx[0]; c = paramsx[1]; } if (hs != null) hScale = (float)hs; text.SetTextMatrix(hScale, b, c, 1, xMarker, yMarker); } if (chunk.IsImage()) { Image image = chunk.Image; float[] matrix = image.Matrix; matrix[Image.CX] = xMarker + chunk.ImageOffsetX - matrix[Image.CX]; matrix[Image.CY] = yMarker + chunk.ImageOffsetY - matrix[Image.CY]; graphics.AddImage(image, matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]); text.MoveText(xMarker + lastBaseFactor + image.ScaledWidth - text.XTLM, 0); } } xMarker += width; ++chunkStrokeIdx; } if (chunk.Font.CompareTo(currentFont) != 0) { currentFont = chunk.Font; text.SetFontAndSize(currentFont.Font, currentFont.Size); } float rise = 0; Object[] textRender = (Object[])chunk.GetAttribute(Chunk.TEXTRENDERMODE); int tr = 0; float strokeWidth = 1; Color strokeColor = null; object fr = chunk.GetAttribute(Chunk.SUBSUPSCRIPT); if (textRender != null) { tr = (int)textRender[0] & 3; if (tr != PdfContentByte.TEXT_RENDER_MODE_FILL) text.SetTextRenderingMode(tr); if (tr == PdfContentByte.TEXT_RENDER_MODE_STROKE || tr == PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE) { strokeWidth = (float)textRender[1]; if (strokeWidth != 1) text.SetLineWidth(strokeWidth); strokeColor = (Color)textRender[2]; if (strokeColor == null) strokeColor = color; if (strokeColor != null) text.SetColorStroke(strokeColor); } } if (fr != null) rise = (float)fr; if (color != null) text.SetColorFill(color); if (rise != 0) text.SetTextRise(rise); if (chunk.IsImage()) { adjustMatrix = true; } else if (chunk.IsHorizontalSeparator()) { PdfTextArray array = new PdfTextArray(); array.Add(-glueWidth * 1000f / chunk.Font.Size / hScale); text.ShowText(array); } else if (chunk.IsTab()) { PdfTextArray array = new PdfTextArray(); array.Add((tabPosition - xMarker) * 1000f / chunk.Font.Size / hScale); text.ShowText(array); } // If it is a CJK chunk or Unicode TTF we will have to simulate the // space adjustment. else if (isJustified && numberOfSpaces > 0 && chunk.IsSpecialEncoding()) { if (hScale != lastHScale) { lastHScale = hScale; text.SetWordSpacing(baseWordSpacing / hScale); text.SetCharacterSpacing(baseCharacterSpacing / hScale); } String s = chunk.ToString(); int idx = s.IndexOf(' '); if (idx < 0) text.ShowText(s); else { float spaceCorrection = - baseWordSpacing * 1000f / chunk.Font.Size / hScale; PdfTextArray textArray = new PdfTextArray(s.Substring(0, idx)); int lastIdx = idx; while ((idx = s.IndexOf(' ', lastIdx + 1)) >= 0) { textArray.Add(spaceCorrection); textArray.Add(s.Substring(lastIdx, idx - lastIdx)); lastIdx = idx; } textArray.Add(spaceCorrection); textArray.Add(s.Substring(lastIdx)); text.ShowText(textArray); } } else { if (isJustified && hScale != lastHScale) { lastHScale = hScale; text.SetWordSpacing(baseWordSpacing / hScale); text.SetCharacterSpacing(baseCharacterSpacing / hScale); } text.ShowText(chunk.ToString()); } if (rise != 0) text.SetTextRise(0); if (color != null) text.ResetRGBColorFill(); if (tr != PdfContentByte.TEXT_RENDER_MODE_FILL) text.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL); if (strokeColor != null) text.ResetRGBColorStroke(); if (strokeWidth != 1) text.SetLineWidth(1); if (chunk.IsAttribute(Chunk.SKEW) || chunk.IsAttribute(Chunk.HSCALE)) { adjustMatrix = true; text.SetTextMatrix(xMarker, yMarker); } } if (isJustified) { text.SetWordSpacing(0); text.SetCharacterSpacing(0); if (line.NewlineSplit) lastBaseFactor = 0; } if (adjustMatrix) text.MoveText(baseXMarker - text.XTLM, 0); currentValues[0] = currentFont; currentValues[1] = lastBaseFactor; }
public void CreatePdf(DataGridView view, string ulica, string mjesto, string oib, int brponude) { Form1 f = new Form1(); crud.PopunjavanjeTrgovinePdf(f.GetTrgovina[0]); int row = 0; string kupac = view.Rows[0].Cells["Kupac"].Value.ToString(); Document document = new Document(PageSize.A4, 25, 25, 30, 1); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("D:\\Posao\\Ponude\\Ponuda_" + kupac + "_" + brponude + ".pdf", FileMode.Create)); int page = 1; // otvara doc za upisivanje u njega document.Open(); // omogućava upisivanje texta // po X & Y parametrima. PdfContentByte cb = writer.DirectContent; // dodajemo footer cb.AddTemplate(PdfFooter(cb, page), 30, 1); // dodavanje slike /* iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance(Server.MapPath("mbase_emc2.png")); * png.ScaleAbsolute(200, 55); * png.SetAbsolutePosition(40, 750); * cb.AddImage(png);*/ // prvo omogućimo pisanje texta cb.BeginText(); // Naslovni dio writeText(cb, crud.GetTrgovina[0], 350, 820, f_cb, 14); writeText(cb, "OiB:", 350, 800, f_cb, 10); writeText(cb, Convert.ToString(crud.GetOib[0]), 420, 800, f_cn, 10); writeText(cb, "IBAN:", 350, 788, f_cb, 10); writeText(cb, crud.GetIban[0], 420, 788, f_cn, 10); writeText(cb, "Adresa:", 350, 776, f_cb, 10); writeText(cb, Convert.ToString(crud.GetUlicaTrg[0]), 420, 776, f_cn, 10); writeText(cb, "Mjesto:", 350, 764, f_cb, 10); writeText(cb, crud.GetMjesto[0], 420, 764, f_cn, 10); writeText(cb, "Mob Tel:", 350, 752, f_cb, 10); writeText(cb, crud.GetMob[0], 420, 752, f_cn, 10); // text primatelja pošiljeke int left_margin = 40; int top_margin = 720; writeText(cb, "Br. ponude: " + brponude, left_margin, top_margin, f_cb, 10); DateTime localDate = DateTime.Now; writeText(cb, "Datum: " + localDate.ToString("dd.MM.yyyy"), left_margin, top_margin - 12, f_cb, 10); writeText(cb, "Dostava: ", left_margin, top_margin - 24, f_cb, 10); writeText(cb, kupac, left_margin, top_margin - 36, f_cn, 10); writeText(cb, ulica, left_margin, top_margin - 48, f_cn, 10); writeText(cb, mjesto, left_margin, top_margin - 60, f_cn, 10); // Podatci kupca left_margin = 40; top_margin = 620; writeText(cb, "Kupac", left_margin, top_margin, f_cb, 10); writeText(cb, kupac, left_margin, top_margin - 12, f_cn, 10); writeText(cb, "Ulica i k.br", left_margin + 100, top_margin, f_cb, 10); writeText(cb, ulica, left_margin + 100, top_margin - 12, f_cn, 10); writeText(cb, "Mjesto", left_margin + 200, top_margin, f_cb, 10); writeText(cb, mjesto, left_margin + 200, top_margin - 12, f_cn, 10); writeText(cb, "Oib", left_margin + 300, top_margin, f_cb, 10); writeText(cb, oib, left_margin + 300, top_margin - 12, f_cn, 10); // ispod sljedeće dodavanje artikala left_margin = 40; top_margin = 575; writeText(cb, "Stavke", left_margin, top_margin, f_cb, 10); // endtext se dodaje prije dodavanja grafičkog djela cb.EndText(); // odvajanje crtom s parametrima pozicije i veličine crte cb.SetLineWidth(0f); cb.MoveTo(40, 570); cb.LineTo(560, 570); cb.Stroke(); // ponovno omogućavanje upisivanje texta cb.BeginText(); // kritična točka gdje ćemo odvajat novu stranicu int lastwriteposition = 100; // naslovi tablice top_margin = 550; left_margin = 40; writeText(cb, "Šifra", left_margin, top_margin, f_cb, 10); writeText(cb, "Naziv robe", left_margin + 70, top_margin, f_cb, 10); writeText(cb, "J.mj.", left_margin + 280, top_margin, f_cb, 10); writeText(cb, "Kolicina", left_margin + 310, top_margin, f_cb, 10); writeText(cb, "PDV %", left_margin + 355, top_margin, f_cb, 10); writeText(cb, "Cijena", left_margin + 395, top_margin, f_cb, 10); writeText(cb, "Popust", left_margin + 435, top_margin, f_cb, 10); writeText(cb, "Iznos", left_margin + 480, top_margin, f_cb, 10); // prvi item počine odavdje top_margin = 538; // loopanje predmeta i upisivanje decimal zaPlatit = 0, sPorezom = 0, bezPoreza = 0, cijenaSamogPoreza = 0; for (int i = 1; i < view.Rows.Count; i++) { writeText(cb, view.Rows[row].Cells["Sifra"].Value.ToString(), left_margin, top_margin, f_cn, 10); if (view.Rows[row].Cells["Naziv"].Value.ToString().Length > 20) { writeText(cb, view.Rows[row].Cells["Naziv"].Value.ToString(), left_margin + 70, top_margin, f_cn, 8); cb.SetFontAndSize(f_cn, 10); } else { writeText(cb, view.Rows[row].Cells["Naziv"].Value.ToString(), left_margin + 70, top_margin, f_cn, 10); } cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, view.Rows[row].Cells["Jm"].Value.ToString(), left_margin + 280, top_margin, 0); string kol = view.Rows[row].Cells["Kolicina"].Value.ToString(); decimal kolicina = Convert.ToDecimal(kol); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, kol, left_margin + (310 + 15), top_margin, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, view.Rows[row].Cells["Porez"].Value.ToString(), left_margin + (355 + 3), top_margin, 0); string pocCijena = view.Rows[row].Cells["Cijena"].Value.ToString(); decimal novCijena = Convert.ToDecimal(pocCijena); decimal novaCijenaKol = novCijena * kolicina; bezPoreza += novaCijenaKol; decimal cijena = Decimal.Multiply(novCijena, 1.25M); sPorezom += (cijena * kolicina); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, cijena.ToString("F2"), left_margin + 395, top_margin, 0); string rab = view.Rows[row].Cells["Rabat"].Value.ToString(); decimal rabat = Convert.ToDecimal(rab); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, view.Rows[row].Cells["Rabat"].Value.ToString() + "%", left_margin + (435 + 8), top_margin, 0); decimal sPopIznos = Decimal.Multiply(cijena, rabat / 100); decimal ukupno = (cijena - sPopIznos) * kolicina; zaPlatit += ukupno; writeText(cb, ukupno.ToString("F2"), left_margin + 480, top_margin, f_cn, 10); top_margin -= 12; row++; // page break tj novi stranica if (top_margin <= lastwriteposition) { cb.EndText(); // page break document.NewPage(); cb.AddTemplate(PdfFooter(cb, ++page), 30, 1); cb.BeginText(); // ponovnp postavljanje gornje margine top_margin = 780; } } top_margin -= 80; left_margin = 350; // ukupno writeText(cb, "Ukupno bez poreza:", left_margin, top_margin, f_cb, 10); writeText(cb, "Iznos poreza (25%):", left_margin, top_margin - 12, f_cb, 10); writeText(cb, "Iznos popusta:", left_margin, top_margin - 24, f_cb, 10); writeText(cb, "Ukupno s porezom i popustom:", left_margin, top_margin - 48, f_cb, 10); // upisivanje rezultata desno left_margin = 540; cb.SetFontAndSize(f_cn, 10); string curr = "Kn"; cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, curr, left_margin, top_margin, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, curr, left_margin, top_margin - 12, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, curr, left_margin, top_margin - 24, 0); left_margin = 535; cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, bezPoreza.ToString("F2"), left_margin, top_margin, 0); cijenaSamogPoreza = sPorezom - bezPoreza; cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, cijenaSamogPoreza.ToString("F2"), left_margin, top_margin - 12, 0); decimal samiRabat = bezPoreza + cijenaSamogPoreza - zaPlatit; cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, samiRabat.ToString("F2"), left_margin, top_margin - 24, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, zaPlatit.ToString("F2"), left_margin, top_margin - 48, 0); cb.EndText(); // zatvaranje writera, documenta s fs document.Close(); writer.Close(); //otvaranje kreiranog pdf-a var process = new ProcessStartInfo(); process.WorkingDirectory = "D:\\Posao\\Ponude"; process.FileName = "Ponuda_" + kupac + "_" + brponude + ".pdf"; Process.Start(process); }
/** * @see com.itextpdf.text.pdf.PdfPCellEvent#cellLayout(com.itextpdf.text.pdf.PdfPCell, * com.itextpdf.text.Rectangle, com.itextpdf.text.pdf.PdfContentByte[]) */ virtual public void CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) { float effectivePadding = styleValues.BorderWidthLeft / 2 + styleValues.HorBorderSpacing; float x1 = position.Left + effectivePadding; if (styleValues.IsLastInRow) { effectivePadding = styleValues.BorderWidthRight / 2 + styleValues.HorBorderSpacing; } else { effectivePadding = styleValues.BorderWidthRight / 2; } float x2 = position.Right - effectivePadding; effectivePadding = styleValues.BorderWidthTop / 2 + styleValues.VerBorderSpacing; float y1 = position.Top - effectivePadding; effectivePadding = styleValues.BorderWidthBottom / 2; float y2 = position.Bottom + effectivePadding; PdfContentByte cb = canvases[PdfPTable.LINECANVAS]; BaseColor color = styleValues.Background; if (color != null) { cb.SetColorStroke(color); cb.SetColorFill(color); cb.Rectangle(x1, y1, x2 - x1, y2 - y1); cb.Fill(); } BaseColor borderColor = styleValues.BorderColorLeft; float width = styleValues.BorderWidthLeft; if (borderColor != null && width != 0) { cb.SetLineWidth(width); cb.SetColorStroke(borderColor); cb.MoveTo(x1, y1); // start leftUpperCorner cb.LineTo(x1, y2); // left cb.Stroke(); } borderColor = styleValues.BorderColorBottom; width = styleValues.BorderWidthBottom; if (borderColor != null && width != 0) { cb.SetLineWidth(width); cb.SetColorStroke(borderColor); cb.MoveTo(x1, y2); // left cb.LineTo(x2, y2); // bottom cb.Stroke(); } borderColor = styleValues.BorderColorRight; width = styleValues.BorderWidthRight; if (borderColor != null && width != 0) { cb.SetLineWidth(width); cb.SetColorStroke(borderColor); cb.MoveTo(x2, y2); // bottom cb.LineTo(x2, y1); // right cb.Stroke(); } borderColor = styleValues.BorderColorTop; width = styleValues.BorderWidthTop; if (borderColor != null && width != 0) { cb.SetLineWidth(width); cb.SetColorStroke(borderColor); cb.MoveTo(x2, y1); // right cb.LineTo(x1, y1); // top cb.Stroke(); } cb.ResetRGBColorStroke(); }
virtual public void TableLayout(PdfPTable table, float[][] width, float[] height, int headerRows, int rowStart, PdfContentByte[] canvas) { float left = styleValues.BorderWidthLeft; float right = styleValues.BorderWidthRight; float top = styleValues.BorderWidthTop; float bottom = styleValues.BorderWidthBottom; float[] widths = width[0]; float effectivePadding = left / 2; float x1 = widths[0] - effectivePadding; effectivePadding = right / 2; float x2 = widths[widths.Length - 1] + effectivePadding; effectivePadding = top / 2; float y1 = height[0] + effectivePadding; effectivePadding = bottom / 2 + styleValues.VerBorderSpacing; float y2 = height[height.Length - 1] - effectivePadding; PdfContentByte cb = canvas[PdfPTable.BACKGROUNDCANVAS]; BaseColor color = styleValues.Background; if (color != null) { cb.SetColorFill(color); cb.Rectangle(x1, y1, x2 - x1, y2 - y1); cb.Fill(); } cb = canvas[PdfPTable.LINECANVAS]; if (left != 0) { color = styleValues.BorderColorLeft; if (color == null) { color = BaseColor.BLACK; } cb.SetLineWidth(left); cb.SetColorStroke(color); cb.MoveTo(x1, y1); // start leftUpperCorner cb.LineTo(x1, y2); // left cb.Stroke(); } if (bottom != 0) { color = styleValues.BorderColorBottom; if (color == null) { color = BaseColor.BLACK; } cb.SetLineWidth(bottom); cb.SetColorStroke(color); cb.MoveTo(x1, y2); // left cb.LineTo(x2, y2); // bottom cb.Stroke(); } if (right != 0) { color = styleValues.BorderColorRight; if (color == null) { color = BaseColor.BLACK; } cb.SetLineWidth(right); cb.SetColorStroke(color); cb.MoveTo(x2, y2); // bottom cb.LineTo(x2, y1); // right cb.Stroke(); } if (top != 0) { color = styleValues.BorderColorTop; if (color == null) { color = BaseColor.BLACK; } cb.SetLineWidth(top); cb.SetColorStroke(color); cb.MoveTo(x2, y1); // right cb.LineTo(x1, y1); // top cb.Stroke(); } cb.ResetRGBColorStroke(); }