public GetLeft ( float margin ) : float | ||
margin | float | a margin |
Результат | float |
void IPdfPCellEvent.CellLayout(PdfPCell cell, iTextSharp.text.Rectangle position, PdfContentByte[] canvases) { PdfContentByte canvas = canvases[PdfPTable.TEXTCANVAS]; float x = 0; float y = 0; int alignment = 0; switch (pos) { case "TOP_LEFT": x = position.GetLeft(3); y = position.GetTop(content.Leading); alignment = Element.ALIGN_LEFT; break; case "TOP_RIGHT": x = position.GetRight(3); y = position.GetTop(content.Leading); alignment = Element.ALIGN_RIGHT; break; case "BOTTOM_LEFT": x = position.GetLeft(3); y = position.GetBottom(3); alignment = Element.ALIGN_LEFT; break; case "BOTTOM_RIGHT": x = position.GetRight(3); y = position.GetBottom(3); alignment = Element.ALIGN_RIGHT; break; case "CENTER_TOP": x = position.GetRight(3) + position.GetLeft(3) / 2; y = position.GetTop(3); alignment = Element.ALIGN_RIGHT; break; case "CENTER_BOTTOM": x = position.GetRight(3) + position.GetLeft(3) / 2; y = position.GetBottom(3); alignment = Element.ALIGN_RIGHT; break; case "CENTER_MIDDLE": x = position.GetRight(3) + position.GetLeft(3) / 2; y = x; alignment = Element.ALIGN_RIGHT; break; } ColumnText.ShowTextAligned(canvas, alignment, content, x, y, 0); }
/// <summary> /// Clears the contents of a given page leaving header and footer. /// </summary> /// <param name="inputPdf">The pdf to modify.</param> /// <param name="outputPdf">The pdf created after modification.</param> /// <param name="pageNum">The page number to be cleared.</param> public static void ClearContents(string inputPdf, string outputPdf, int pageNum) { using (FileStream fs = new FileStream(outputPdf, FileMode.Create, FileAccess.Write)) { PdfReader reader = new PdfReader(inputPdf); PdfStamper stamper = new PdfStamper(reader, fs); //Get the reactangle leaving header and footer Rectangle mediabox = reader.GetPageSize(pageNum); float llx = mediabox.GetLeft(10f); float urx = mediabox.GetRight(10f); float lly = mediabox.GetBottom(10f) + 100f; // Leave footer float ury = mediabox.GetTop(10f) - 120f; //Leave header List <PdfCleanUpLocation> cleanUpLocations = new List <PdfCleanUpLocation> { new PdfCleanUpLocation(pageNum, new iTextSharp.text.Rectangle(llx, lly, urx, ury), BaseColor.WHITE) }; //Use the PdfCleanUpProcessor to clean the page PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper); cleaner.CleanUp(); stamper.Close(); reader.Close(); } }
/** * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[]) */ public void CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) { float sp_left = spacing_left; if (float.IsNaN(sp_left)) { sp_left = 0f; } float sp_right = spacing_right; if (float.IsNaN(sp_right)) { sp_right = 0f; } float sp_top = spacing_top; if (float.IsNaN(sp_top)) { sp_top = 0f; } float sp_bottom = spacing_bottom; if (float.IsNaN(sp_bottom)) { sp_bottom = 0f; } Rectangle rect = new Rectangle(position.GetLeft(sp_left), position.GetBottom(sp_bottom), position.GetRight(sp_right), position.GetTop(sp_top)); rect.CloneNonPositionParameters(this); canvases[PdfPTable.BACKGROUNDCANVAS].Rectangle(rect); rect.BackgroundColor = null; canvases[PdfPTable.LINECANVAS].Rectangle(rect); }
public override void OnEndPage(PdfWriter writer, Document document) { base.OnEndPage(writer, document); BaseFont bf_qty = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false); //int pageN = writer.PageNumber; //String text = "Page " + pageN.ToString(); String text = "Page " + 1 + " of "; float len = bf_qty.GetWidthPoint(text, 8); //float len = this.RunDateFont.BaseFont.GetWidthPoint(text, this.RunDateFont.Size); iTextSharp.text.Rectangle pageSize = document.PageSize; // cb.SetRGBColorFill(100, 100, 100); cb.BeginText(); //Font font_qty = new Font(bf_qty, 10, Font.NORMAL); cb.SetFontAndSize(bf_qty, 10f); cb.SetTextMatrix(document.LeftMargin, pageSize.GetBottom(document.BottomMargin)); // cb.ShowText(text); cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, "Printed On " + DateTime.Now.ToString(), pageSize.GetRight(40), pageSize.GetBottom(30), 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, text, pageSize.GetLeft(40), pageSize.GetBottom(30), 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "This is a Computer generated Invoice", pageSize.GetLeft(200), pageSize.GetBottom(30), 0); cb.EndText(); // cb.AddTemplate(template, document.LeftMargin, pageSize.GetBottom(document.BottomMargin)); cb.AddTemplate(template, pageSize.GetLeft(40) + len, pageSize.GetBottom(30)); }
// --------------------------------------------------------------------------- /** * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout( * com.lowagie.text.pdf.PdfPCell, * com.lowagie.text.Rectangle, * com.lowagie.text.pdf.PdfContentByte[] * ) */ public void CellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] cb) { parent.AddKid(kid); kid.SetWidget( new Rectangle(rect.GetLeft(padding), rect.GetBottom(padding), rect.GetRight(padding), rect.GetTop(padding)), PdfAnnotation.HIGHLIGHT_INVERT ); }
//creat 2 - line weight private void equalline(iTextSharp.text.Rectangle pagesize, int toTheTop) { cb.EndText(); cb.SetColorStroke(new BaseColor(0x32, 0x5a, 0x75)); cb.MoveTo(pagesize.GetLeft(40), pagesize.GetTop(toTheTop - 5)); cb.LineTo(pagesize.GetRight(40), pagesize.GetTop(toTheTop - 5)); cb.SetLineWidth(2f); cb.Stroke(); cb.BeginText(); }
//create 1 - line weight private void line(iTextSharp.text.Rectangle pagesize, int toTheTop, Boolean summary) { cb.EndText(); cb.SetColorStroke(new BaseColor(0x66, 0x83, 0x97)); cb.MoveTo(pagesize.GetLeft(40), pagesize.GetTop(toTheTop - 5)); cb.LineTo(pagesize.GetRight(40), pagesize.GetTop(toTheTop - 5)); cb.SetLineWidth(1f); cb.Stroke(); if (!summary) { cb.BeginText(); } }
/* public override void OnEndPage(PdfWriter writer, Document document) * { * //PdfContentByte cb = writer.DirectContentUnder; * * //iTextSharp.text.Image marca = iTextSharp.text.Image.GetInstance(marcaAgua); * * //// Calcular la proporcion * //float ancho = marca.Width; * //float alto = marca.Height; * //float proporcion = alto / ancho; * * //float positionY = (writer.PageSize.Top / 2) - (alto /2); * //float positionX = (writer.PageSize.Right / 2) - (ancho / 2); * * * //marca.ScaleAbsoluteWidth(400); * //marca.ScaleAbsoluteHeight(400 * proporcion); * * //marca.SetAbsolutePosition(positionX,positionY); * //PdfGState state = new PdfGState(); * //state.FillOpacity = 0.2f; * //cb.SetGState(state); * //cb.AddImage(marca); * * * //PdfPTable tbHeader = new PdfPTable(3); * //tbHeader.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; * //tbHeader.DefaultCell.Border = 0; * * //tbHeader.AddCell(new Paragraph()); * * //PdfPCell _cell = new PdfPCell(new Paragraph("Listado de Producto")); * //_cell.HorizontalAlignment = Element.ALIGN_CENTER; * //_cell.Border = 0; * //tbHeader.AddCell(_cell); * //tbHeader.AddCell(new Paragraph()); * * //tbHeader.WriteSelectedRows(0, -1, document.LeftMargin, writer.PageSize.GetTop(document.TopMargin)+40, writer.DirectContent); * * //PdfPTable tbFooter = new PdfPTable(3); * //tbFooter.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; * //tbFooter.DefaultCell.Border = 0; * * ////tbFooter.AddCell(new Paragraph()); * * //// _cell = new PdfPCell(new Paragraph("Vendemos de lo Mejor")); * ////_cell.HorizontalAlignment = Element.ALIGN_CENTER; * ////_cell.Border = 0; * ////tbFooter.AddCell(_cell); * * ////_cell = new PdfPCell(new Paragraph("Página " +writer.PageNumber)); * ////_cell.HorizontalAlignment = Element.ALIGN_RIGHT; * ////_cell.Border = 0; * ////tbFooter.AddCell(_cell); * * ////tbFooter.WriteSelectedRows(0, -1, document.LeftMargin, writer.PageSize.GetBottom(document.BottomMargin) -5, writer.DirectContent); * * //// Begin Image * * //iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(logoPath); * * //// Calcular la proporcion * // ancho = logo.Width; * // alto = logo.Height; * // proporcion = alto / ancho; * * //logo.ScaleAbsoluteWidth(150); * //logo.ScaleAbsoluteHeight(150 * proporcion); * * //logo.SetAbsolutePosition(document.LeftMargin, writer.PageSize.GetTop(document.TopMargin)+10); * * //// Porcentaje de la imagen * * ////logo.ScalePercent(35); * //document.Add(logo); * * ////End Image * }*/ public override void OnStartPage(PdfWriter writer, Document document) { base.OnStartPage(writer, document); Rectangle pageSize = document.PageSize; if (Title != string.Empty) { cb.BeginText(); cb.SetFontAndSize(bf, 15); cb.SetRgbColorFill(50, 50, 200); cb.SetTextMatrix(pageSize.GetLeft(40), pageSize.GetTop(40)); cb.ShowText(Title); cb.EndText(); } if (HeaderLeft + HeaderRight != string.Empty) { PdfPTable HeaderTable = new PdfPTable(2); HeaderTable.DefaultCell.Border = 0; HeaderTable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE; HeaderTable.TotalWidth = pageSize.Width - 80; HeaderTable.SetWidthPercentage(new float[] { 45, 45 }, pageSize); PdfPCell HeaderLeftCell = new PdfPCell(new Phrase(8, HeaderLeft, HeaderFont)); HeaderLeftCell.Padding = 5; HeaderLeftCell.PaddingBottom = 8; // HeaderLeftCell.BorderWidthRight = 0; HeaderTable.AddCell(HeaderLeftCell); PdfPCell HeaderRightCell = new PdfPCell(new Phrase(8, HeaderRight, HeaderFont)); HeaderRightCell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT; HeaderRightCell.Padding = 5; HeaderRightCell.PaddingBottom = 8; // HeaderRightCell.BorderWidthLeft = 0; HeaderTable.AddCell(HeaderRightCell); cb.SetRgbColorFill(0, 0, 0); HeaderTable.WriteSelectedRows(0, -1, pageSize.GetLeft(40), pageSize.GetTop(50), cb); } }
private static void ConfiguraAparenciaAssinatura(PdfSignatureAppearance signatureAppearance, string Reason, string Contact, string Location, string Creator, Bitmap bmp, float Altura, float Largura, float X, float Y, int Rotation, int Pagina, PdfReader pdfReader) { iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(bmp, System.Drawing.Imaging.ImageFormat.Jpeg); signatureAppearance.Reason = Reason; signatureAppearance.Contact = Contact; signatureAppearance.Location = "Indústrias Nucleares do Brasil S/A - INB"; signatureAppearance.SignatureCreator = "Assinador da INB - Desenvolvimento Interno"; signatureAppearance.SignatureGraphic = pic; signatureAppearance.SignatureRenderingMode = PdfSignatureAppearance.RenderingMode.GRAPHIC; float Left, Top; float Width, Height; float LarguraAssinatura = Largura; float AlturaAssinatura = Altura; float X_Ajustado, Y_Ajustado; iTextSharp.text.Rectangle cropBox = pdfReader.GetCropBox(Pagina); iTextSharp.text.Rectangle oRetangulo; if (Rotation == 90 || Rotation == 270) { X_Ajustado = (float)X; Y_Ajustado = (float)Y; if (Rotation == 270) { Y_Ajustado -= 5; Top = cropBox.GetLeft(X_Ajustado); Width = cropBox.GetLeft(X_Ajustado + Largura); Left = cropBox.GetRight(Y_Ajustado); Height = cropBox.GetRight(Y_Ajustado + Altura); oRetangulo = new iTextSharp.text.Rectangle(Top, Left, Width, Height); } else { Y_Ajustado -= 5; Top = cropBox.GetRight(X_Ajustado); Width = cropBox.GetRight(X_Ajustado + Largura); Left = cropBox.GetLeft(Y_Ajustado); Height = cropBox.GetLeft(Y_Ajustado + Altura); oRetangulo = new iTextSharp.text.Rectangle(Top, Left, Width, Height); } } else { X_Ajustado = (float)X; Y_Ajustado = (float)Y - 5; Left = cropBox.GetLeft(X_Ajustado); Top = cropBox.GetTop(Y_Ajustado); Width = cropBox.GetLeft(X_Ajustado + LarguraAssinatura); Height = cropBox.GetTop(Y_Ajustado + AlturaAssinatura); oRetangulo = new iTextSharp.text.Rectangle(Left, Height, Width, Top); } signatureAppearance.SetVisibleSignature(oRetangulo, Pagina, "sig" + DateTime.Now.ToString("ddMMyyHHmmss")); }
public override void OnEndPage(PdfWriter writer, Document document) { base.OnEndPage(writer, document); int pageN = writer.PageNumber; String text = "Página " + pageN + "/"; float len = bf.GetWidthPoint(text, 8); Rectangle pageSize = document.PageSize; cb.SetRgbColorFill(100, 100, 100); cb.BeginText(); cb.SetFontAndSize(bf, 8); cb.SetTextMatrix(pageSize.GetLeft(40), pageSize.GetBottom(30)); cb.ShowText(text); cb.EndText(); cb.AddTemplate(template, pageSize.GetLeft(40) + len, pageSize.GetBottom(30)); cb.BeginText(); cb.SetFontAndSize(bf, 8); cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, "Fecha Impre.: " + PrintTime.ToString(), pageSize.GetRight(40), pageSize.GetBottom(30), 0); cb.EndText(); }
public override void OnEndPage(PdfWriter writer, Document document) { base.OnEndPage(writer, document); int pageN = writer.PageNumber; String text = msg + " Page " + pageN; float len = bf.GetWidthPoint(text, 8); iTextSharp.text.Rectangle pageSize = document.PageSize; cb.SetRGBColorFill(100, 100, 100); cb.BeginText(); cb.SetFontAndSize(bf, 8); cb.SetColorFill(iTextSharp.text.Color.BLACK); cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, text, 570, 15, 0); cb.EndText(); cb.AddTemplate(template, pageSize.GetLeft(570) + len, pageSize.GetBottom(15)); }
public override void OnStartPage(PdfWriter writer, Document document) { base.OnStartPage(writer, document); iTextSharp.text.Rectangle pageSize = document.PageSize; if (HeaderRight != string.Empty) { PdfPTable HeaderTable = new PdfPTable(2); HeaderTable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE; HeaderTable.TotalWidth = pageSize.Width - 10; HeaderTable.SetWidthPercentage(new float[] { 45, 45 }, pageSize); PdfPCell HeaderRightCell = new PdfPCell(new Phrase(8, HeaderRight, HeaderFont)); HeaderRightCell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT; HeaderRightCell.Border = 0; HeaderRightCell.Colspan = 2; HeaderTable.AddCell(HeaderRightCell); cb.SetRGBColorFill(0, 0, 0); HeaderTable.WriteSelectedRows(0, -1, pageSize.GetLeft(0), pageSize.GetTop(10), cb); } }
/** * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[]) */ virtual public void CellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvases) { if (cellField == null || (fieldWriter == null && parent == null)) throw new ArgumentException(MessageLocalization.GetComposedMessage("you.have.used.the.wrong.constructor.for.this.fieldpositioningevents.class")); cellField.Put(PdfName.RECT, new PdfRectangle(rect.GetLeft(padding), rect.GetBottom(padding), rect.GetRight(padding), rect.GetTop(padding))); if (parent == null) fieldWriter.AddAnnotation(cellField); else parent.AddKid(cellField); }
/** * @see com.lowagie.text.pdf.PdfPageEvent#onGenericTag(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document, com.lowagie.text.Rectangle, java.lang.String) */ public override void OnGenericTag(PdfWriter writer, Document document, Rectangle rect, String text) { rect.Bottom = rect.Bottom - 3; PdfFormField field; genericChunkFields.TryGetValue(text, out field); if (field == null) { TextField tf = new TextField(writer, new Rectangle(rect.GetLeft(padding), rect.GetBottom(padding), rect.GetRight(padding), rect.GetTop(padding)), text); tf.FontSize = 14; field = tf.GetTextField(); } else { field.Put(PdfName.RECT, new PdfRectangle(rect.GetLeft(padding), rect.GetBottom(padding), rect.GetRight(padding), rect.GetTop(padding))); } if (parent == null) writer.AddAnnotation(field); else parent.AddKid(field); }
/** * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[]) */ public void CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) { float sp_left = spacing_left; if (float.IsNaN(sp_left)) sp_left = 0f; float sp_right = spacing_right; if (float.IsNaN(sp_right)) sp_right = 0f; float sp_top = spacing_top; if (float.IsNaN(sp_top)) sp_top = 0f; float sp_bottom = spacing_bottom; if (float.IsNaN(sp_bottom)) sp_bottom = 0f; Rectangle rect = new Rectangle(position.GetLeft(sp_left), position.GetBottom(sp_bottom), position.GetRight(sp_right), position.GetTop(sp_top)); rect.CloneNonPositionParameters(this); canvases[PdfPTable.BACKGROUNDCANVAS].Rectangle(rect); rect.BackgroundColor = null; canvases[PdfPTable.LINECANVAS].Rectangle(rect); }
/// <summary> /// Returns the lower left x-coordinate considering a given margin. /// </summary> /// <param name="margin">a margin</param> /// <returns>the lower left x-coordinate</returns> public float GetLeft(float margin) { return(pageSize.GetLeft(marginLeft + margin)); }
/** * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[]) */ public void CellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvases) { if (cellField == null || (fieldWriter == null && parent == null)) throw new ArgumentException("You have used the wrong constructor for this FieldPositioningEvents class."); cellField.Put(PdfName.RECT, new PdfRectangle(rect.GetLeft(padding), rect.GetBottom(padding), rect.GetRight(padding), rect.GetTop(padding))); if (parent == null) fieldWriter.AddAnnotation(cellField); else parent.AddKid(cellField); }
//make the pdf new func private void makepdf(object sender, RoutedEventArgs e) { //open new doc and create base font for doc Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35); BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); MySqlDataReader dr = null; MySqlCommand cmd = null; object nme = main.cb1.SelectedItem; string name = ""; string date1 = main.dp1.Text; string date2 = main.dp2.Text; string firstName = ""; //get name if (nme != null) { name = nme.ToString(); int spaceIndex = name.IndexOf(" ") + 1; firstName = name.Substring(0, spaceIndex); name = name.Substring(0, 1) + " " + name.Substring(spaceIndex, name.Length - spaceIndex); } if ((bool)timecard.IsChecked) { //to create save dialog box SaveFileDialog sfd1 = new SaveFileDialog(); sfd1.Filter = "PDF(*.pdf)|*.pdf"; sfd1.FilterIndex = 1; sfd1.Title = "save time card"; sfd1.FileName = name + "_TimeCard.pdf"; sfd1.RestoreDirectory = true; sfd1.ShowDialog(); string full_path = sfd1.InitialDirectory + sfd1.FileName; FileStream fs = new FileStream(full_path, FileMode.Create); PdfWriter wri = PdfWriter.GetInstance(doc, fs); OneColHeaderFooter PageEventHandler = new OneColHeaderFooter(); wri.PageEvent = PageEventHandler; iTextSharp.text.Rectangle pagesize = doc.PageSize; String missingPunches = " Missing Punches!!! "; if (main.openConn()) { string query = "USE crst_dash; \n"; query += "SELECT pin FROM a_staff WHERE first_name = \"" + firstName + "\""; cmd = new MySqlCommand(query, main.myconn); try { int counter = 1; dr = cmd.ExecuteReader(); while (dr.Read()) { PageEventHandler.Header = name + " " + dr[0] + " Time Report " + date1 + " to " + date2; } main.closeConn(); //turn date1 and date2 into strings String date11 = DateTime.Parse(date1).ToString("yyyy/MM/dd"); String date21 = DateTime.Parse(date2).ToString("yyyy/MM/dd"); main.openConn(); query = "USE crst_dash; \n" + "SELECT COUNT(id) FROM a_staff_time WHERE name = \"" + name + "\" AND time >= \"" + date11 + "\" AND time <= \"" + date21 + "\" GROUP BY YEAR(time), MONTH(time), DAY(time)"; cmd = new MySqlCommand(query, main.myconn); dr = cmd.ExecuteReader(); ArrayList myCount = new ArrayList(); while (dr.Read()) { myCount.Add(dr[0]); } Object[] countArr = myCount.ToArray(); main.closeConn(); main.openConn(); //open document doc.Open(); cb = wri.DirectContent; query = "USE crst_dash; \n" + "SELECT time, status FROM a_staff_time WHERE name = \"" + name + "\" AND time >= \"" + date11 + "\" AND time <= \"" + date21 + "\" ORDER BY time ASC;"; cmd = new MySqlCommand(query, main.myconn); dr = cmd.ExecuteReader(); //index to check my count arr; int dex = 0; int endPage = 1; int toTheTop = 60; Boolean addedDate = true; DateTime time1 = new DateTime(); DateTime time2 = new DateTime(); DateTime sum = new DateTime(); double sumAll = 0.0; cb.BeginText(); while (dr.Read() && (dex < countArr.Length)) { cb.SetFontAndSize(bf, 10); Console.WriteLine(dr[0] + " <dr0 dr1> " + dr[1] + " counter -> " + counter); if (addedDate) { addedDate = false; cb.SetTextMatrix(pagesize.GetLeft(40), pagesize.GetTop(toTheTop)); String theDate = Convert.ToDateTime(dr[0]).ToString("MM-dd-yyyy"); cb.ShowText("Date: " + theDate); endPage += 1; toTheTop += 20; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } } if (Convert.ToInt32(countArr[dex]) <= 4 && Convert.ToInt32(countArr[dex]) > 2) { if (counter == Convert.ToInt32(countArr[dex]) && counter != 4) { if (Convert.ToInt32(dr[1]) == 0) { time2 = Convert.ToDateTime(dr[0]); cb.SetTextMatrix(pagesize.GetLeft(60), pagesize.GetTop(toTheTop)); String outString = "out: " + time2.ToString("HH:mm:ss"); toTheTop += 20; cb.ShowText(outString); endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } double min = time2.Subtract(time1).Minutes; min = min / 100; int hours = time2.Subtract(time1).Hours; sumAll += (hours + min); cb.SetTextMatrix(pagesize.GetLeft(60), pagesize.GetTop(toTheTop)); String totString = "total hours: " + (hours + min); toTheTop += 20; cb.ShowText(totString); endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } } else { Console.WriteLine("1 t1 --"); time1 = Convert.ToDateTime(dr[0]); cb.SetTextMatrix(pagesize.GetLeft(60), pagesize.GetTop(toTheTop)); String inString = "in: " + time1.ToString("HH:mm:ss"); toTheTop += 20; cb.ShowText(inString); endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } } Console.WriteLine("IN HERE"); String totalFinal = "final total hours: " + sumAll; line(pagesize, toTheTop, false); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } //cb.BeginText(); cb.SetTextMatrix(pagesize.GetLeft(60), pagesize.GetTop(toTheTop)); cb.ShowText(missingPunches); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } cb.SetTextMatrix(pagesize.GetLeft(60), pagesize.GetTop(toTheTop)); cb.ShowText(totalFinal); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } equalline(pagesize, toTheTop); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } counter = 1; addedDate = true; sumAll = 0.0; sum = new DateTime(); dex++; continue; } //check status if (Convert.ToInt32(dr[1]) == 0) { Console.WriteLine("0 t2"); time2 = Convert.ToDateTime(dr[0]); String outString = "out: " + time2.ToString("HH:mm:ss"); cb.SetTextMatrix(pagesize.GetLeft(60), pagesize.GetTop(toTheTop)); cb.ShowText(outString); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } if (Convert.ToInt32(countArr[dex]) < 4 && counter == 1) { Console.WriteLine("c - 1 < 4"); String totalHr = "total hours: 0"; cb.SetTextMatrix(pagesize.GetLeft(60), pagesize.GetTop(toTheTop)); cb.ShowText(totalHr); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } line(pagesize, toTheTop, false); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } } else { sum += time2.Subtract(time1); Console.WriteLine(time2 + " " + time1); Console.WriteLine(time2.Subtract(time1)); double min = time2.Subtract(time1).Minutes; min = min / 100; int hours = time2.Subtract(time1).Hours; sumAll += (hours + min); String totalHr = "total hours: " + (hours + min); cb.SetTextMatrix(pagesize.GetLeft(60), pagesize.GetTop(toTheTop)); cb.ShowText(totalHr); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } } if (counter == 4) { Console.WriteLine("c - 4"); String finalTotal = "final total hours: " + sumAll; line(pagesize, toTheTop, false); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } cb.SetTextMatrix(pagesize.GetLeft(60), pagesize.GetTop(toTheTop)); cb.ShowText(finalTotal); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } equalline(pagesize, toTheTop); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } counter = 0; addedDate = true; sumAll = 0.0; sum = new DateTime(); dex++; } else if (counter == 2) { Console.WriteLine("c - 2"); line(pagesize, toTheTop, false); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } } } else { Console.WriteLine("1 t1"); time1 = Convert.ToDateTime(dr[0]); cb.SetTextMatrix(pagesize.GetLeft(60), pagesize.GetTop(toTheTop)); String inString = "in: " + time1.ToString("HH:mm:ss"); cb.ShowText(inString); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } } counter++; } else if (Convert.ToInt32(countArr[dex]) <= 2) { if (counter == Convert.ToInt32(countArr[dex]) && counter != 2) { if (Convert.ToInt32(dr[1]) == 0) { Console.WriteLine("2 0 t2"); time2 = (DateTime)dr[0]; String outString = "out: " + time2.ToString("HH:mm:ss"); String totalHrs = "total hours: " + 0; cb.SetTextMatrix(pagesize.GetLeft(60), pagesize.GetTop(toTheTop)); cb.ShowText(outString); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } cb.SetTextMatrix(pagesize.GetLeft(60), pagesize.GetTop(toTheTop)); cb.ShowText(totalHrs); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } } else { Console.WriteLine("2 1 t1"); time1 = (DateTime)dr[0]; String inString = "in: " + time1.ToString("HH:mm:ss"); cb.SetTextMatrix(pagesize.GetLeft(60), pagesize.GetTop(toTheTop)); cb.ShowText(inString); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } } String finalTotHrs = "final total hours: " + sumAll; line(pagesize, toTheTop, false); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } cb.SetTextMatrix(pagesize.GetLeft(60), pagesize.GetTop(toTheTop)); cb.ShowText(missingPunches); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } cb.SetTextMatrix(pagesize.GetLeft(60), pagesize.GetTop(toTheTop)); cb.ShowText(finalTotHrs); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } equalline(pagesize, toTheTop); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } counter = 1; addedDate = true; sumAll = 0.0; sum = new DateTime(); dex++; continue; } if (Convert.ToInt32(dr[1]) == 0) { Console.WriteLine("2 0 t2 -- "); time2 = (DateTime)dr[0]; sum += time2.Subtract(time1); double min = time2.Subtract(time1).Minutes; min = min / 100; int hours = time2.Subtract(time1).Hours; sumAll += (hours + min); String outString = "out: " + time2.ToString("HH:mm:ss"); String totalHrs = "total hours: " + (hours + min); cb.SetTextMatrix(pagesize.GetLeft(60), pagesize.GetTop(toTheTop)); cb.ShowText(outString); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } cb.SetTextMatrix(pagesize.GetLeft(60), pagesize.GetTop(toTheTop)); cb.ShowText(totalHrs); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } if (counter == 2) { Console.WriteLine("2 c - 2"); String finalTotalHrs = "final total hours: " + sumAll; line(pagesize, toTheTop, false); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } cb.SetTextMatrix(pagesize.GetLeft(60), pagesize.GetTop(toTheTop)); cb.ShowText(finalTotalHrs); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } equalline(pagesize, toTheTop); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } counter = 0; addedDate = true; sumAll = 0.0; sum = new DateTime(); dex++; } } else { Console.WriteLine("2 1 t1 -- "); time1 = (DateTime)dr[0]; String inString = "in: " + time1.ToString("HH:mm:ss"); cb.SetTextMatrix(pagesize.GetLeft(60), pagesize.GetTop(toTheTop)); cb.ShowText(inString); toTheTop += 20; endPage += 1; if (checkEndPage(endPage)) { cb.EndText(); doc.NewPage(); endPage = 1; toTheTop = 60; cb.BeginText(); } } counter++; } } cb.EndText(); } catch (Exception ex) { Console.WriteLine("Error: " + ex); } } doc.Close(); main.closeConn(); main.dialogHost.IsOpen = false; main.snackbar.MessageQueue.Enqueue("Pdf Created"); } else if ((bool)summary.IsChecked) { //to check all people's hours //to create save dialog box SaveFileDialog sfd1 = new SaveFileDialog(); sfd1.Filter = "PDF(*.pdf)|*.pdf"; sfd1.FilterIndex = 1; sfd1.Title = "save summary"; string[] splited_date1 = date1.Split('/'); string date1_no_slash = splited_date1[0] + "_" + splited_date1[1] + "_" + splited_date1[2]; sfd1.FileName = "Summary_for_week_of_" + date1_no_slash + ".pdf"; sfd1.RestoreDirectory = true; sfd1.ShowDialog(); string full_path = sfd1.InitialDirectory + sfd1.FileName; FileStream fs = new FileStream(full_path, FileMode.Create); PdfWriter wri = PdfWriter.GetInstance(doc, fs); OneColHeaderFooter PageEventHandler = new OneColHeaderFooter(); wri.PageEvent = PageEventHandler; iTextSharp.text.Rectangle pagesize = doc.PageSize; int fromTop = 60; int endPage = 1; if (main.openConn()) { PageEventHandler.Header = "Hours Summary Report for " + date1 + " to " + date2; ArrayList names = new ArrayList(); string query = "USE crst_dash; \n"; query += "SELECT first_name, last_name FROM a_staff"; cmd = new MySqlCommand(query, main.myconn); dr = cmd.ExecuteReader(); while (dr.Read()) { String fn = dr[0].ToString(); String myName = fn.Substring(0, 1) + " " + dr[1].ToString(); names.Add(myName); } //open document doc.Open(); cb = wri.DirectContent; Object[] nameArr = names.ToArray(); main.closeConn(); DateTime sevenDate = Convert.ToDateTime(date1).AddDays(7.0); for (int i = 0; i < nameArr.Length; i++) { int countDays = 0; double seven = 0.0; double fourteen = 0.0; //to get pin of the staff using name main.openConn(); query = "USE crst_dash; \n"; query += "SELECT pin FROM a_staff_time WHERE name = \"" + nameArr[i] + "\""; cmd = new MySqlCommand(query, main.myconn); dr = cmd.ExecuteReader(); String pin = ""; while (dr.Read()) { pin = dr[0].ToString(); } main.closeConn(); //to get first name and last name from a_staff using pin main.openConn(); query = "USE crst_dash; \n"; query += "SELECT first_name, last_name FROM a_staff WHERE pin = \"" + pin + "\""; cmd = new MySqlCommand(query, main.myconn); dr = cmd.ExecuteReader(); String fullName = ""; while (dr.Read()) { fullName = dr[0].ToString() + " " + dr[1].ToString(); } main.closeConn(); //to get the department from a_staff using pin main.openConn(); query = "USE crst_dash; \n"; query += "SELECT department FROM a_staff WHERE pin = \"" + pin + "\""; cmd = new MySqlCommand(query, main.myconn); dr = cmd.ExecuteReader(); String dept = ""; while (dr.Read()) { dept = dr[0].ToString(); } main.closeConn(); //to count the dates between date1 and date2 main.openConn(); String date11 = DateTime.Parse(date1).ToString("yyyy/MM/dd"); String date21 = DateTime.Parse(date2).ToString("yyyy/MM/dd"); query = "USE crst_dash; \n" + "SELECT COUNT(id) FROM a_staff_time WHERE name = \"" + nameArr[i] + "\" AND time >= \"" + date11 + "\" AND time <= \"" + date21 + "\" GROUP BY YEAR(time), MONTH(time), DAY(time)"; cmd = new MySqlCommand(query, main.myconn); dr = cmd.ExecuteReader(); ArrayList myCount = new ArrayList(); while (dr.Read()) { myCount.Add(dr[0]); } Object[] countArr = myCount.ToArray(); main.closeConn(); //to get the time and status between date1 and date2 main.openConn(); query = "USE crst_dash; \n" + "SELECT time, status FROM a_staff_time WHERE name = \"" + nameArr[i] + "\" AND time >= \"" + date11 + "\" AND time <= \"" + date21 + "\" ORDER BY time ASC;"; cmd = new MySqlCommand(query, main.myconn); dr = cmd.ExecuteReader(); //index to check my count arr; int dex = 0; int counter = 1; DateTime time1 = new DateTime(); DateTime time2 = new DateTime(); double sumAll = 0; while (dr.Read() && (dex < countArr.Length)) { if (Convert.ToInt32(countArr[dex]) <= 4 && Convert.ToInt32(countArr[dex]) > 2) { if (Convert.ToInt32(dr[1]) == 0) { time2 = Convert.ToDateTime(dr[0]); double min = time2.Subtract(time1).Minutes; int hours = time2.Subtract(time1).Hours; min = min / 100; sumAll += (hours + min); if (countDays <= 9) { seven = sumAll; Console.WriteLine(seven + " seven 4"); } if (countDays >= 10) { fourteen += (hours + min); } countDays++; } else { time1 = Convert.ToDateTime(dr[0]); } } else if (Convert.ToInt32(countArr[dex]) <= 2) { if (Convert.ToInt32(dr[1]) == 0) { time2 = Convert.ToDateTime(dr[0]); double min = time2.Subtract(time1).Minutes; int hours = time2.Subtract(time1).Hours; min = min / 100; sumAll += (hours + min); if (countDays <= 9) { seven = sumAll; Console.WriteLine(seven + " seven 2"); } if (countDays >= 10) { fourteen += (hours + min); } countDays++; } else { time1 = Convert.ToDateTime(dr[0]); } } counter++; } //so words don't go off of the page - add a new paghe to doc and reset endpage and fromTop if (endPage == 35) { endPage = 1; fromTop = 60; doc.NewPage(); } if (pin != "") { //name pin dept wages cb.SetFontAndSize(bf, 12); cb.BeginText(); cb.SetTextMatrix(pagesize.GetLeft(40), pagesize.GetTop(fromTop)); cb.ShowText(fullName); cb.SetFontAndSize(bf, 10); cb.SetTextMatrix(pagesize.GetLeft(200), pagesize.GetTop(fromTop)); cb.ShowText("Pin " + pin); cb.SetTextMatrix(pagesize.GetLeft(300), pagesize.GetTop(fromTop)); cb.ShowText("Dept " + dept); cb.SetTextMatrix(pagesize.GetLeft(400), pagesize.GetTop(fromTop)); cb.ShowText("Wages"); fromTop += 20; //first week of pay period cb.SetTextMatrix(pagesize.GetLeft(40), pagesize.GetTop(fromTop)); String firstWeek = "Week of " + DateTime.Parse(date1).ToString("yyyy/MM/dd"); cb.ShowText(firstWeek); cb.SetTextMatrix(pagesize.GetLeft(200), pagesize.GetTop(fromTop)); cb.ShowText("Total: " + seven); fromTop += 20; //second week of pay period cb.SetTextMatrix(pagesize.GetLeft(40), pagesize.GetTop(fromTop)); String secondWeek = "Week of " + sevenDate.ToString("yyyy/MM/dd"); cb.ShowText(secondWeek); cb.SetTextMatrix(pagesize.GetLeft(200), pagesize.GetTop(fromTop)); cb.ShowText("Total: " + fourteen); /* * if (fourteen == 0.0 && (string.Compare(seven, "0.0") < 0)) * { * String secondWeek = "Week of " + sevenDate.ToString("yyyy/MM/dd"); * cb.ShowText(secondWeek); * cb.SetTextMatrix(pagesize.GetLeft(200), pagesize.GetTop(fromTop)); * cb.ShowText("Total: " + fourteen); * } * else * { * String secondWeek = "Week of " + sevenDate.ToString("yyyy/MM/dd"); * cb.ShowText(secondWeek); * cb.SetTextMatrix(pagesize.GetLeft(200), pagesize.GetTop(fromTop)); * cb.ShowText("Total: " + sumAll); * }*/ fromTop += 20; //weekly total cb.SetTextMatrix(pagesize.GetLeft(200), pagesize.GetTop(fromTop)); String total = "Weekly Total: " + sumAll; cb.ShowText(total); fromTop += 20; line(pagesize, fromTop, true); fromTop += 20; endPage += 3; } main.closeConn(); } } main.closeConn(); doc.Close(); main.dialogHost.IsOpen = false; main.snackbar.MessageQueue.Enqueue("Pdf Created"); } main.dialogHost.IsOpen = false; }
/// <summary> /// Recreate the pdf with a Table of Contents at the given location. /// </summary> /// <param name="inputPdf">The pdf to read from.</param> /// <param name="outputPdf">The pdf created with the TOC.</param> /// <param name="pageTOC">Page number for TOC.</param> /// <param name="pageStart">Starting page for TOC.</param> /// <param name="pageEnd">Ending page for TOC.</param> public static void CreateTOC(string inputPdf, string outputPdf, int pageTOC, int pageStart, int pageEnd) { //Bind a reader to our input file using (PdfReader reader = new PdfReader(inputPdf)) { using (FileStream fs = new FileStream(outputPdf, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) { using (Document doc = new Document(reader.GetPageSizeWithRotation(1))) { PdfWriter writer = PdfWriter.GetInstance(doc, fs); doc.Open(); PdfContentByte cb = writer.DirectContentUnder; //Get the rectangle to copy and paste Rectangle mediabox = reader.GetPageSize(1); float llx = mediabox.GetLeft(0f); float lly = mediabox.GetBottom(0f); //Not working //TOCEvent evento = new TOCEvent(); //writer.PageEvent = evento; //Create the list of pageIndex manulally. List <PageIndex> toc = new List <PageIndex>(); for (int i = pageStart; i <= pageEnd; i++) { String text = GetContentsTextFromPage(inputPdf, i); toc.Add(new PageIndex() { Text = text, Name = text, Page = i }); } //Start copying the pdf for (int i = 1; i <= reader.NumberOfPages; i++) { if (i == pageTOC) //This is the TOC page. { //Add header and footer doc.NewPage(); PdfImportedPage page = writer.GetImportedPage(reader, i); cb.AddTemplate(page, llx, lly); //Create TOC Chunk dottedLine = new Chunk(new DottedLineSeparator()); // Change later for drawing with rectangle Paragraph gap = new Paragraph { "\n\n\n\n\n\n\n" }; doc.Add(gap); Paragraph p; foreach (PageIndex pageIndex in toc) { Chunk chunk = new Chunk(pageIndex.Text); chunk.SetAction(PdfAction.GotoLocalPage(pageIndex.Name, false)); p = new Paragraph(chunk) { dottedLine }; chunk = new Chunk(pageIndex.Page.ToString()); chunk.SetAction(PdfAction.GotoLocalPage(pageIndex.Name, false)); p.Add(chunk); doc.Add(p); } } else // other pages write { doc.NewPage(); PdfImportedPage page = writer.GetImportedPage(reader, i); cb.AddTemplate(page, llx, lly); } } } } } }
public void GenerarPresupuestoPdf(PresupuestoBE Presup) { try { Document pdfDoc = new Document(PageSize.A4, 10, 10, 10, 10); PdfWriter writer = PdfWriter.GetInstance(pdfDoc, new FileStream("Presupuesto.pdf", FileMode.Create)); var titleFont = FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.BOLD); var titleFontBlue = FontFactory.GetFont("Arial", 14, iTextSharp.text.Font.NORMAL, BaseColor.BLUE); var boldTableFont = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD); var bodyFont = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL); var EmailFont = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLUE); BaseColor TabelHeaderBackGroundColor = WebColors.GetRGBColor("#EEEEEE"); iTextSharp.text.Rectangle pageSize = writer.PageSize; pdfDoc.Open(); #region Top table // Cabecera PdfPTable headertable = new PdfPTable(3); headertable.HorizontalAlignment = 0; headertable.WidthPercentage = 100; headertable.SetWidths(new float[] { 120f, 280f, 120f }); headertable.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER; iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance("C:\\OneDrive - EQA SAIC\\Escritorio\\logo.png"); logo.ScaleToFit(100, 30); { PdfPCell pdfCelllogo = new PdfPCell(logo); pdfCelllogo.Border = iTextSharp.text.Rectangle.NO_BORDER; pdfCelllogo.BorderColorBottom = new BaseColor(System.Drawing.Color.Black); pdfCelllogo.BorderWidthBottom = 1f; headertable.AddCell(pdfCelllogo); } { PdfPCell middlecell = new PdfPCell(); middlecell.Border = iTextSharp.text.Rectangle.NO_BORDER; middlecell.BorderColorBottom = new BaseColor(System.Drawing.Color.Black); middlecell.BorderWidthBottom = 1f; headertable.AddCell(middlecell); } { PdfPTable nested = new PdfPTable(1); nested.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER; PdfPCell nextPostCell1 = new PdfPCell(new Phrase("Gestión de Ventas", titleFont)); nextPostCell1.Border = iTextSharp.text.Rectangle.NO_BORDER; nested.AddCell(nextPostCell1); PdfPCell nextPostCell2 = new PdfPCell(new Phrase("VENDEDOR:", bodyFont)); nextPostCell2.Border = iTextSharp.text.Rectangle.NO_BORDER; nested.AddCell(nextPostCell2); PdfPCell nextPostCell3 = new PdfPCell(new Phrase(Presup.Vendedor.ToString(), bodyFont)); nextPostCell3.Border = iTextSharp.text.Rectangle.NO_BORDER; nested.AddCell(nextPostCell3); PdfPCell nextPostCell4 = new PdfPCell(new Phrase(Presup.Vendedor.Mail, EmailFont)); nextPostCell4.Border = iTextSharp.text.Rectangle.NO_BORDER; nested.AddCell(nextPostCell4); nested.AddCell(""); PdfPCell nesthousing = new PdfPCell(nested); nesthousing.Border = iTextSharp.text.Rectangle.NO_BORDER; nesthousing.BorderColorBottom = new BaseColor(System.Drawing.Color.Black); nesthousing.BorderWidthBottom = 1f; nesthousing.Rowspan = 5; nesthousing.PaddingBottom = 10f; headertable.AddCell(nesthousing); } PdfPTable Invoicetable = new PdfPTable(3); Invoicetable.HorizontalAlignment = 0; Invoicetable.WidthPercentage = 100; Invoicetable.SetWidths(new float[] { 120f, 280f, 120f }); Invoicetable.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER; { PdfPTable nested = new PdfPTable(1); nested.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER; PdfPCell nextPostCell1 = new PdfPCell(new Phrase("PARA:", bodyFont)); nextPostCell1.Border = iTextSharp.text.Rectangle.NO_BORDER; nested.AddCell(nextPostCell1); PdfPCell nextPostCell2 = new PdfPCell(new Phrase(Presup.Cliente.RazonSocial, titleFont)); nextPostCell2.Border = iTextSharp.text.Rectangle.NO_BORDER; nested.AddCell(nextPostCell2); PdfPCell nextPostCell3 = new PdfPCell(new Phrase(Presup.Cliente.Direccion, bodyFont)); nextPostCell3.Border = iTextSharp.text.Rectangle.NO_BORDER; nested.AddCell(nextPostCell3); PdfPCell nextPostCell4 = new PdfPCell(new Phrase(Presup.Cliente.Mail, EmailFont)); nextPostCell4.Border = iTextSharp.text.Rectangle.NO_BORDER; nested.AddCell(nextPostCell4); nested.AddCell(""); PdfPCell nesthousing = new PdfPCell(nested); nesthousing.Border = iTextSharp.text.Rectangle.NO_BORDER; nesthousing.Rowspan = 5; nesthousing.PaddingBottom = 10f; Invoicetable.AddCell(nesthousing); } { PdfPCell middlecell = new PdfPCell(); middlecell.Border = iTextSharp.text.Rectangle.NO_BORDER; Invoicetable.AddCell(middlecell); } { TimeSpan PlazoEntrega = Presup.FechaEntrega - Presup.FechaEmision;// PdfPTable nested = new PdfPTable(1); nested.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER; PdfPCell nextPostCell1 = new PdfPCell(new Phrase("Presupuesto N° " + Presup.Id, titleFontBlue)); nextPostCell1.Border = iTextSharp.text.Rectangle.NO_BORDER; nested.AddCell(nextPostCell1); PdfPCell nextPostCell2 = new PdfPCell(new Phrase("Fecha Emisión: " + Presup.FechaEmision.ToShortDateString(), bodyFont)); nextPostCell2.Border = iTextSharp.text.Rectangle.NO_BORDER; nested.AddCell(nextPostCell2); PdfPCell nextPostCell3 = new PdfPCell(new Phrase("Plazo Entrega: " + Convert.ToInt32(PlazoEntrega.TotalDays) + " días", bodyFont)); nextPostCell3.Border = iTextSharp.text.Rectangle.NO_BORDER; nested.AddCell(nextPostCell3); nested.AddCell(""); PdfPCell nesthousing = new PdfPCell(nested); nesthousing.Border = iTextSharp.text.Rectangle.NO_BORDER; nesthousing.Rowspan = 5; nesthousing.PaddingBottom = 10f; Invoicetable.AddCell(nesthousing); } pdfDoc.Add(headertable); Invoicetable.PaddingTop = 10f; pdfDoc.Add(Invoicetable); #endregion #region Items Table //Cuerpo de la tabla PdfPTable itemTable = new PdfPTable(7); itemTable.HorizontalAlignment = 0; itemTable.WidthPercentage = 100; itemTable.SetWidths(new float[] { 5, 40, 10, 10, 10, 10, 15 }); // ancho relativo itemTable.SpacingAfter = 40; itemTable.DefaultCell.Border = iTextSharp.text.Rectangle.BOX; PdfPCell cell1 = new PdfPCell(new Phrase("ITEM", boldTableFont)); cell1.BackgroundColor = TabelHeaderBackGroundColor; cell1.HorizontalAlignment = Element.ALIGN_CENTER; itemTable.AddCell(cell1); PdfPCell cell2 = new PdfPCell(new Phrase("DESCRIPCION", boldTableFont)); cell2.BackgroundColor = TabelHeaderBackGroundColor; cell2.HorizontalAlignment = 1; itemTable.AddCell(cell2); PdfPCell cell3 = new PdfPCell(new Phrase("CANTIDAD", boldTableFont)); cell3.BackgroundColor = TabelHeaderBackGroundColor; cell3.HorizontalAlignment = Element.ALIGN_CENTER; itemTable.AddCell(cell3); PdfPCell cell4 = new PdfPCell(new Phrase("PRECIO UNITARIO", boldTableFont)); cell4.BackgroundColor = TabelHeaderBackGroundColor; cell4.HorizontalAlignment = Element.ALIGN_CENTER; itemTable.AddCell(cell4); PdfPCell cell5 = new PdfPCell(new Phrase("% IVA", boldTableFont)); cell5.BackgroundColor = TabelHeaderBackGroundColor; cell5.HorizontalAlignment = Element.ALIGN_CENTER; itemTable.AddCell(cell5); PdfPCell cell6 = new PdfPCell(new Phrase("IVA ITEM", boldTableFont)); cell6.BackgroundColor = TabelHeaderBackGroundColor; cell6.HorizontalAlignment = Element.ALIGN_CENTER; itemTable.AddCell(cell6); PdfPCell cell7 = new PdfPCell(new Phrase("TOTAL ITEM", boldTableFont)); cell7.BackgroundColor = TabelHeaderBackGroundColor; cell7.HorizontalAlignment = Element.ALIGN_CENTER; itemTable.AddCell(cell7); int Item = 1; foreach (PresupuestoItemBE item in Presup.Items) { PdfPCell numberCell = new PdfPCell(new Phrase(Item.ToString(), bodyFont)); // Num Item numberCell.HorizontalAlignment = 1; numberCell.PaddingLeft = 10f; numberCell.Border = iTextSharp.text.Rectangle.LEFT_BORDER | iTextSharp.text.Rectangle.RIGHT_BORDER; itemTable.AddCell(numberCell); var _phrase = new Phrase(); _phrase.Add(new Chunk("Codigo: " + item.Producto.Id + "\n", EmailFont)); _phrase.Add(new Chunk(item.Producto.Descripcion, bodyFont)); PdfPCell descCell = new PdfPCell(_phrase); descCell.HorizontalAlignment = 0; descCell.PaddingLeft = 10f; descCell.Border = iTextSharp.text.Rectangle.LEFT_BORDER | iTextSharp.text.Rectangle.RIGHT_BORDER; itemTable.AddCell(descCell); PdfPCell qtyCell = new PdfPCell(new Phrase(item.Cantidad.ToString(), bodyFont)); qtyCell.HorizontalAlignment = 1; qtyCell.PaddingLeft = 10f; qtyCell.Border = iTextSharp.text.Rectangle.LEFT_BORDER | iTextSharp.text.Rectangle.RIGHT_BORDER; itemTable.AddCell(qtyCell); PdfPCell amountCell = new PdfPCell(new Phrase("$" + item.PrecioUnitario.ToString(), bodyFont)); amountCell.HorizontalAlignment = 1; amountCell.PaddingLeft = 10f; amountCell.Border = iTextSharp.text.Rectangle.LEFT_BORDER | iTextSharp.text.Rectangle.RIGHT_BORDER; itemTable.AddCell(amountCell); PdfPCell porIvaCell = new PdfPCell(new Phrase(item.PorcIVA.ToString() + "%", bodyFont)); porIvaCell.HorizontalAlignment = 1; porIvaCell.PaddingLeft = 10f; porIvaCell.Border = iTextSharp.text.Rectangle.LEFT_BORDER | iTextSharp.text.Rectangle.RIGHT_BORDER; itemTable.AddCell(porIvaCell); PdfPCell ivaItemCell = new PdfPCell(new Phrase("$" + item.IvaItem.ToString(), bodyFont)); ivaItemCell.HorizontalAlignment = 1; ivaItemCell.PaddingLeft = 10f; ivaItemCell.Border = iTextSharp.text.Rectangle.LEFT_BORDER | iTextSharp.text.Rectangle.RIGHT_BORDER; itemTable.AddCell(ivaItemCell); PdfPCell totalamtCell = new PdfPCell(new Phrase("$" + item.TotalItem.ToString(), bodyFont)); totalamtCell.HorizontalAlignment = 1; totalamtCell.Border = iTextSharp.text.Rectangle.LEFT_BORDER | iTextSharp.text.Rectangle.RIGHT_BORDER; itemTable.AddCell(totalamtCell); Item++; } PdfPCell cella = new PdfPCell(new Phrase("Impuestos", boldTableFont)); cella.Colspan = 6; cella.HorizontalAlignment = 2; itemTable.AddCell(cella); PdfPCell cellz = new PdfPCell(new Phrase("$ " + Presup.Iva.ToString(), boldTableFont)); cellz.Colspan = 1; cellz.HorizontalAlignment = 2; itemTable.AddCell(cellz); PdfPCell cellb = new PdfPCell(new Phrase("Descuentos", boldTableFont)); cellb.Colspan = 6; cellb.HorizontalAlignment = 2; // cellz.Border = iTextSharp.text.Rectangle.LEFT_BORDER | iTextSharp.text.Rectangle.RIGHT_BORDER; itemTable.AddCell(cellb); PdfPCell celly = new PdfPCell(new Phrase("$ " + Presup.Descuento.ToString(), boldTableFont)); celly.Colspan = 1; celly.HorizontalAlignment = 2; // cellz.Border = iTextSharp.text.Rectangle.LEFT_BORDER | iTextSharp.text.Rectangle.RIGHT_BORDER; itemTable.AddCell(celly); PdfPCell cellc = new PdfPCell(new Phrase("Total Oferta", boldTableFont)); cellc.Colspan = 6; cellc.HorizontalAlignment = 2; // cellz.Border = iTextSharp.text.Rectangle.LEFT_BORDER | iTextSharp.text.Rectangle.RIGHT_BORDER; itemTable.AddCell(cellc); PdfPCell cellx = new PdfPCell(new Phrase("$ " + Presup.Total.ToString(), boldTableFont)); cellx.Colspan = 1; cellx.HorizontalAlignment = 2; // cellz.Border = iTextSharp.text.Rectangle.LEFT_BORDER | iTextSharp.text.Rectangle.RIGHT_BORDER; itemTable.AddCell(cellx); PdfPCell cell = new PdfPCell(new Phrase("***Oferta válida hasta el " + Presup.FechaValidez.ToShortDateString() + "***", bodyFont)); cell.Colspan = 7; cell.HorizontalAlignment = 1; itemTable.AddCell(cell); pdfDoc.Add(itemTable); #endregion PdfContentByte cb = new PdfContentByte(writer); BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, true); cb = new PdfContentByte(writer); cb = writer.DirectContent; cb.BeginText(); cb.SetFontAndSize(bf, 8); cb.SetTextMatrix(pageSize.GetLeft(120), 20); cb.ShowText("Observaciones: " + Presup.Observaciones); cb.EndText(); cb.MoveTo(40, pdfDoc.PageSize.GetBottom(50)); cb.LineTo(pdfDoc.PageSize.Width - 40, pdfDoc.PageSize.GetBottom(50)); cb.Stroke(); pdfDoc.Close(); System.Diagnostics.Process.Start("C:\\OneDrive - EQA SAIC\\00_Trabajo de Campo\\Proyecto\\Sistema\\UI\\bin\\Debug\\Presupuesto.pdf"); } // Fin TRY catch (Exception ex) { MessageBox.Show("Errror al crear Layout. " + ex.Message); } }
private static Rectangle GetSignatureLocation(Rectangle cropBox, PdfSignatureParameters parameters) { return new Rectangle(cropBox.GetLeft(parameters.SignatureLeftMargin), cropBox.GetTop(parameters.SignatureYLocation + parameters.SignatureHeight), cropBox.Width - parameters.SignatureRightMargin, cropBox.GetTop(parameters.SignatureYLocation)); }