protected void Button1_Click(object sender, EventArgs e) { Page.Title = "Contact List"; MemoryStream PDFData = new MemoryStream(); // step 1: creation of a document-object Document document = new Document(); // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.GetInstance(document, PDFData); // step 3: we open the document document.Open(); // step 4: we add a paragraph to the document document.Add(new Paragraph(DateTime.Now.ToString())); Contact oContact = new Contact(); DataTable dtContact = oContact.LoadAll(); int numRow = dtContact.Rows.Count; int numCol = 5; iTextSharp.text.Table aTable = new iTextSharp.text.Table(numCol, numRow); aTable.AutoFillEmptyCells = true; aTable.Padding = 1; aTable.Spacing = 1; Cell cell = new Cell(new Phrase("Contact List", FontFactory.GetFont(FontFactory.TIMES, 14, Font.BOLD))); cell.Header = true; cell.Colspan = numCol; cell.BackgroundColor = Color.LIGHT_GRAY; cell.HorizontalAlignment = Element.ALIGN_CENTER; aTable.AddCell(cell); for (int i = 0; i < dtContact.Rows.Count; i++) { for (int n = 1; n <= numCol; n++) aTable.AddCell(dtContact.Rows[i][n].ToString()); } document.Add(aTable); // step 5: we close the document document.Close(); Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "application/pdf"; Response.Charset = string.Empty; Response.Cache.SetCacheability(System.Web.HttpCacheability.Public); Response.AddHeader("Content-Disposition", "attachment; filename=" + Title.Replace(" ", "").Replace(":", "-") + ".pdf"); Response.OutputStream.Write(PDFData.GetBuffer(), 0, PDFData.GetBuffer().Length); Response.OutputStream.Flush(); Response.OutputStream.Close(); Response.End(); }
public static iTextSharp.text.Table ConvertHeaderFooter(DocTemplateVers.Domain.DTO.ServiceExport.DTO_HeaderFooter HeaderFooter, float ContentWidth) { int Col = ColumnCount(HeaderFooter); iTextSharp.text.Table table = null; if (Col > 0) { float MaxWidth = ContentWidth / Col; table = new iTextSharp.text.Table(Col); if (HeaderFooter.Left != null) { table.AddCell(RenderElement(HeaderFooter.Left, MaxWidth)); } if (HeaderFooter.Center != null) { table.AddCell(RenderElement(HeaderFooter.Center, MaxWidth)); } if (HeaderFooter.Right != null) { table.AddCell(RenderElement(HeaderFooter.Right, MaxWidth)); } } return(table); }
private void RenderProjectsReports() { if (this.ProjectList != null && this.ProjectList.Count > 0) { // float[] DetailsHeaderwidths = {"100"}; // percentage iTextSharp.text.Table JobDetailstable = new iTextSharp.text.Table(1); JobDetailstable.Padding = 1; JobDetailstable.DefaultCell.BorderWidth = 1; // JobDetailstable.Widths = DetailsHeaderwidths; JobDetailstable.WidthPercentage = 100; JobDetailstable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; JobDetailstable.DefaultCell.BackgroundColor = Color.LIGHT_GRAY; Font myDetailFont = fntDetails; JobDetailstable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; JobDetailstable.AddCell(new Phrase("Projects", fntDetails)); foreach (var x in this.ProjectList) { JobDetailstable.DefaultCell.BackgroundColor = Color.WHITE; JobDetailstable.AddCell(new Phrase(x.Project_Number + " : " + x.Project_Name, fntDetails)); } JobDetailstable.DefaultCell.BorderWidth = 0; JobDetailstable.AddCell(new Phrase(" ", fntDetails)); JobDetailstable.AddCell(new Phrase(" ", fntDetails)); JobDetailstable.AddCell(new Phrase(" ", fntDetails)); JobDetailstable.AddCell(new Phrase(" ", fntDetails)); JobDetailstable.AddCell(new Phrase(" ", fntDetails)); JobDetailstable.AddCell(new Phrase(" ", fntDetails)); doc.Add(JobDetailstable); } }
public static void write_pdf() { string sFilePDF="myFile.pdf"; // step 1: creation of a document-object Document document = new Document(); try { // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(sFilePDF, FileMode.Create)); // step 3: we open the document document.Open(); // step 4: we create a table and add it to the document Table aTable = new Table(2, 2); // 2 rows, 2 columns aTable.AddCell("0.0"); aTable.AddCell("0.1"); aTable.AddCell("1.0"); aTable.AddCell("1.1"); document.Add(aTable); } catch (DocumentException de) { Console.WriteLine(de.ToString()); } catch (IOException ioe) { Console.WriteLine(ioe.ToString()); } // step 5: we close the document document.Close(); }
public static void Export(DetailsView dvGetStudent) { int rows = dvGetStudent.Rows.Count; int columns = dvGetStudent.Rows[0].Cells.Count; int pdfTableRows = rows; iTextSharp.text.Table PdfTable = new iTextSharp.text.Table(2, pdfTableRows); PdfTable.BorderWidth = 1; PdfTable.Cellpadding = 0; PdfTable.Cellspacing = 0; for (int rowCounter = 0; rowCounter < rows; rowCounter++) { for (int columnCounter = 0; columnCounter < columns; columnCounter++) { string strValue = dvGetStudent.Rows[rowCounter].Cells[columnCounter].Text; PdfTable.AddCell(strValue); } } Document Doc = new Document(); PdfWriter.GetInstance(Doc, HttpContext.Current.Response.OutputStream); Doc.Open(); Doc.Add(PdfTable); Doc.Close(); HttpContext.Current.Response.ContentType = "application/pdf"; HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=StudentDetails.pdf"); HttpContext.Current.Response.End(); }
public static void Export(DetailsView dvGetStudent, string imageFilePath, string filename) { int rows = dvGetStudent.Rows.Count; int columns = dvGetStudent.Rows[0].Cells.Count; int pdfTableRows = rows - 1; iTextSharp.text.Table PdfTable = new iTextSharp.text.Table(2, pdfTableRows); //PdfTable.BorderWidth = 1; PdfTable.Cellpadding = 0; PdfTable.Cellspacing = 0; iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageFilePath); jpg.Alignment = Element.ALIGN_CENTER; jpg.ScaleToFit(150f, 150f); string fontUrl = System.AppDomain.CurrentDomain.BaseDirectory + "Files\\arial.ttf"; BaseFont STF_Helvetica_Russian = BaseFont.CreateFont(fontUrl, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); Font font = new Font(STF_Helvetica_Russian, Font.DEFAULTSIZE, Font.NORMAL); for (int rowCounter = 1; rowCounter < rows; rowCounter++) { for (int columnCounter = 0; columnCounter < columns; columnCounter++) { string strValue = dvGetStudent.Rows[rowCounter].Cells[columnCounter].Text; PdfTable.AddCell(new Paragraph(strValue, font)); } } Document Doc = new Document(); PdfWriter.GetInstance(Doc, HttpContext.Current.Response.OutputStream); Doc.Open(); Doc.Add(jpg); Doc.Add(PdfTable); Doc.Close(); HttpContext.Current.Response.ContentType = "application/pdf"; HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + filename + ".pdf"); HttpContext.Current.Response.End(); }
/** * Creates a Table object based on this TableAttributes object. * @return a com.lowagie.text.Table object * @throws BadElementException */ public Table CreateTable() { if (content.Count == 0) throw new BadElementException("Trying to create a table without rows."); SimpleCell rowx = (SimpleCell)content[0]; int columns = 0; foreach (SimpleCell cell in rowx.Content) { columns += cell.Colspan; } float[] widths = new float[columns]; float[] widthpercentages = new float[columns]; Table table = new Table(columns); table.Alignment = alignment; table.Spacing = cellspacing; table.Padding = cellpadding; table.CloneNonPositionParameters(this); int pos; foreach (SimpleCell row in content) { pos = 0; foreach (SimpleCell cell in row.Content) { table.AddCell(cell.CreateCell(row)); if (cell.Colspan == 1) { if (cell.Width > 0) widths[pos] = cell.Width; if (cell.Widthpercentage > 0) widthpercentages[pos] = cell.Widthpercentage; } pos += cell.Colspan; } } float sumWidths = 0f; for (int i = 0; i < columns; i++) { if (widths[i] == 0) { sumWidths = 0; break; } sumWidths += widths[i]; } if (sumWidths > 0) { table.Width = sumWidths; table.Locked = true; table.Widths = widths; } else { for (int i = 0; i < columns; i++) { if (widthpercentages[i] == 0) { sumWidths = 0; break; } sumWidths += widthpercentages[i]; } if (sumWidths > 0) { table.Widths = widthpercentages; } } if (width > 0) { table.Width = width; table.Locked = true; } else if (widthpercentage > 0) { table.Width = widthpercentage; } return table; }
protected override void RenderDocument(iTS.Document doc, iTS.rtf.RtfWriter2 rtfWriter) { //iTS.Table contentTable = new iTS.Table(1); ////Me lo mette come percentualeee!!! ////contentTable.Width = 100; // *(_template.Settings.Width - (_template.Settings.MarginLeft + _template.Settings.MarginRight)) / _template.Settings.Width; //iTS.Cell body = RenderBody(); //contentTable.AddCell(body); iTS.Table contentTable = new iTS.Table(1); contentTable.AddCell(RenderBody()); try // In taluni casi la conversione manda in crash qui, con mille casini a seguire... { doc.Add(contentTable); } catch { } if (_template.Signatures != null && _template.Signatures.Count() > 0) { RenderSignature(doc); } }
protected static void SetTitle(Misc.sp_052_displayConfirmationRow row, iTextSharp.text.Table tblMain) { Cell CellTitle = new Cell(); CellTitle.Colspan = 2; CellTitle.Add(GetTitlePhrase("Rebate Form (Confirmation ID " + row.ConfirmationID + ") \n\n")); CellTitle.HorizontalAlignment = Element.ALIGN_CENTER; tblMain.AddCell(CellTitle); }
protected void Button1_Click(object sender, EventArgs e) { GridView GridView1 = gvIncome; GridView1.AllowPaging = false; GridView1.DataBind(); iTextSharp.text.Table table = new iTextSharp.text.Table(GridView1.Columns.Count); table.Cellpadding = 5; for (int x = 0; x < GridView1.Columns.Count; x++) { String cellText = Server.HtmlDecode(GridView1.HeaderRow.Cells[x].Text); iTextSharp.text.Cell cell = new iTextSharp.text.Cell(cellText); cell.BackgroundColor = new Color(System.Drawing.ColorTranslator.FromHtml("#1C5E55")); table.AddCell(cell); } for (int i = 0; i < GridView1.Rows.Count; i++) { if (GridView1.Rows[i].RowType == DataControlRowType.DataRow) { for (int j = 0; j < GridView1.Columns.Count; j++) { string cellText = Server.HtmlDecode(GridView1.Rows[i].Cells[j].Text); iTextSharp.text.Cell cell = new iTextSharp.text.Cell(cellText); if (i % 2 != 0) { cell.BackgroundColor = new Color(System.Drawing.ColorTranslator.FromHtml("#E3EAEB")); } table.AddCell(cell); } } } Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); pdfDoc.Add(table); pdfDoc.Close(); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=Income.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Write(pdfDoc); Response.End(); }
private iTextSharp.text.Table GenerateRelatedTable(DataSet dsMainTable, string strRelatedTableName, string strRelatedInfoName) { DataSet dsRelatedTable = new DataSet(); // 生成表格 BaseFont bfChinese = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); Font font20B = new Font(bfChinese, 20, iTextSharp.text.Font.BOLD); Font font20 = new Font(bfChinese, 20); Font font14B = new Font(bfChinese, 14, iTextSharp.text.Font.BOLD); Font font14 = new Font(bfChinese, 14); Font font13B = new Font(bfChinese, 13, iTextSharp.text.Font.BOLD); Font font13 = new Font(bfChinese, 13); Font font12B = new Font(bfChinese, 12, iTextSharp.text.Font.BOLD); Font font12 = new Font(bfChinese, 12); Font font11B = new Font(bfChinese, 11, iTextSharp.text.Font.BOLD); Font font11 = new Font(bfChinese, 11); Font font10B = new Font(bfChinese, 10, iTextSharp.text.Font.BOLD); Font font10 = new Font(bfChinese, 10); Font font9B = new Font(bfChinese, 9, iTextSharp.text.Font.BOLD); Font font9 = new Font(bfChinese, 9); Font font8B = new Font(bfChinese, 8, iTextSharp.text.Font.BOLD); Font font8 = new Font(bfChinese, 8); int intColumn = 0; iTextSharp.text.Table itbOutput = new iTextSharp.text.Table(intColumn); itbOutput.BorderWidth = 0; itbOutput.Cellpadding = 2; itbOutput.Cellspacing = 0; itbOutput.Width = 100; if (dsMainTable.Tables.Count > 0) { if (dsMainTable.Tables[0].Rows.Count > 0) { // 加入表头信息 Cell cellTitle = new Cell(new Paragraph(strRelatedInfoName, font11B)); cellTitle.BorderWidth = 0.5F; cellTitle.HorizontalAlignment = 1; cellTitle.VerticalAlignment = Cell.ALIGN_MIDDLE; cellTitle.Colspan = intColumn; itbOutput.AddCell(cellTitle); // 加入相关表字段名称 // 加入相关表数据 if (dsRelatedTable.Tables.Count > 0) { string strTempValue = string.Empty; foreach (DataRow drTemp in dsRelatedTable.Tables[0].Rows) { } } } } return itbOutput; }
protected override void RenderErrorDocument(iTS.Document doc) { iTS.Table contentTable = new iTextSharp.text.Table(1); contentTable.Width = _template.Settings.Width - (_template.Settings.MarginLeft + _template.Settings.MarginRight); contentTable.AddCell(RenderBody()); doc.Add(contentTable); if (_template.Signatures != null && _template.Signatures.Count() > 0) { RenderSignature(doc); } }
// // public static SimplePersonsList GetInstance(Selection selection, // Rectangle pageSize, // string reportFile) { // // if (instance == null) // instance = new SimplePersonsList(selection, pageSize, reportFile); // else { // instance.selection = selection; // instance.reportFile = reportFile; // } // // if (!this.doc.IsOpen()) // this.doc.Open(); // // return instance; // } public override void MakeReport() { Table t = new Table(3); t.Border = 0; t.DefaultCellBorder = 0; Cell cell = new Cell(); cell.HorizontalAlignment = Element.ALIGN_CENTER; t.DefaultCell = cell; // Default cell Font fuenteTitulo = FontFactory.GetFont(FontFactory.HELVETICA_OBLIQUE, 14, Font.UNDERLINE); cell = new Cell(); Chunk texto = new Chunk("Apellido", fuenteTitulo); cell.Add(texto); t.AddCell(cell); cell = new Cell(); texto = new Chunk("Nombre", fuenteTitulo); cell.Add(texto); t.AddCell(cell); cell = new Cell(); texto = new Chunk("E-Mail", fuenteTitulo); cell.Add(texto); t.AddCell(cell); Font fuenteDatos = FontFactory.GetFont(FontFactory.HELVETICA, 10); foreach (Person p in this.selection.Persons) { cell = new Cell(); texto = new Chunk(p.Surname, fuenteDatos); cell.Add(texto); t.AddCell(cell); cell = new Cell(); texto = new Chunk(p.Name, fuenteDatos); cell.Add(texto); t.AddCell(cell); cell = new Cell(); texto = new Chunk(p.EMail, fuenteDatos); cell.Add(texto); t.AddCell(cell); } this.doc.Add(t); }
private Table GeneratePDFTable(IList <ProductListView> list, string[] titles, string[] columns) { Table datatable = new Table(columns.Length); datatable.Padding = 2; datatable.Spacing = 0; float[] headerwidths; if (!CanExportAll) { headerwidths = new float[] { 85, 450, 65, 120 } } ; else { headerwidths = new float[] { 85, 200, 110, 90, 120, 60, 120, 65, 65, 65, 65, 65, 65, 65, 65, 100 } }; datatable.Widths = headerwidths; datatable.WidthPercentage = 100; datatable.DefaultCellBorderWidth = 1; datatable.BackgroundColor = Color.LIGHT_GRAY; Font myfont = new Font(FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL)); Font myfontTitle = new Font(FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.BOLD, new Color(255, 255, 255))); Cell cel = new Cell(); foreach (string title in titles) { cel = new Cell(); cel.Add(new Phrase(title, myfontTitle)); cel.BackgroundColor = new Color(0, 51, 102); cel.HorizontalAlignment = Element.ALIGN_CENTER; datatable.AddCell(cel); } datatable.EndHeaders(); datatable.BackgroundColor = Color.WHITE; foreach (object r in list) { foreach (string column in columns) { object o = r.GetType().GetProperty(column).GetValue(r, new object[0]); string val; if (o is double || o is decimal) { val = Convert.ToDouble(o).ToString("0.00"); } else { val = Convert.ToString(o); } cel = new Cell(); cel.Add(new Phrase(val, myfont)); cel.SetHorizontalAlignment(ElementTags.LEFT); if (column != "FinalInfo" && column != "Provider") { cel.HorizontalAlignment = Element.ALIGN_RIGHT; } datatable.AddCell(cel); } } return(datatable); }
private void ExportToPDF(int id) { oVariables = new Variables(intEnvironment); Document doc = new Document(); Cell cell; iTextSharp.text.Table oTable = new iTextSharp.text.Table(2); oTable.BorderWidth = 0; oTable.BorderColor = new iTextSharp.text.Color(255, 255, 255); oTable.Padding = 2; oTable.Width = 100; iTextSharp.text.Font oFontHeader = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 10, 1); iTextSharp.text.Font oFontBold = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 8, 1); iTextSharp.text.Font oFont = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 8, 0); DataSet ds; if (strRoute == "CSRC") { ds = oTPM.GetCSRC(id); } else { ds = oTPM.GetPCR(id); } int intRequest = Int32.Parse(ds.Tables[0].Rows[0]["requestid"].ToString()); int intItem = Int32.Parse(ds.Tables[0].Rows[0]["itemid"].ToString()); int intNumber = Int32.Parse(ds.Tables[0].Rows[0]["number"].ToString()); DataSet dsResource = oCustomized.GetTPM(intRequest, intItem, intNumber); string strFile = DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + "_" + intProfile.ToString() + ".pdf"; string strPath = oVariables.UploadsFolder() + strFile; string strVirtualPath = oVariables.UploadsFolder() + strFile; FileStream fs = new FileStream(strPath, FileMode.Create); PdfWriter.GetInstance(doc, fs); // PdfWriter.GetInstance(doc, Response.OutputStream); string strHeader = "ClearView PCR Information"; HeaderFooter header = new HeaderFooter(new Phrase(strHeader, new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 6)), false); header.Border = iTextSharp.text.Rectangle.NO_BORDER; header.Alignment = 2; doc.Header = header; string strFooter = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(); HeaderFooter footer = new HeaderFooter(new Phrase(strFooter, new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 6)), false); footer.Border = iTextSharp.text.Rectangle.NO_BORDER; footer.Alignment = 2; doc.Footer = footer; doc.Open(); cell = new Cell(new Phrase("Project Change Request Report", oFontHeader)); cell.Colspan = 2; cell.BackgroundColor = new iTextSharp.text.Color(169, 162, 141); oTable.AddCell(cell); oTable.AddCell(new Cell(new Phrase("Scope:", oFontBold))); oTable.AddCell(new Cell(new Phrase((ds.Tables[0].Rows[0]["scope"].ToString() == "1" ? "Yes" : "No"), oFont))); oTable.AddCell(new Cell(new Phrase("Schedule:", oFontBold))); oTable.AddCell(new Cell(new Phrase((ds.Tables[0].Rows[0]["s"].ToString() == "1" ? "Yes" : "No"), oFont))); oTable.AddCell(new Cell(new Phrase("Financial:", oFontBold))); oTable.AddCell(new Cell(new Phrase((ds.Tables[0].Rows[0]["f"].ToString() == "1" ? "Yes" : "No"), oFont))); doc.Add(oTable); //style=\"border:dashed 1px #CCCCCC\" class=\"lightdefault\" iTextSharp.text.Table oTable2 = new iTextSharp.text.Table(3); oTable2.BorderWidth = 0; oTable2.BorderColor = new iTextSharp.text.Color(255, 255, 255); oTable2.Padding = 2; oTable2.Width = 100; cell = new Cell(new Phrase("Schedule Change Details", oFontBold)); cell.Colspan = 3; oTable2.AddCell(cell); oTable2.AddCell(new Cell(new Phrase("Phase", oFontBold))); oTable2.AddCell(new Cell(new Phrase("Approved Dates", oFontBold))); oTable2.AddCell(new Cell(new Phrase("Modified Dates", oFontBold))); oTable2.AddCell(new Cell(new Phrase("Discovery", oFont))); if (dsResource.Tables[0].Rows[0]["appsd"] == DBNull.Value || dsResource.Tables[0].Rows[0]["apped"] == DBNull.Value) { oTable2.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable2.AddCell(new Cell(new Phrase(GetDate(dsResource.Tables[0].Rows[0]["appsd"].ToString()) + " - " + GetDate(dsResource.Tables[0].Rows[0]["apped"].ToString()), oFont))); } if (ds.Tables[0].Rows[0]["sds"] == DBNull.Value || ds.Tables[0].Rows[0]["sde"] == DBNull.Value) { oTable2.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable2.AddCell(new Cell(new Phrase(GetDate(ds.Tables[0].Rows[0]["sds"].ToString()) + " - " + GetDate(ds.Tables[0].Rows[0]["sde"].ToString()), oFont))); } oTable2.AddCell(new Cell(new Phrase("Planning", oFont))); if (dsResource.Tables[0].Rows[0]["appsp"] == DBNull.Value || dsResource.Tables[0].Rows[0]["appep"] == DBNull.Value) { oTable2.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable2.AddCell(new Cell(new Phrase(GetDate(dsResource.Tables[0].Rows[0]["appsp"].ToString()) + " - " + GetDate(dsResource.Tables[0].Rows[0]["appep"].ToString()), oFont))); } if (ds.Tables[0].Rows[0]["sps"] == DBNull.Value || ds.Tables[0].Rows[0]["spe"] == DBNull.Value) { oTable2.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable2.AddCell(new Cell(new Phrase(GetDate(ds.Tables[0].Rows[0]["sps"].ToString()) + " - " + GetDate(ds.Tables[0].Rows[0]["spe"].ToString()), oFont))); } oTable2.AddCell(new Cell(new Phrase("Execution", oFont))); if (dsResource.Tables[0].Rows[0]["appse"] == DBNull.Value || dsResource.Tables[0].Rows[0]["appee"] == DBNull.Value) { oTable2.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable2.AddCell(new Cell(new Phrase(GetDate(dsResource.Tables[0].Rows[0]["appse"].ToString()) + " - " + GetDate(dsResource.Tables[0].Rows[0]["appee"].ToString()), oFont))); } if (ds.Tables[0].Rows[0]["ses"] == DBNull.Value || ds.Tables[0].Rows[0]["see"] == DBNull.Value) { oTable2.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable2.AddCell(new Cell(new Phrase(GetDate(ds.Tables[0].Rows[0]["ses"].ToString()) + " - " + GetDate(ds.Tables[0].Rows[0]["see"].ToString()), oFont))); } oTable2.AddCell(new Cell(new Phrase("Closing", oFont))); if (dsResource.Tables[0].Rows[0]["appsc"] == DBNull.Value || dsResource.Tables[0].Rows[0]["appec"] == DBNull.Value) { oTable2.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable2.AddCell(new Cell(new Phrase(GetDate(dsResource.Tables[0].Rows[0]["appsc"].ToString()) + " - " + GetDate(dsResource.Tables[0].Rows[0]["appec"].ToString()), oFont))); } if (ds.Tables[0].Rows[0]["scs"] == DBNull.Value || ds.Tables[0].Rows[0]["sce"] == DBNull.Value) { oTable2.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable2.AddCell(new Cell(new Phrase(GetDate(ds.Tables[0].Rows[0]["scs"].ToString()) + " - " + GetDate(ds.Tables[0].Rows[0]["sce"].ToString()), oFont))); } doc.Add(oTable2); iTextSharp.text.Table oTable3 = new iTextSharp.text.Table(3); oTable3.BorderWidth = 0; oTable3.BorderColor = new iTextSharp.text.Color(255, 255, 255); oTable3.Padding = 2; oTable3.Width = 100; cell = new Cell(new Phrase("Financial Change Details", oFontBold)); cell.Colspan = 3; oTable3.AddCell(cell); oTable3.AddCell(new Cell(new Phrase("Phase", oFontBold))); oTable3.AddCell(new Cell(new Phrase("Approved Financials", oFontBold))); oTable3.AddCell(new Cell(new Phrase("Modified Financials", oFontBold))); double dblAppDI = GetFloat(dsResource.Tables[0].Rows[0]["appid"].ToString()); double dblAppDE = GetFloat(dsResource.Tables[0].Rows[0]["appexd"].ToString()); double dblAppDH = GetFloat(dsResource.Tables[0].Rows[0]["apphd"].ToString()); double dblAppD = dblAppDI + dblAppDE + dblAppDH; double dblFD = GetFloat(ds.Tables[0].Rows[0]["fd"].ToString()); double dblFP = GetFloat(ds.Tables[0].Rows[0]["fp"].ToString()); double dblFE = GetFloat(ds.Tables[0].Rows[0]["fe"].ToString()); double dblFC = GetFloat(ds.Tables[0].Rows[0]["fc"].ToString()); double dblAppPI = GetFloat(dsResource.Tables[0].Rows[0]["appip"].ToString()); double dblAppPE = GetFloat(dsResource.Tables[0].Rows[0]["appexp"].ToString()); double dblAppPH = GetFloat(dsResource.Tables[0].Rows[0]["apphp"].ToString()); double dblAppP = dblAppPI + dblAppPE + dblAppPH; double dblAppEI = GetFloat(dsResource.Tables[0].Rows[0]["appie"].ToString()); double dblAppEE = GetFloat(dsResource.Tables[0].Rows[0]["appexe"].ToString()); double dblAppEH = GetFloat(dsResource.Tables[0].Rows[0]["apphe"].ToString()); double dblAppE = dblAppEI + dblAppEE + dblAppEH; double dblAppCI = GetFloat(dsResource.Tables[0].Rows[0]["appic"].ToString()); double dblAppCE = GetFloat(dsResource.Tables[0].Rows[0]["appexc"].ToString()); double dblAppCH = GetFloat(dsResource.Tables[0].Rows[0]["apphc"].ToString()); double dblAppC = dblAppCI + dblAppCE + dblAppCH; oTable3.AddCell(new Cell(new Phrase("Discovery", oFont))); oTable3.AddCell(new Cell(new Phrase("$" + dblAppD.ToString("N"), oFont))); oTable3.AddCell(new Cell(new Phrase("$" + dblFD.ToString("N"), oFont))); oTable3.AddCell(new Cell(new Phrase("Planning", oFont))); oTable3.AddCell(new Cell(new Phrase("$" + dblAppP.ToString("N"), oFont))); oTable3.AddCell(new Cell(new Phrase("$" + dblFP.ToString("N"), oFont))); oTable3.AddCell(new Cell(new Phrase("Execution", oFont))); oTable3.AddCell(new Cell(new Phrase("$" + dblAppE.ToString("N"), oFont))); oTable3.AddCell(new Cell(new Phrase("$" + dblFE.ToString("N"), oFont))); oTable3.AddCell(new Cell(new Phrase("Closing", oFont))); oTable3.AddCell(new Cell(new Phrase("$" + dblAppC.ToString("N"), oFont))); oTable3.AddCell(new Cell(new Phrase("$" + dblFC.ToString("N"), oFont))); doc.Add(oTable3); iTextSharp.text.Table oTable4 = new iTextSharp.text.Table(3); oTable4.BorderWidth = 0; oTable4.BorderColor = new iTextSharp.text.Color(255, 255, 255); oTable4.Padding = 2; oTable4.Width = 100; cell = new Cell(new Phrase("Reason for PCR ", oFontBold)); cell.Colspan = 3; oTable4.AddCell(cell); string[] strReasons = ds.Tables[0].Rows[0]["reasons"].ToString().Split(';'); foreach (string str in strReasons) { if (str != "") { oTable4.AddCell(new Cell(new Phrase(str, oFont))); } } doc.Add(oTable4); doc.Close(); fs.Close(); string strURL = oVariables.UploadsFolder() + strFile; oTPM.UpdatePCRPath(id, oVariables.UploadsFolder() + strFile); strAttachement += "<tr><td><a href=\"" + strURL + "\" target=\"_blank\"><img src=\"/images/icons/pdf.gif \" align=\"absmiddle\" border=\"0\" /> View PCR Document (" + ds.Tables[0].Rows[0]["name"] + ")</a></td></tr> "; //Response.ContentType = "application/pdf"; //Response.AddHeader("Content-Disposition", "attachment; filename=closure_form.pdf"); //Response.End(); //Response.Flush(); }
protected static DocumentPDF printTable(StampaVO.Table tableTmp, DataTable dt, DocumentPDF docPDF) { if (dt == null) { return(docPDF); } //** Operazioni Preliminari //reupero del numero di colonne dal DataTable int col = tableTmp.columns.Length; int col_visible = 0; for (int j = 0; j < tableTmp.columns.Length; j++) { if (tableTmp.columns[j].visible) { col_visible++; } } try { //creazione della tabella iTextSharp.text.Table aTable = new iTextSharp.text.Table(col_visible); //Adattamento delle colonne al contenuto aTable.Padding = tableTmp.padding; aTable.Spacing = tableTmp.spacing; aTable.Width = 100; aTable.Alignment = Utils.getAlign(tableTmp.align); int[] widths = getColWidths(tableTmp, col_visible); aTable.SetWidths(widths); aTable.TableFitsPage = true; //** Aggiunta automatica dell'header della tabella for (int k = 0; k < col; k++) { if (((StampaVO.Column)tableTmp.columns[k]).visible) { StampaVO.Font font = tableTmp.headerTable.font; Font font1 = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(font.style), Utils.getColor(font.color)); string testo = ((StampaVO.Column)tableTmp.columns[k]).alias; Cell c = new Cell(new Phrase(testo, font1)); c.HorizontalAlignment = Utils.getAlign(tableTmp.headerTable.align); c.VerticalAlignment = Utils.getAlign(tableTmp.headerTable.vAlign); //c.NoWrap=true; c.BackgroundColor = Utils.getColor(tableTmp.headerTable.bgColor); aTable.AddCell(c); } } aTable.EndHeaders(); //** Popolamento automatico della tabella //Scansione dei dati for (int i = 0; i < dt.Rows.Count; i++) { //Creazione delle celle for (int h = 0; h < col; h++) { if (((StampaVO.Column)tableTmp.columns[h]).visible) { StampaVO.Font font = tableTmp.dataTable.font; Font font1 = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(font.style), Utils.getColor(font.color)); string column_name = tableTmp.columns[h].name; Cell c1 = new Cell(new Phrase(dt.Rows[i][column_name].ToString(), font1)); c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align); c1.VerticalAlignment = Utils.getAlign(tableTmp.columns[h].vAlign); if (!string.IsNullOrEmpty(tableTmp.columns[h].bgColor)) { c1.BackgroundColor = Utils.getColor(tableTmp.columns[h].bgColor); } aTable.AddCell(c1, new System.Drawing.Point(i + 1, h)); } } } docPDF.Add(aTable); } catch (Exception ex) { docPDF.Close(); writer.Close(); throw new ReportException(ErrorCode.IncompletePDFFile, "Errore nella scrittura dei dati: " + ex.Message); } return(docPDF); }
protected void GeneratePDF() { // Refresh the grid else there will be nothing to generate (no postback) this.PopulateGrid(); // Create and initialize a new document object iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LEGAL, 24, 24, 24, 24); document.PageSize.Rotate(); System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(); try { // Create an instance of the writer object iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, memoryStream); // Add some meta information to the document Label lblPageTitle = (Label)(this.Page.Master.FindControl("lblDefaultMasterPageTitle")); document.AddAuthor(lblPageTitle.Text); document.AddSubject(this.lblReportTitle.Text); // Open the document document.Open(); // Create a table to match our current summary grid iTextSharp.text.Table table = new iTextSharp.text.Table(4); table.TableFitsPage = true; // Apply spacing/padding/borders/column widths to the table table.Padding = 2; table.Spacing = 0; table.DefaultCellBorderWidth = 1; float[] headerwidths = { 40, 30, 30, 35 }; table.Widths = headerwidths; table.Width = 100; // Add report title spanning all columns iTextSharp.text.Font titleFont = new iTextSharp.text.Font(Font.GetFamilyIndex("Tahoma"), 4, Font.BOLD); titleFont.Color = new iTextSharp.text.Color(System.Drawing.Color.Firebrick); iTextSharp.text.Cell titleCell = new iTextSharp.text.Cell(); titleCell.SetHorizontalAlignment("Left"); titleCell.SetVerticalAlignment("Top"); titleCell.BackgroundColor = new iTextSharp.text.Color(System.Drawing.Color.White); titleCell.BorderWidth = 0; titleCell.Colspan = 4; titleCell.AddElement(new iTextSharp.text.Phrase(this.lblReportTitle.Text, titleFont)); table.AddCell(titleCell); // Add table headers for (int i = 0; i < this.grdReporting.Columns.Count; i++) { iTextSharp.text.Font headerCellFont = new iTextSharp.text.Font(Font.GetFamilyIndex("Tahoma"), 8, Font.NORMAL + Font.UNDERLINE); headerCellFont.Color = new iTextSharp.text.Color(System.Drawing.Color.White); iTextSharp.text.Cell headerCell = new iTextSharp.text.Cell(); headerCell.SetHorizontalAlignment("Left"); headerCell.SetVerticalAlignment("Top"); headerCell.BackgroundColor = new iTextSharp.text.Color(System.Drawing.Color.SteelBlue); headerCell.BorderColor = new iTextSharp.text.Color(System.Drawing.Color.White); headerCell.AddElement(new iTextSharp.text.Phrase(this.grdReporting.Columns[i].HeaderText, headerCellFont)); table.AddCell(headerCell); } table.EndHeaders(); // Add data to the table int j = 0; int k = 0; string phrase = ""; foreach (System.Data.DataRow row in this._pdfDataTable.Rows) { j++; // Increment the row counter k = 0; // Reset the column counter for the new row foreach (System.Data.DataColumn col in this._pdfDataTable.Columns) { k++; // Increment the column counter iTextSharp.text.Font cellFont = new iTextSharp.text.Font(Font.GetFamilyIndex("Tahoma"), 7, Font.NORMAL); if (j % 2 == 0) { cellFont.Color = new iTextSharp.text.Color(System.Drawing.Color.DarkRed); } else { cellFont.Color = new iTextSharp.text.Color(System.Drawing.Color.Black); } iTextSharp.text.Cell cell = new iTextSharp.text.Cell(); cell.SetHorizontalAlignment("Left"); cell.SetVerticalAlignment("Top"); cell.BorderColor = new iTextSharp.text.Color(System.Drawing.Color.White); if (j % 2 == 0) { cell.BackgroundColor = new iTextSharp.text.Color(System.Drawing.Color.LightGray); } else { cell.BackgroundColor = new iTextSharp.text.Color(System.Drawing.Color.White); } // Generate formatted phrase for cell. switch (col.ColumnName) { case "TotalCount": phrase = String.Format("{0:G}", row[col]); break; case "AvgSecs": case "StdDevSecs": phrase = String.Format("{0:F2}", row[col]); break; default: phrase = row[col].ToString(); break; } cell.AddElement(new iTextSharp.text.Phrase(phrase, cellFont)); table.AddCell(cell); } } // Add the table to the document document.Add(table); // Close the document document.Close(); // Show the document Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=MonthlyReportingPerformance.pdf"); Response.ContentType = "application/pdf"; Response.BinaryWrite(memoryStream.ToArray()); Response.End(); } catch (Exception xcptn) { Response.Write(xcptn.Message); } }
public static void formatoABCDIJKLM(Document document, ElectronicDocument electronicDocument, Data objTimbre, pdfPageEventHandlerPfizer pageEventHandler, Int64 idCfdi, DataTable dtEncabezado, DataTable dtDetalle, Hashtable htCFDI, HttpContext hc) { try { DAL dal = new DAL(); #region "Construimos el Documento" #region "Construimos el Encabezado" Table encabezado = new Table(7); float[] headerwidthsEncabezado = { 9, 18, 28, 28, 5, 7, 5 }; encabezado.Widths = headerwidthsEncabezado; encabezado.WidthPercentage = 100; encabezado.Padding = 1; encabezado.Spacing = 1; encabezado.BorderWidth = 0; encabezado.DefaultCellBorder = 0; encabezado.BorderColor = gris; //Agregando Imagen de Logotipo Image imgLogo = Image.GetInstance(pathIMGLOGO); imgLogo.ScalePercent(47f); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(1f, 1f); par.Add(new Chunk(imgLogo, 0, 0)); par.Add(new Chunk("", f6)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 5; cel.Colspan = 2; encabezado.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(8f, 9f); par.Add(new Chunk(htCFDI["nombreEmisor"].ToString().ToUpper(), f6B)); par.Add(new Chunk("\nRFC " + htCFDI["rfcEmisor"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor1"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor2"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor3"].ToString().ToUpper(), f6)); par.Add(new Chunk("\nTel. (52) 55 5081-8500", f6)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 5; encabezado.AddCell(cel); StringBuilder expedido = new StringBuilder(); expedido. Append("Lugar de Expedición México DF\n"). Append(htCFDI["sucursal"]).Append("\n"). Append(htCFDI["direccionExpedido1"].ToString().ToUpper()).Append("\n"). Append(htCFDI["direccionExpedido2"].ToString().ToUpper()).Append("\n"). Append(htCFDI["direccionExpedido3"].ToString().ToUpper()).Append("\n"); cel = new Cell(new Phrase(expedido.ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.Rowspan = 4; encabezado.AddCell(cel); cel = new Cell(new Phrase(htCFDI["tipoDoc"].ToString(), titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase(htCFDI["serie"].ToString().ToUpper() + electronicDocument.Data.Folio.Value, f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase("Día", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("Mes", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("Año", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); string[] fechaCFDI = Convert.ToDateTime(htCFDI["fechaCfdi"].ToString()).GetDateTimeFormats(); string HORAS = fechaCFDI[103]; string DIA = Convert.ToDateTime(htCFDI["fechaCfdi"]).Day.ToString(); string MES = Convert.ToDateTime(htCFDI["fechaCfdi"]).ToString("MMMM").ToUpper(); string ANIO = Convert.ToDateTime(htCFDI["fechaCfdi"]).Year.ToString(); cel = new Cell(new Phrase(DIA, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(MES, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(ANIO, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("No. y Año de Aprobación: " + dtEncabezado.Rows[0]["NoAp"].ToString() + " " + dtEncabezado.Rows[0]["AnoAp"].ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(HORAS, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase("CLIENTE", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BackgroundColor = azul; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; encabezado.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Receptor.Nombre.Value, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase("Termino Pago: " + electronicDocument.Data.CondicionesPago.Value, f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 1f); par.Add(new Chunk("R.F.C. " + electronicDocument.Data.Receptor.Rfc.Value + "\n", f5)); par.Add(new Chunk(htCFDI["direccionReceptor1"] + "\n", f5)); par.Add(new Chunk(htCFDI["direccionReceptor2"] + "\n", f5)); par.Add(new Chunk(htCFDI["direccionReceptor3"] + "\n", f5)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; cel.Rowspan = 5; cel.Colspan = 2; encabezado.AddCell(cel); #region "Consignado a" string nombreEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-NOMBRE"].ToString();//CE string calleEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-CALLE"].ToString();//CE 10, 11, 12 string coloniaEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-COLONIA"].ToString();//CE13 string cpEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-CP"].ToString();//CE18 string municEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-MUNIC"].ToString();//CE15 string estadoEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-ESTADO"].ToString();//CE16 string paisEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-PAIS"].ToString();//CE17 string localidadEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-LOCAL"].ToString();//CE14 string saltoEntregado = "\n"; string separador = ", "; string espacio = " "; if (nombreEntregado.Length > 0) nombreEntregado = nombreEntregado + saltoEntregado; else nombreEntregado = "" + saltoEntregado; if (calleEntregado.Length > 0) calleEntregado = calleEntregado + saltoEntregado; else calleEntregado = "" + saltoEntregado; if (coloniaEntregado.Length > 0) coloniaEntregado = coloniaEntregado + espacio; else coloniaEntregado = "" + espacio; if (cpEntregado.Length > 0) cpEntregado = ", CP " + cpEntregado + saltoEntregado; else cpEntregado = "" + separador + saltoEntregado; if (municEntregado.Length > 0) municEntregado = municEntregado + separador; else municEntregado = ""; if (localidadEntregado.Length > 0) localidadEntregado = localidadEntregado + saltoEntregado; else localidadEntregado = "" + saltoEntregado; if (estadoEntregado.Length > 0) estadoEntregado = estadoEntregado + espacio; else estadoEntregado = "" + espacio; if (paisEntregado.Length > 0) paisEntregado = paisEntregado + ""; else paisEntregado = ""; #endregion par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 1f); par.Add(new Chunk("Consignado a:\n", f5B)); par.Add(new Chunk(calleEntregado, f5)); par.Add(new Chunk(coloniaEntregado, f5)); par.Add(new Chunk(cpEntregado, f5)); par.Add(new Chunk(municEntregado, f5)); par.Add(new Chunk(localidadEntregado, f5)); par.Add(new Chunk(estadoEntregado, f5)); par.Add(new Chunk(paisEntregado, f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Rowspan = 5; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Cliente No:\n", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["clienteNo"].ToString(), f5)); par.Add(new Chunk("\nContacto:\n", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["contacto"].ToString(), f5)); par.Add(new Chunk("\nTeléfono:\n", f5B)); par.Add(new Chunk("" + "\n", f5)); if (htCFDI["serie"].ToString() == "C" || htCFDI["serie"].ToString() == "D") { par.Add(new Chunk("Zona:\n", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["zona"].ToString(), f5)); } cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 5; encabezado.AddCell(cel); if (htCFDI["serie"].ToString() == "C") { par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Vencimiento: ", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["vencimiento"].ToString(), f5B)); //CE27 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); } par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Moneda: ", f5B)); par.Add(new Chunk(electronicDocument.Data.Moneda.Value, f5)); cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); if (htCFDI["serie"].ToString() == "D" || htCFDI["serie"].ToString() == "L" || htCFDI["serie"].ToString() == "N") par.Add(new Chunk("Referencia: ", f5B)); else par.Add(new Chunk("Orden Compra: ", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["referencia"].ToString(), f5));//CE33 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); if (htCFDI["serie"].ToString() == "N") { par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Fecha Referencia: ", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["fechaRefDoc"].ToString(), f5));//CE34 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); } par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Pedido: ", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["pedido"].ToString(), f5));//CE19 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("División: ", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["division"].ToString(), f5));//CE20 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); #endregion #region "Construimos Tablas de Partidas" #region "Añadimos Detalle de Conceptos" // Creamos la tabla para insertar los conceptos de detalle de la factura StringBuilder sbOpcionalDetalle = new StringBuilder(); sbOpcionalDetalle. Append("SELECT ROW_NUMBER() OVER (ORDER BY idCfdi ASC) AS numero, "). Append("campo1 AS codigoProducto, campo18 AS codigoBarras, "). Append("campo3 AS lote, campo5 AS fechaLote, campo4 AS cantidadLote "). Append("FROM opcionalDetalle "). Append("WHERE idCfdi = @0 "); DataTable dtOpcionalDetalle = dal.QueryDT("DS_FE", sbOpcionalDetalle.ToString(), "F:I:" + idCfdi, hc); // Obtenemos los conceptos guardados en el Xml int numConceptosXml = electronicDocument.Data.Conceptos.Count; // Debido a que no siempre hacen match el número de conceptos de xml con los de opcionalDetalle armamos un Hashtable // Armamos la tabla que contendra los conceptops finales a imprimir en el Pdf DataTable dtConceptosFinal = new DataTable(); dtConceptosFinal.Columns.Add("numero", typeof(int)); dtConceptosFinal.Columns.Add("codigoBarras", typeof(string)); dtConceptosFinal.Columns.Add("codigoProducto", typeof(string)); dtConceptosFinal.Columns.Add("lote", typeof(string)); dtConceptosFinal.Columns.Add("fechaLote", typeof(string)); dtConceptosFinal.Columns.Add("cantidadLote", typeof(string)); dtConceptosFinal.Columns.Add("descripcion", typeof(string)); dtConceptosFinal.Columns.Add("cantidad", typeof(double)); dtConceptosFinal.Columns.Add("unidadMedida", typeof(string)); dtConceptosFinal.Columns.Add("precioUnitario", typeof(double)); dtConceptosFinal.Columns.Add("importe", typeof(double)); int contConceptos = 1; foreach (DataRow rowConceptos in dtOpcionalDetalle.Rows) { for (int i = contConceptos; i <= numConceptosXml; i++) { object[] arrayConceptos = new object[11]; if (Convert.ToInt32(rowConceptos["numero"]) == i) { arrayConceptos[0] = Convert.ToInt32(rowConceptos["numero"]); arrayConceptos[1] = rowConceptos["codigoBarras"].ToString(); arrayConceptos[2] = rowConceptos["codigoProducto"].ToString(); arrayConceptos[3] = rowConceptos["lote"].ToString(); arrayConceptos[4] = rowConceptos["fechaLote"].ToString(); arrayConceptos[5] = rowConceptos["cantidadLote"].ToString(); arrayConceptos[6] = electronicDocument.Data.Conceptos[i - 1].Descripcion.Value; arrayConceptos[7] = electronicDocument.Data.Conceptos[i - 1].Cantidad.Value; arrayConceptos[8] = electronicDocument.Data.Conceptos[i - 1].Unidad.Value; arrayConceptos[9] = electronicDocument.Data.Conceptos[i - 1].ValorUnitario.Value; arrayConceptos[10] = electronicDocument.Data.Conceptos[i - 1].Importe.Value; } else { arrayConceptos[0] = 0; arrayConceptos[1] = string.Empty; arrayConceptos[2] = string.Empty; arrayConceptos[3] = string.Empty; arrayConceptos[4] = string.Empty; arrayConceptos[5] = string.Empty; arrayConceptos[6] = electronicDocument.Data.Conceptos[i - 1].Descripcion.Value; arrayConceptos[7] = electronicDocument.Data.Conceptos[i - 1].Cantidad.Value; arrayConceptos[8] = electronicDocument.Data.Conceptos[i - 1].Unidad.Value; arrayConceptos[9] = electronicDocument.Data.Conceptos[i - 1].ValorUnitario.Value; arrayConceptos[10] = electronicDocument.Data.Conceptos[i - 1].Importe.Value; } dtConceptosFinal.Rows.Add(arrayConceptos); break; } contConceptos++; } // Una vez llena la tabla final de conceptos procedemos a generar la tabla de detalle. #region"Tabla Detalle" Table encabezadoDetalle = new Table(7); float[] headerEncabezadoDetalle = { 5, 12, 11, 40, 9, 10, 12 }; encabezadoDetalle.Widths = headerEncabezadoDetalle; encabezadoDetalle.WidthPercentage = 100F; encabezadoDetalle.Padding = 1; encabezadoDetalle.Spacing = 1; encabezadoDetalle.BorderWidth = 0; encabezadoDetalle.DefaultCellBorder = 0; encabezadoDetalle.BorderColor = gris; // Número cel = new Cell(new Phrase("No", titulo)); cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Còdigo de Barras cel = new Cell(new Phrase("Cod. Barras", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Código cel = new Cell(new Phrase("Código", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Descripción cel = new Cell(new Phrase("Descripción", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Cantidad cel = new Cell(new Phrase("Cantidad", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Precio Unitario cel = new Cell(new Phrase("Precio Unitario", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Importe cel = new Cell(new Phrase("Importe", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); PdfPCell cell; PdfPTable tableConceptos = new PdfPTable(7); tableConceptos.SetWidths(new int[7] { 5, 12, 11, 40, 9, 10, 12 }); // tableConceptos.WidthPercentage = 91.5F; tableConceptos.WidthPercentage = 100F; Font fontLbl = new Font(Font.HELVETICA, 7, Font.BOLD, new Color(43, 145, 175)); Font fontVal = new Font(Font.HELVETICA, 7, Font.NORMAL); foreach (DataRow rowConceptos in dtConceptosFinal.Rows) { // Número cell = new PdfPCell(new Phrase(rowConceptos["numero"].ToString(), f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = (float).5; cell.BorderWidthRight = 0; cell.BorderWidthBottom = (float).5; cell.BorderColor = gris; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; tableConceptos.AddCell(cell); // Código de Barras cell = new PdfPCell(new Phrase(rowConceptos["codigoBarras"].ToString(), f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = (float).5; cell.BorderWidthRight = 0; cell.BorderWidthBottom = (float).5; cell.BorderColor = gris; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; tableConceptos.AddCell(cell); // Código de Producto cell = new PdfPCell(new Phrase(rowConceptos["codigoProducto"].ToString(), f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = (float).5; cell.BorderWidthRight = 0; cell.BorderWidthBottom = (float).5; cell.BorderColor = gris; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; tableConceptos.AddCell(cell); // Tabla de Descripción PdfPTable tableDesc = new PdfPTable(3); tableDesc.WidthPercentage = 100; // Descripción cell = new PdfPCell(new Phrase(rowConceptos["descripcion"].ToString(), f5)); cell.Border = 0; cell.NoWrap = true; cel.VerticalAlignment = Element.ALIGN_MIDDLE; cell.Colspan = 3; tableDesc.AddCell(cell); // Lote //Phrase pLote = new Phrase(); //Chunk cLoteLbl = new Chunk("Lote : \n", fontLbl); //Chunk cLoteVal = new Chunk(rowConceptos["lote"].ToString().Replace("*", "\n"), fontVal); //pLote.Add(cLoteLbl); //pLote.Add(cLoteVal); //par.KeepTogether = true; //par.SetLeading(7f, 1f); par = new Paragraph(); par.Add(new Chunk("Lote\n\n", f5L)); par.Add(new Chunk(rowConceptos["lote"].ToString().Replace("*", "\n"), f5)); cell = new PdfPCell(par); cell.Border = 0; cell.HorizontalAlignment = Element.ALIGN_LEFT; tableDesc.AddCell(cell); //// Cantidad //Phrase pCantidad = new Phrase(); //Chunk cCantidadLbl = new Chunk("Cantidad\n", fontLbl); //Chunk cCantidadVal = new Chunk(rowConceptos["cantidadLote"].ToString().Replace("*", "\n"), fontVal); //pCantidad.Add(cCantidadLbl); //pCantidad.Add(cCantidadVal); //cell = new PdfPCell(pCantidad); //cell.Border = 1; //cell.HorizontalAlignment = Element.ALIGN_CENTER; //cell.VerticalAlignment = Element.ALIGN_MIDDLE; //tableDesc.AddCell(cell); par = new Paragraph(); par.Add(new Chunk("Cantidad\n\n", f5L)); par.Add(new Chunk(rowConceptos["cantidadLote"].ToString().Replace("*", "\n"), f5)); cell = new PdfPCell(par); cell.Border = 0; cell.HorizontalAlignment = Element.ALIGN_LEFT; tableDesc.AddCell(cell); //// Fecha Lote //Phrase pFecLote = new Phrase(); //Chunk cFecLoteLbl; //Chunk cFecLoteVal; par = new Paragraph(); //if (electronicDocument.Data.Serie.Value == "C" || electronicDocument.Data.Serie.Value == "D" || electronicDocument.Data.Serie.Value == "K" || electronicDocument.Data.Serie.Value == "L" || electronicDocument.Data.Serie.Value == "M" || electronicDocument.Data.Serie.Value == "N") //{ // par.Add(new Chunk("", fontLbl)); // par.Add(new Chunk("", fontVal)); // //cFecLoteLbl = new Chunk("11", fontLbl); // //cFecLoteVal = new Chunk("22", fontVal); //} //else if (electronicDocument.Data.Serie.Value == "A") { par.Add(new Chunk("Expiración\n\n", f5L)); par.Add(new Chunk(rowConceptos["fechaLote"].ToString().Replace("*", "\n"), f5)); //cFecLoteLbl = new Chunk("Fecha Lote : ", fontLbl); //cFecLoteVal = new Chunk(rowConceptos["fechaLote"].ToString().Replace("*", "\n"), fontVal); } else { par.Add(new Chunk("")); par.Add(new Chunk("", f5)); //cFecLoteLbl = new Chunk("Fecha Lote : ", fontLbl); //cFecLoteVal = new Chunk(rowConceptos["fechaLote"].ToString().Replace("*", "\n"), fontVal); } //pFecLote.Add(cFecLoteLbl); //pFecLote.Add(cFecLoteVal); cell = new PdfPCell(par); cell.Border = 0; cell.HorizontalAlignment = Element.ALIGN_LEFT; tableDesc.AddCell(cell); // Número de Cantidad cell = new PdfPCell(new Phrase("")); cell.Border = 0; cell.Colspan = 3; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; tableDesc.AddCell(cell); cell = new PdfPCell(tableDesc); cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.BorderWidthTop = 0; cell.BorderWidthLeft = (float).5; cell.BorderWidthRight = 0; cell.BorderWidthBottom = (float).5; cell.BorderColor = gris; tableConceptos.AddCell(cell); // Cantidad cell = new PdfPCell(new Phrase(rowConceptos["cantidad"] + " " + rowConceptos["unidadMedida"], f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = (float).5; cell.BorderWidthRight = 0; cell.BorderWidthBottom = (float).5; cell.BorderColor = gris; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; tableConceptos.AddCell(cell); // Precio Unitario cell = new PdfPCell(new Phrase(Convert.ToDouble(rowConceptos["precioUnitario"]).ToString("C", _ci), f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = (float).5; cell.BorderWidthRight = 0; cell.BorderWidthBottom = (float).5; cell.BorderColor = gris; cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.VerticalAlignment = Element.ALIGN_MIDDLE; tableConceptos.AddCell(cell); // Importe cell = new PdfPCell(new Phrase(Convert.ToDouble(rowConceptos["importe"]).ToString("C", _ci), f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = (float).5; cell.BorderWidthRight = (float).5; cell.BorderWidthBottom = (float).5; cell.BorderColor = gris; cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.VerticalAlignment = Element.ALIGN_MIDDLE; tableConceptos.AddCell(cell); } #endregion #endregion #endregion #region "Construimos el Comentarios" Table comentarios = new Table(7); float[] headerwidthsComentarios = { 9, 18, 28, 28, 7, 5, 5 }; comentarios.Widths = headerwidthsComentarios; comentarios.WidthPercentage = 100; comentarios.Padding = 1; comentarios.Spacing = 1; comentarios.BorderWidth = 0; comentarios.DefaultCellBorder = 0; comentarios.BorderColor = gris; cel = new Cell(new Phrase("Cantidad:", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 3; comentarios.AddCell(cel); cel = new Cell(new Phrase(dtEncabezado.Rows[0]["cantidadLetra"].ToString(), f5));//CE26 cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; cel.Rowspan = 3; comentarios.AddCell(cel); cel = new Cell(new Phrase("Sub Total", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.SubTotal.Value.ToString("C", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); double importe = 0; double tasa = 0; for (int i = 0; i < electronicDocument.Data.Impuestos.Traslados.Count; i++) { if (electronicDocument.Data.Impuestos.Traslados[i].Tipo.Value == "IVA") { importe = electronicDocument.Data.Impuestos.Traslados[i].Importe.Value; tasa = electronicDocument.Data.Impuestos.Traslados[i].Tasa.Value; break; } } cel = new Cell(new Phrase("IVA " + tasa + " %", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.TotalTraslados.Value.ToString("C", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Total", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Total.Value.ToString("C", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Observaciones:", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(dtEncabezado.Rows[0]["observaciones"].ToString(), f5)); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 6; comentarios.AddCell(cel); #endregion #region "Construimos Tabla Especial" Table especial = new Table(5); float[] headerwidthsEspecial = { 20, 20, 20, 20, 20 }; especial.Widths = headerwidthsEspecial; especial.WidthPercentage = 100; especial.Padding = 1; especial.Spacing = 1; especial.BorderWidth = 0; especial.DefaultCellBorder = 0; especial.BorderColor = blanco; cel = new Cell(new Phrase("", f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = blanco; cel.Colspan = 5; especial.AddCell(cel); #endregion #region "Construimos Tabla de Datos CFDI" DefaultSplitCharacter split = new DefaultSplitCharacter(); Table adicional = new Table(3); float[] headerwidthsAdicional = { 20, 25, 55 }; adicional.Widths = headerwidthsAdicional; adicional.WidthPercentage = 100; adicional.Padding = 1; adicional.Spacing = 1; adicional.BorderWidth = (float).5; adicional.DefaultCellBorder = 1; adicional.BorderColor = gris; if (timbrar) { #region "Generamos Quick Response Code" byte[] bytesQRCode = new byte[0]; if (timbrar) { // Generamos el Quick Response Code (QRCode) string re = electronicDocument.Data.Emisor.Rfc.Value; string rr = electronicDocument.Data.Receptor.Rfc.Value; string tt = String.Format("{0:F6}", electronicDocument.Data.Total.Value); string id = objTimbre.Uuid.Value; StringBuilder sbCadenaQRCode = new StringBuilder(); sbCadenaQRCode. Append("?"). Append("re=").Append(re). Append("&"). Append("rr=").Append(rr). Append("&"). Append("tt=").Append(tt). Append("&"). Append("id=").Append(id); BarcodeLib.Barcode.QRCode.QRCode barcode = new BarcodeLib.Barcode.QRCode.QRCode(); barcode.Data = sbCadenaQRCode.ToString(); barcode.ModuleSize = 3; barcode.LeftMargin = 0; barcode.RightMargin = 10; barcode.TopMargin = 0; barcode.BottomMargin = 0; barcode.Encoding = BarcodeLib.Barcode.QRCode.QRCodeEncoding.Auto; barcode.Version = BarcodeLib.Barcode.QRCode.QRCodeVersion.Auto; barcode.ECL = BarcodeLib.Barcode.QRCode.ErrorCorrectionLevel.L; bytesQRCode = barcode.drawBarcodeAsBytes(); } #endregion Image imageQRCode = Image.GetInstance(bytesQRCode); imageQRCode.Alignment = (Image.TEXTWRAP | Image.ALIGN_LEFT); imageQRCode.ScaleToFit(90f, 90f); imageQRCode.IndentationLeft = 9f; imageQRCode.SpacingAfter = 9f; imageQRCode.BorderColorTop = Color.WHITE; cel = new Cell(imageQRCode); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 6; adicional.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("SELLO DIGITAL DEL EMISOR\n", f5L)); par.Add(new Chunk(electronicDocument.Data.Sello.Value, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Colspan = 2; adicional.AddCell(cel); cel = new Cell(new Phrase("FOLIO FISCAL:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase(objTimbre.Uuid.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("FECHA Y HORA DE CERTIFICACION:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); string[] fechaTimbrado = Convert.ToDateTime(objTimbre.FechaTimbrado.Value).GetDateTimeFormats('s'); cel = new Cell(new Phrase(fechaTimbrado[0], f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL SAT:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase(objTimbre.NumeroCertificadoSat.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL EMISOR:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; adicional.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.NumeroCertificado.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = (float).5; adicional.AddCell(cel); string lbRegimen = "REGIMEN FISCAL APLICABLE: "; StringBuilder regimenes = new StringBuilder(); if (electronicDocument.Data.Emisor.Regimenes.IsAssigned) { for (int i = 0; i < electronicDocument.Data.Emisor.Regimenes.Count; i++) { regimenes.Append(electronicDocument.Data.Emisor.Regimenes[i].Regimen.Value).Append("\n"); } } else { regimenes.Append(""); lbRegimen = ""; } string cuenta = electronicDocument.Data.NumeroCuentaPago.IsAssigned ? electronicDocument.Data.NumeroCuentaPago.Value : ""; par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("TIPO DE COMPROBANTE: ", f5L)); par.Add(new Chunk(electronicDocument.Data.TipoComprobante.Value + " | ", f5)); par.Add(new Chunk("Moneda: ", f5L)); par.Add(new Chunk(electronicDocument.Data.Moneda.Value + " | ", f5)); par.Add(new Chunk("TASA DE CAMBIO: ", f5L)); string tasaCambio = electronicDocument.Data.TipoCambio.Value; if (tasaCambio.Length > 0) { par.Add(new Chunk(Convert.ToDouble(tasaCambio).ToString("C", _ci) + " | ", f5)); } else { par.Add(new Chunk(" | ", f5)); } par.Add(new Chunk("FORMA DE PAGO: ", f5L)); par.Add(new Chunk(electronicDocument.Data.FormaPago.Value + "\n", f5)); par.Add(new Chunk("MÉTODO DE PAGO: ", f5L)); par.Add(new Chunk(electronicDocument.Data.MetodoPago.Value + " | ", f5)); par.Add(new Chunk("NÚMERO DE CUENTA: ", f5L)); par.Add(new Chunk(cuenta + " | ", f5)); par.Add(new Chunk(lbRegimen, f5L)); par.Add(new Chunk(regimenes.ToString(), f5)); cel.BorderColor = gris; cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; cel.BorderColor = gris; adicional.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("CADENA ORIGINAL DEL COMPLEMENTO DE CERTIFICACIÓN DIGITAL DEL SAT\n", f5L)); par.Add(new Chunk(electronicDocument.FingerPrintPac, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Colspan = 3; adicional.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 0f); par.Add(new Chunk("SELLO DIGITAL DEL SAT\n", f5L)); par.Add(new Chunk(objTimbre.SelloSat.Value, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 3; adicional.AddCell(cel); } #endregion #region "Construimos Tabla Adicional Datos de Pago" Table pago = new Table(5); float[] headerwidthsPago = { 40, 10, 20, 10, 20 }; pago.Widths = headerwidthsPago; pago.WidthPercentage = 100; pago.Padding = 1; pago.Spacing = 1; pago.BorderWidth = (float).5; pago.DefaultCellBorder = 1; pago.BorderColor = gris; cel = new Cell(new Phrase("Para ejecutar su pago para consultas", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Para efectuar su pago", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; pago.AddCell(cel); cel = new Cell(new Phrase("Información del Cliente", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; pago.AddCell(cel); string[] ejecutarPago = dtEncabezado.Rows[0]["paraConsultas"].ToString().Split(new Char[] { '*' });//CE23 string[] pagoDatos = dtEncabezado.Rows[0]["efectuarPago"].ToString().Split(new Char[] { '*' });//CE21 par = new Paragraph(); par.SetLeading(7f, 0f); if (ejecutarPago.Length > 0) par.Add(new Chunk(ejecutarPago[0] + "\n", f5)); else par.Add(new Chunk("\n", f5)); if (ejecutarPago.Length > 1) par.Add(new Chunk(ejecutarPago[1] + "\n", f5)); else par.Add(new Chunk("\n", f5)); if (ejecutarPago.Length > 2) par.Add(new Chunk(ejecutarPago[2] + "\n", f5)); else par.Add(new Chunk("\n", f5)); if (ejecutarPago.Length > 3) par.Add(new Chunk(ejecutarPago[3] + "\n", f5)); else par.Add(new Chunk("\n", f5)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Rowspan = 6; pago.AddCell(cel); cel = new Cell(new Phrase("Banco:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); if (pagoDatos.Length > 0) par.Add(new Chunk(pagoDatos[0], f5)); else par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Cliente:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Receptor.Nombre.Value, f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Cuenta:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); if (pagoDatos.Length > 1) par.Add(new Chunk(pagoDatos[1], f5)); else par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("No. Cliente:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase(dtEncabezado.Rows[0]["clienteNo"].ToString(), f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); if (htCFDI["serie"].ToString() == "B" || htCFDI["serie"].ToString() == "D" || htCFDI["serie"].ToString() == "J" || htCFDI["serie"].ToString() == "L" || htCFDI["serie"].ToString() == "N") { cel = new Cell(new Phrase("", f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; pago.AddCell(cel); } else { cel = new Cell(new Phrase("SWIFT:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); if (pagoDatos.Length > 3) cel = new Cell(new Phrase(pagoDatos[3], f5)); else cel = new Cell(new Phrase("", f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); } cel = new Cell(new Phrase("Factura No:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase(htCFDI["serie"].ToString().ToUpper() + "-" + electronicDocument.Data.Folio.Value.ToString(), f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Moneda:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); if (pagoDatos.Length > 4) par.Add(new Chunk(pagoDatos[4], f5)); else par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Fecha Factura", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); string[] fechaFactura = Convert.ToDateTime(objTimbre.FechaTimbrado.Value).GetDateTimeFormats('s'); cel = new Cell(new Phrase(DIA + "/" + MES + "/" + ANIO, f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Beneficiario:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); if (pagoDatos.Length > 5) par.Add(new Chunk(pagoDatos[5], f5)); else par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Valor Total:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Total.Value.ToString("C", _ci), f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Dirección:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; pago.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); if (pagoDatos.Length > 4) par.Add(new Chunk(dtEncabezado.Rows[0]["direccionPie"].ToString(), f5));//CE22 else par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; pago.AddCell(cel); if (htCFDI["serie"].ToString() == "C") { cel = new Cell(new Phrase("Fecha Vencimiento:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; pago.AddCell(cel); cel = new Cell(new Phrase(dtEncabezado.Rows[0]["vencimiento"].ToString(), f5B)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; pago.AddCell(cel); } else { cel = new Cell(new Phrase("Moneda:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; pago.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Moneda.Value, f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; pago.AddCell(cel); } #endregion #region "Construimos Tabla del Footer" PdfPTable footer = new PdfPTable(1); footer.WidthPercentage = 100; footer.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; cell = new PdfPCell(new Phrase("", f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.BorderWidthBottom = 0; footer.AddCell(cell); cell = new PdfPCell(new Phrase("ESTE DOCUMENTO ES UNA REPRESENTACIÓN IMPRESA DE UN CFDI", titulo)); cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = azul; cell.BorderWidthTop = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.BorderWidthBottom = 0; footer.AddCell(cell); #endregion pageEventHandler.encabezado = encabezado; pageEventHandler.encPartidas = encabezadoDetalle; pageEventHandler.footer = footer; document.Open(); document.Add(tableConceptos); document.Add(comentarios); document.Add(especial); document.Add(adicional); document.Add(pago); #endregion } catch (Exception ex) { string exe = ex.Message; } }
public iTextSharp.text.Table GenerateCoreReport(String RptDate) { iTextSharp.text.Table datatable = new iTextSharp.text.Table(10); datatable.Padding = 4.0F; datatable.Spacing = 0.0F; //datatable.setBorder(Rectangle.NO_BORDER); int[] headerwidths = { 10, 24, 12, 12, 7, 7, 7, 7, 1, 1 }; datatable.SetWidths(headerwidths); datatable.Width = 100; // the first cell spans 10 columns Cell cell = new Cell(new Phrase("Daily Production Report For " + RptDate, FontFactory.GetFont(FontFactory.HELVETICA, 18, iTextSharp.text.Font.BOLD))); cell.HorizontalAlignment = 1; cell.Leading = 30; cell.Colspan = 10; cell.Border = iTextSharp.text.Rectangle.NO_BORDER; cell.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY; datatable.AddCell(cell); // These cells span 2 rows datatable.DefaultCellBorderWidth = 2; datatable.DefaultHorizontalAlignment = 1; datatable.DefaultRowspan = 2; datatable.AddCell("User Id"); datatable.AddCell(new Phrase("Name", FontFactory.GetFont(FontFactory.HELVETICA, 14, iTextSharp.text.Font.BOLD))); datatable.AddCell("Work order"); datatable.AddCell("Comments"); // This cell spans the remaining 6 columns in 1 row datatable.DefaultRowspan = 1; datatable.DefaultColspan = 6; datatable.AddCell("Hours"); // These cells span 1 row and 1 column datatable.DefaultColspan = 1; datatable.AddCell("Fab."); datatable.AddCell("Finish"); datatable.AddCell("Eng."); datatable.AddCell("Misc."); datatable.AddCell(""); datatable.AddCell(""); //Here goes the Outer Loop to get the Project Information for the Day.Get the Project Name and display Here. whitfield_prod_reports _wproj = new whitfield_prod_reports(); DataSet _mOuter = _wproj.GetProjectReportOuter(RptDate); DataTable dtProject = _mOuter.Tables[0]; foreach (DataRow dProjRow in dtProject.Rows) { String _projNumber = dProjRow["TWC_Proj_Number"] == DBNull.Value ? "" : dProjRow["TWC_Proj_Number"].ToString(); String _projName = dProjRow["ProjName"] == DBNull.Value ? "" : dProjRow["ProjName"].ToString(); String _rptNumber = dProjRow["twc_report_number"] == DBNull.Value ? "" : dProjRow["twc_report_number"].ToString(); Cell cell1 = new Cell(new Phrase(_projName + '(' + _projNumber + ')' , FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.BOLD))); cell1.HorizontalAlignment = 1; cell1.Leading = 30; cell1.Colspan = 10; cell1.Border = iTextSharp.text.Rectangle.TOP_BORDER; cell1.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY; datatable.AddCell(cell1); datatable.DefaultCellBorderWidth = 1; datatable.DefaultRowspan = 1; //Here Goes the Inner Loop for the Employees worked on the Project. DataSet _mInner = _wproj.GetProjectReportInner(Convert.ToInt32(_rptNumber), Convert.ToInt32(_projNumber)); DataTable dtActivity = _mInner.Tables[0]; foreach (DataRow drActivity in dtActivity.Rows) { datatable.DefaultHorizontalAlignment = 1; datatable.AddCell(drActivity["loginid"] == DBNull.Value ? "" : drActivity["loginid"].ToString()); datatable.AddCell(drActivity["UName"] == DBNull.Value ? "" : drActivity["UName"].ToString()); datatable.AddCell(drActivity["Description"] == DBNull.Value ? "" : drActivity["Description"].ToString()); datatable.AddCell(drActivity["empl_comments"] == DBNull.Value ? "" : drActivity["empl_comments"].ToString()); datatable.DefaultHorizontalAlignment = 0; datatable.AddCell(drActivity["fab_hours"] == DBNull.Value ? "0" : drActivity["fab_hours"].ToString()); datatable.AddCell(drActivity["fin_hours"] == DBNull.Value ? "0" : drActivity["fin_hours"].ToString()); datatable.AddCell(drActivity["eng_hours"] == DBNull.Value ? "0" : drActivity["eng_hours"].ToString()); datatable.AddCell(drActivity["misc_hours"] == DBNull.Value ? "0" : drActivity["misc_hours"].ToString()); _totFabHours += Convert.ToInt32(drActivity["fab_hours"] == DBNull.Value ? "0" : drActivity["fab_hours"].ToString()); _totFinHours += Convert.ToInt32(drActivity["fin_hours"] == DBNull.Value ? "0" : drActivity["fin_hours"].ToString()); _totEngHours += Convert.ToInt32(drActivity["eng_hours"] == DBNull.Value ? "0" : drActivity["eng_hours"].ToString()); _totMiscHours += Convert.ToInt32(drActivity["misc_hours"] == DBNull.Value ? "0" : drActivity["misc_hours"].ToString()); datatable.AddCell(""); datatable.AddCell(""); } //Here goes the SubTotal Per project.. Dont Forget. datatable.DefaultCellBorderWidth = 1; datatable.DefaultRowspan = 1; datatable.DefaultHorizontalAlignment = 1; datatable.AddCell(""); datatable.AddCell("Subtotal:"); datatable.AddCell(""); datatable.AddCell(""); datatable.DefaultHorizontalAlignment = 0; datatable.AddCell(_totFabHours.ToString()); datatable.AddCell(_totFinHours.ToString()); datatable.AddCell(_totEngHours.ToString()); datatable.AddCell(_totMiscHours.ToString()); datatable.AddCell(""); datatable.AddCell(""); //Subtotal calculation ends here. _totFabHours = 0; _totFinHours = 0; _totEngHours = 0; _totMiscHours = 0; } return datatable; }
//Se genera el PDF public void VariasPaginas(string OT, string NombreOT, string FI, string FT, string Check) { //inicio variables int CantGuias = 0; string tirajeTotal = ""; int totalDesp = 0; //fin variables List <DespachoPDF> lista = ListDespacho(OT, NombreOT, FI, FT, Check); MemoryStream MStream = new MemoryStream(); Document document = new Document(PageSize.A4.Rotate(), 30, 30, 60, 30); PdfWriter writer = PdfWriter.GetInstance(document, MStream); writer.CloseStream = false; itsEvents ev = new itsEvents(); writer.PageEvent = ev; BaseFont bftime = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false); Font time = new Font(bftime, 16, Font.BOLD, Color.BLACK); if (FI == "01/01/1900" || FT == ":01/01/1900") { info = "INFORME DIARIO \nFecha : " + DateTime.Now.ToString("dd/MM/yyyy") + " ";// Nombre : " + NombreOT + " } else { if (FI == FT) { info = "INFORME DIARIO \nFecha : " + FI + " "; } else { info = "INFORME DIARIO \nFecha Inicio:" + FI + " Fecha Termino: " + FT; } } Paragraph para = new Paragraph(" ", time);//" Informe Despachos por OT \n", time HeaderFooter header = new HeaderFooter(para, false); header.Alignment = Element.ALIGN_CENTER; header.Border = 0; document.Header = header; document.Open(); int columnCount = 7; int rowCount = lista.Count; int tableRows = rowCount + 3; iTextSharp.text.Table grdTable = new iTextSharp.text.Table(columnCount, tableRows); // grdTable.Width = 100; //int[] w = new int[] { 12, 13, 35, 60, 25, 15, 20, 2 }; //int[] w = new int[] { 8, 18, 36, 68, 15, 10, 8 }; ORIGNAL int[] w = new int[] { 12, 13, 35, 60, 25, 15, 20 }; grdTable.SetWidths(w); grdTable.BorderColor = new iTextSharp.text.Color(0); grdTable.BorderWidth = 1;//1 grdTable.Cellpadding = 15; grdTable.Cellspacing = -15; int[] widths = new int[lista.Count]; int contador = 0; foreach (DespachoPDF des in lista) { if ((contador % 2) == 0) { grdTable.DefaultCell.BackgroundColor = new iTextSharp.text.Color(255, 255, 255); grdTable.Cellpadding = 1; grdTable.Cellspacing = 0; //grdTable.DefaultCell.BorderColor = new iTextSharp.text.Color(255, 255, 255); } else { grdTable.DefaultCell.BackgroundColor = new iTextSharp.text.Color(210, 210, 210); grdTable.Cellpadding = 1; grdTable.Cellspacing = 0; //grdTable.DefaultCell.BorderColor = new iTextSharp.text.Color(255, 255, 255); } bftime = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false); time = new Font(bftime, 9, Font.NORMAL, Color.BLACK); grdTable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; grdTable.AddCell(new Paragraph(des.OT, time)); grdTable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT; grdTable.AddCell(new Paragraph(des.guia.ToString(), time)); grdTable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; grdTable.AddCell(new Paragraph(des.NombreOT, time)); grdTable.AddCell(new Paragraph(des.Cliente, time)); grdTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; grdTable.AddCell(new Paragraph(des.FechaImpresion.ToString(), time)); grdTable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT; grdTable.AddCell(new Paragraph(des.TirajeTotal, time)); grdTable.AddCell(new Paragraph(des.Despachado, time)); contador++; totalDesp = totalDesp + des.Rut; CantGuias = CantGuias + 1; tirajeTotal = des.TirajeTotal; } //// //iTextSharp.text.Table grdTable2 = new iTextSharp.text.Table(3, 3); //// //grdTable2.Width = 100; //int[] w2 = new int[] { 100, 15, 10 }; //grdTable2.SetWidths(w2); //grdTable2.BorderColor = new iTextSharp.text.Color(0); //grdTable2.BorderWidth = 0; //grdTable2.Cellpadding = 1;//15 ////grdTable2.Cellspacing = -15; //grdTable2.DefaultCell.Border = 0; //grdTable2.AddCell(new Paragraph("", time));//1 //grdTable2.DefaultCell.BackgroundColor = new iTextSharp.text.Color(210, 210, 210); //grdTable2.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; //grdTable2.DefaultCell.Border = 1; //grdTable2.DefaultCell.BorderWidthLeft = 1; //grdTable2.DefaultCell.BorderWidthRight = 1; //grdTable2.AddCell(new Paragraph("Cantidad Guías: ", time)); //grdTable2.DefaultCell.BackgroundColor = new iTextSharp.text.Color(255, 255, 255); //grdTable2.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT; //grdTable2.AddCell(new Paragraph(" " + CantGuias.ToString("N0"), time)); //grdTable2.DefaultCell.Border = 0; //grdTable2.AddCell(new Paragraph("", time));//2 //grdTable2.DefaultCell.BackgroundColor = new iTextSharp.text.Color(210, 210, 210); //grdTable2.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; //grdTable2.DefaultCell.Border = 1; //grdTable2.DefaultCell.BorderWidthLeft = 1; //grdTable2.DefaultCell.BorderWidthRight = 1; //grdTable2.AddCell(new Paragraph("Tiraje Total: ", time)); //grdTable2.DefaultCell.BackgroundColor = new iTextSharp.text.Color(255, 255, 255); //grdTable2.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT; //grdTable2.AddCell(new Paragraph(" " + tirajeTotal, time)); //grdTable2.DefaultCell.Border = 0; //grdTable2.AddCell(new Paragraph("", time));//3 //grdTable2.DefaultCell.BackgroundColor = new iTextSharp.text.Color(210, 210, 210); //grdTable2.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; //grdTable2.DefaultCell.Border = 1; //grdTable2.DefaultCell.BorderWidthLeft = 1; //grdTable2.DefaultCell.BorderWidthRight = 1; //grdTable2.DefaultCell.BorderWidthBottom = 1; //grdTable2.AddCell(new Paragraph("Total Despachado: ", time)); //grdTable2.DefaultCell.BackgroundColor = new iTextSharp.text.Color(255, 255, 255); //grdTable2.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT; //grdTable2.AddCell(new Paragraph(" " + totalDesp.ToString("N0"), time)); document.Add(grdTable); //document.Add(new Paragraph("\n")); //document.Add(grdTable2); document.Close(); //var context = HttpContext.Current; Response.ContentType = "application/pdf"; Response.Buffer = true; Response.ClearContent(); Response.ClearHeaders(); string fecha = ""; if (FI == "01/01/1900" || FI == "") { fecha = DateTime.Now.ToString("dd/MM/yyyy"); } else { fecha = FI; } Response.AddHeader("Content-Disposition", "attachment;filename=InformeDiario_" + fecha.ToString() + ".pdf"); Response.BinaryWrite(MStream.GetBuffer()); Response.End(); }
protected static void SetContactInfo(Misc.sp_052_displayConfirmationRow row, iTextSharp.text.Table tblMain) { Phrase ph = new Phrase(); ph.Add(GetTextPhrase("--- Header Information ---\n", true, 14)); ph.Add(GetTextPhrase("Confirmation Number:", true)); ph.Add(GetTextPhrase(row.ConfirmationID + "\n", false)); ph.Add(GetTextPhrase("UtilityName:", true)); ph.Add(GetTextPhrase(row.UtilityName + "\n", false)); tblMain.AddCell(ph); ph = new Phrase(); ph.Add(GetTextPhrase("--- Rebate Summary ---\n", true, 14)); ph.Add(GetTextPhrase("IncentiveName: ", true)); ph.Add(GetTextPhrase(row.IncentiveName + "\n", false)); ph.Add(GetTextPhrase("Summary: ", true)); ph.Add(GetTextPhrase(row.Summary + "\n", false)); tblMain.AddCell(ph); ph = new Phrase(); ph.Add(GetTextPhrase("--- Item Purchased ---\n", true, 14)); ph.Add(GetTextPhrase("CategoryLabel:", true)); ph.Add(GetTextPhrase(row.CategoryLabel + "\n", false)); ph.Add(GetTextPhrase("BrandName: ", true)); ph.Add(GetTextPhrase(row.BrandName + "\n", false)); ph.Add(GetTextPhrase("RatingModelNumber: ", true)); ph.Add(GetTextPhrase(row.RatingModelNumber + "\n", false)); tblMain.AddCell(ph); ph = new Phrase(); ph.Add(GetTextPhrase("--- My Information ---\n", true, 14)); ph.Add(GetTextPhrase("First Name:", true)); ph.Add(GetTextPhrase(row.FName + "\n", false)); ph.Add(GetTextPhrase("Last Name: ", true)); ph.Add(GetTextPhrase(row.LName + "\n", false)); ph.Add(GetTextPhrase("Street: ", true)); ph.Add(GetTextPhrase(row.Street + "\n", false)); ph.Add(GetTextPhrase("Apartment: ", true)); ph.Add(GetTextPhrase(row.Apartment + "\n", false)); ph.Add(GetTextPhrase("City: ", true)); ph.Add(GetTextPhrase(row.City + "\n", false)); ph.Add(GetTextPhrase("State: ", true)); ph.Add(GetTextPhrase(row.State + "\n", false)); ph.Add(GetTextPhrase("Zip: ", true)); ph.Add(GetTextPhrase(row.ZIP + "\n", false)); ph.Add(GetTextPhrase("Logon Email: ", true)); ph.Add(GetTextPhrase(row.logonEmail + "\n", false)); ph.Add(GetTextPhrase("UtilityAccountNumber: \n", true)); ph.Add(GetTextPhrase(row.UtilityAccountNumber + "\n", false)); tblMain.AddCell(ph); //Utility Bill Payer, if other than me ph = new Phrase(); ph.Add(GetTextPhrase("--- Utility Bill Payer --- \n", true, 14)); ph.Add(GetTextPhrase(row.B_FName + "\n", false)); ph.Add(GetTextPhrase(row.B_LName + "\n", false)); ph.Add(GetTextPhrase(row.B_Street + "\n", false)); ph.Add(GetTextPhrase(row.B_Apartment + "\n", false)); ph.Add(GetTextPhrase(row.B_City + "\n", false)); ph.Add(GetTextPhrase(row.B_ZIP + "\n", false)); ph.Add(GetTextPhrase(row.B_Phone + "\n", false)); ph.Add(GetTextPhrase(row.B_email + "\n", false)); tblMain.AddCell(ph); ph = new Phrase(); ph.Add(GetTextPhrase("--- Mail Rebate To --- \n", true, 14)); ph.Add(GetTextPhrase(row.ContactFName + "\n", false)); ph.Add(GetTextPhrase(row.ContactLName + "\n", false)); ph.Add(GetTextPhrase(row.ContactDept + "\n", false)); ph.Add(GetTextPhrase(row.ContactStreet + "\n", false)); ph.Add(GetTextPhrase(row.ContactCity + "\n", false)); ph.Add(GetTextPhrase(row.ContactState + "\n", false)); ph.Add(GetTextPhrase(row.ContactZip + "\n", false)); ph.Add(GetTextPhrase(row.ContactPhone + "\n", false)); ph.Add(GetTextPhrase(row.ContactWebsite + "\n", false)); tblMain.AddCell(ph); }
// methods to set the membervariables /** * Adds an element to this Cell. * <P> * Remark: you can't add ListItems, Rows, Cells, * JPEGs, GIFs or PNGs to a Cell. * * @param element The Element to add * @throws BadElementException if the method was called with a ListItem, Row or Cell */ /// <summary> /// Adds an element to this Cell. /// </summary> /// <remarks> /// You can't add ListItems, Rows, Cells, /// JPEGs, GIFs or PNGs to a Cell. /// </remarks> /// <param name="element">the Element to add</param> public void AddElement(IElement element) { if (IsTable()) { Table table = (Table)arrayList[0]; Cell tmp = new Cell(element); tmp.Border = NO_BORDER; tmp.Colspan = table.Columns; table.AddCell(tmp); return; } switch (element.Type) { case Element.LISTITEM: case Element.ROW: case Element.CELL: throw new BadElementException("You can't add listitems, rows or cells to a cell."); case Element.JPEG: case Element.IMGRAW: case Element.IMGTEMPLATE: arrayList.Add(element); break; case Element.LIST: if (float.IsNaN(this.Leading)) { leading = ((List)element).TotalLeading; } if (((List)element).IsEmpty()) { return; } arrayList.Add(element); return; case Element.ANCHOR: case Element.PARAGRAPH: case Element.PHRASE: if (float.IsNaN(leading)) { leading = ((Phrase)element).Leading; } if (((Phrase)element).IsEmpty()) { return; } arrayList.Add(element); return; case Element.CHUNK: if (((Chunk)element).IsEmpty()) { return; } arrayList.Add(element); return; case Element.TABLE: Table table = new Table(3); float[] widths = new float[3]; widths[1] = ((Table)element).Width; switch (((Table)element).Alignment) { case Element.ALIGN_LEFT: widths[0] = 0f; widths[2] = 100f - widths[1]; break; case Element.ALIGN_CENTER: widths[0] = (100f - widths[1]) / 2f; widths[2] = widths[0]; break; case Element.ALIGN_RIGHT: widths[0] = 100f - widths[1]; widths[2] = 0f; break; } table.Widths = widths; Cell tmp; if (arrayList.Count == 0) { table.AddCell(Cell.DummyCell); } else { tmp = new Cell(); tmp.Border = NO_BORDER; tmp.Colspan = 3; foreach (IElement ele in arrayList) { tmp.Add(ele); } table.AddCell(tmp); } tmp = new Cell(); tmp.Border = NO_BORDER; table.AddCell(tmp); table.InsertTable((Table)element); tmp = new Cell(); tmp.Border = NO_BORDER; table.AddCell(tmp); table.AddCell(Cell.DummyCell); Clear(); arrayList.Add(table); return; default: arrayList.Add(element); break; } }
public void OnStartPage(PdfWriter writer, Document document) { var pessoaJuridica = empresa.Pessoa as IPessoaJuridica; Chunk imagem; if (!string.IsNullOrEmpty(pessoaJuridica.Logomarca)) { var imghead = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath(pessoaJuridica.Logomarca)); imagem = new Chunk(imghead, 0, 0); } else imagem = new Chunk(""); var dadosEmpresa = new Phrase(); dadosEmpresa.Add(pessoaJuridica.NomeFantasia + Environment.NewLine); if (pessoaJuridica.Enderecos.Count > 0) { var endereco = pessoaJuridica.Enderecos[0]; dadosEmpresa.Add(endereco.ToString()); } if (pessoaJuridica.Telefones.Count > 0) { var telefone = pessoaJuridica.Telefones[0]; dadosEmpresa.Add("Telefone " + telefone); } var tabelaHeader = new Table(2); tabelaHeader.Border = 0; tabelaHeader.Width = 100; var cell = new Cell(new Phrase(imagem)); cell.Border = 0; cell.Width = 30; tabelaHeader.AddCell(cell); var cell1 = new Cell(dadosEmpresa); cell1.Border = 0; cell1.Width = 70; tabelaHeader.AddCell(cell1); var linhaVazia = new Cell(new Phrase("\n", font2)); linhaVazia.Colspan = 2; linhaVazia.DisableBorderSide(1); tabelaHeader.AddCell(linhaVazia); document.Add(tabelaHeader); var tabelaTitulo = new Table(1); tabelaTitulo.Border = 0; tabelaTitulo.Width = 100; var celulaTitulo = new Cell(new Phrase((relatorioDeContasAReceber ? "Relatório de Contas a Receber" : "Relatório de Gerenciamento de Itens Financeiros") + DateTime.Now.ToString("dd/MM/yyyy"), font3)); celulaTitulo.Border = 0; celulaTitulo.Width = 70; celulaTitulo.Colspan = 1; tabelaTitulo.AddCell(celulaTitulo); var linhaVaziaNumeroRevista = new Cell(new Phrase("\n", font2)); linhaVaziaNumeroRevista.Border = 0; linhaVaziaNumeroRevista.Width = 70; linhaVaziaNumeroRevista.Colspan = 1; linhaVaziaNumeroRevista.DisableBorderSide(1); tabelaTitulo.AddCell(linhaVaziaNumeroRevista); document.Add(tabelaTitulo); }
protected void Page_Load(object sender, EventArgs e) { AuthenticateUser(); intProfile = Int32.Parse(Request.Cookies["profileid"].Value); if (Request.QueryString["id"] != null && Request.QueryString["id"] != "") { StringBuilder sb = new StringBuilder(strQuestions); oForecast = new Forecast(intProfile, dsn); oUser = new Users(intProfile, dsn); oProject = new Projects(intProfile, dsn); oProjectPending = new ProjectsPending(intProfile, dsn, intEnvironment); oRequest = new Requests(intProfile, dsn); oOrganization = new Organizations(intProfile, dsn); oStatusLevel = new StatusLevels(); oPlatform = new Platforms(intProfile, dsn); oModel = new Models(intProfile, dsn); oModelsProperties = new ModelsProperties(intProfile, dsn); int intForecast = Int32.Parse(Request.QueryString["id"]); if (!IsPostBack) { Document doc = new Document(); iTextSharp.text.Table oTable = new iTextSharp.text.Table(2); oTable.BorderWidth = 0; oTable.BorderColor = new iTextSharp.text.Color(255, 255, 255); oTable.Padding = 2; oTable.Width = 100; iTextSharp.text.Font oFontHeader = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 10, 1); iTextSharp.text.Font oFontBold = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 8, 1); iTextSharp.text.Font oFont = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 8, 0); if (Request.QueryString["export"] != null) { PdfWriter.GetInstance(doc, Response.OutputStream); string strHeader = "ClearView Design Summary"; HeaderFooter header = new HeaderFooter(new Phrase(strHeader, new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 6)), false); header.Border = iTextSharp.text.Rectangle.NO_BORDER; header.Alignment = 2; doc.Header = header; string strFooter = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(); HeaderFooter footer = new HeaderFooter(new Phrase(strFooter, new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 6)), false); footer.Border = iTextSharp.text.Rectangle.NO_BORDER; footer.Alignment = 2; doc.Footer = footer; doc.Open(); //iTextSharp.text.Image gif = iTextSharp.text.Image.GetInstance(Request.MapPath("~/images/nc_logo.gif")); //gif.Alignment = iTextSharp.text.Image.RIGHT_ALIGN; //gif.ScalePercent(50f); // change it's size //doc.Add(gif); Cell cell = new Cell(new Phrase("General Information", oFontHeader)); cell.Colspan = 2; cell.BackgroundColor = new iTextSharp.text.Color(204, 204, 204); oTable.AddCell(cell); } DataSet ds = oForecast.Get(intForecast); int intRequest = 0; sb.Append("<table width=\"100%\" cellpadding=\"4\" cellspacing=\"3\" border=\"0\">"); sb.Append("<tr><td colspan=\"2\" class=\"header\">General Information</td></tr>"); if (ds.Tables[0].Rows.Count > 0) { oTable.AddCell(new Cell(new Phrase("Requestor:", oFontBold))); oTable.AddCell(new Cell(new Phrase(oUser.GetFullName(Int32.Parse(ds.Tables[0].Rows[0]["userid"].ToString())), oFont))); sb.Append("<tr><td nowrap>Requestor:</td><td width=\"100%\">"); sb.Append(oUser.GetFullName(Int32.Parse(ds.Tables[0].Rows[0]["userid"].ToString()))); sb.Append("</td></tr>"); oTable.AddCell(new Cell(new Phrase("Submission Date:", oFontBold))); oTable.AddCell(new Cell(new Phrase(DateTime.Parse(ds.Tables[0].Rows[0]["created"].ToString()).ToLongDateString(), oFont))); sb.Append("<tr><td nowrap>Submission Date:</td><td width=\"100%\">"); sb.Append(DateTime.Parse(ds.Tables[0].Rows[0]["created"].ToString()).ToLongDateString()); sb.Append("</td></tr>"); intRequest = Int32.Parse(ds.Tables[0].Rows[0]["requestid"].ToString()); } int intManager = 0; int intEngineer = 0; int intLead = 0; int intProject = oRequest.GetProjectNumber(intRequest); if (intProject > 0) { DataSet dsProject = oProject.Get(intProject); if (dsProject.Tables[0].Rows.Count > 0) { oTable.AddCell(new Cell(new Phrase("Project Name:", oFontBold))); oTable.AddCell(new Cell(new Phrase(dsProject.Tables[0].Rows[0]["name"].ToString(), oFont))); oTable.AddCell(new Cell(new Phrase("Initiative Type:", oFontBold))); oTable.AddCell(new Cell(new Phrase(dsProject.Tables[0].Rows[0]["bd"].ToString(), oFont))); oTable.AddCell(new Cell(new Phrase("Organization:", oFontBold))); oTable.AddCell(new Cell(new Phrase(oOrganization.GetName(Int32.Parse(dsProject.Tables[0].Rows[0]["organization"].ToString())), oFont))); oTable.AddCell(new Cell(new Phrase("Project Number:", oFontBold))); oTable.AddCell(new Cell(new Phrase(dsProject.Tables[0].Rows[0]["number"].ToString(), oFont))); oTable.AddCell(new Cell(new Phrase("Project Status:", oFontBold))); oTable.AddCell(new Cell(new Phrase(oStatusLevel.Name(Int32.Parse(dsProject.Tables[0].Rows[0]["status"].ToString())), oFont))); sb.Append("<tr><td nowrap>Project Name:</td><td width=\"100%\">"); sb.Append(dsProject.Tables[0].Rows[0]["name"].ToString()); sb.Append("</td></tr>"); sb.Append("<tr><td nowrap>Initiative Type:</td><td width=\"100%\">"); sb.Append(dsProject.Tables[0].Rows[0]["bd"].ToString()); sb.Append("</td></tr>"); sb.Append("<tr><td nowrap>Organization:</td><td width=\"100%\">"); sb.Append(oOrganization.GetName(Int32.Parse(dsProject.Tables[0].Rows[0]["organization"].ToString()))); sb.Append("</td></tr>"); sb.Append("<tr><td nowrap>Project Number:</td><td width=\"100%\">"); sb.Append(dsProject.Tables[0].Rows[0]["number"].ToString()); sb.Append("</td></tr>"); sb.Append("<tr><td nowrap>Project Status:</td><td width=\"100%\">"); sb.Append(oStatusLevel.HTML(Int32.Parse(dsProject.Tables[0].Rows[0]["status"].ToString()))); sb.Append("</td></tr>"); intManager = Int32.Parse(dsProject.Tables[0].Rows[0]["lead"].ToString()); intEngineer = Int32.Parse(dsProject.Tables[0].Rows[0]["engineer"].ToString()); intLead = Int32.Parse(dsProject.Tables[0].Rows[0]["technical"].ToString()); } } else { DataSet dsPending = oProjectPending.GetRequest(intRequest); if (dsPending.Tables[0].Rows.Count > 0) { oTable.AddCell(new Cell(new Phrase("Project Name:", oFontBold))); oTable.AddCell(new Cell(new Phrase(dsPending.Tables[0].Rows[0]["name"].ToString(), oFont))); oTable.AddCell(new Cell(new Phrase("Initiative Type:", oFontBold))); oTable.AddCell(new Cell(new Phrase(dsPending.Tables[0].Rows[0]["bd"].ToString(), oFont))); oTable.AddCell(new Cell(new Phrase("Organization:", oFontBold))); oTable.AddCell(new Cell(new Phrase(oOrganization.GetName(Int32.Parse(dsPending.Tables[0].Rows[0]["organization"].ToString())), oFont))); oTable.AddCell(new Cell(new Phrase("Project Number:", oFontBold))); oTable.AddCell(new Cell(new Phrase(dsPending.Tables[0].Rows[0]["number"].ToString(), oFont))); oTable.AddCell(new Cell(new Phrase("Project Status:", oFontBold))); oTable.AddCell(new Cell(new Phrase("PENDING", oFont))); sb.Append("<tr><td nowrap>Project Name:</td><td width=\"100%\">"); sb.Append(dsPending.Tables[0].Rows[0]["name"].ToString()); sb.Append("</td></tr>"); sb.Append("<tr><td nowrap>Initiative Type:</td><td width=\"100%\">"); sb.Append(dsPending.Tables[0].Rows[0]["bd"].ToString()); sb.Append("</td></tr>"); sb.Append("<tr><td nowrap>Organization:</td><td width=\"100%\">"); sb.Append(oOrganization.GetName(Int32.Parse(dsPending.Tables[0].Rows[0]["organization"].ToString()))); sb.Append("</td></tr>"); sb.Append("<tr><td nowrap>Project Number:</td><td width=\"100%\">"); sb.Append(dsPending.Tables[0].Rows[0]["number"].ToString()); sb.Append("</td></tr>"); sb.Append("<tr><td nowrap>Project Status:</td><td width=\"100%\" class=\"pending\">PENDING</td></tr>"); intManager = Int32.Parse(dsPending.Tables[0].Rows[0]["lead"].ToString()); intEngineer = Int32.Parse(dsPending.Tables[0].Rows[0]["engineer"].ToString()); intLead = Int32.Parse(dsPending.Tables[0].Rows[0]["technical"].ToString()); } } if (intManager > 0) { sb.Append("<tr><td nowrap>Project Manager:</td><td width=\"100%\">"); sb.Append(oUser.GetFullName(intManager)); sb.Append("</td></tr>"); } else { sb.Append("<tr><td nowrap>Project Manager:</td><td width=\"100%\"></td></tr>"); } if (intEngineer > 0) { sb.Append("<tr><td nowrap>Integration Engineer:</td><td width=\"100%\">"); sb.Append(oUser.GetFullName(intEngineer)); sb.Append("</td></tr>"); } else { sb.Append("<tr><td nowrap>Integration Engineer:</td><td width=\"100%\"></td></tr>"); } if (intLead > 0) { sb.Append("<tr><td nowrap>Technical Lead:</td><td width=\"100%\">"); sb.Append(oUser.GetFullName(intLead)); sb.Append("</td></tr>"); } else { sb.Append("<tr><td nowrap>Technical Lead:</td><td width=\"100%\"></td></tr>"); } oTable.AddCell(new Cell(new Phrase("Project Manager:", oFontBold))); oTable.AddCell(new Cell(new Phrase(oUser.GetFullName(intManager), oFont))); oTable.AddCell(new Cell(new Phrase("Integration Engineer:", oFontBold))); oTable.AddCell(new Cell(new Phrase(oUser.GetFullName(intEngineer), oFont))); oTable.AddCell(new Cell(new Phrase("Technical Lead:", oFontBold))); oTable.AddCell(new Cell(new Phrase(oUser.GetFullName(intLead), oFont))); oTable.AddCell(new Cell(new Phrase(" ", oFontBold))); oTable.AddCell(new Cell(new Phrase(" ", oFont))); Cell cell2 = new Cell(new Phrase("Line Items", oFontHeader)); cell2.Colspan = 2; cell2.BackgroundColor = new iTextSharp.text.Color(204, 204, 204); oTable.AddCell(cell2); sb.Append("<tr><td colspan=\"2\"><hr size=\"1\" noshade /></td></tr>"); sb.Append("<tr><td colspan=\"2\" class=\"header\">Line Items</td></tr>"); sb.Append("<tr><td colspan=\"2\">"); ds = oForecast.GetAnswers(intForecast); bool boolChange = false; foreach (DataRow dr in ds.Tables[0].Rows) { int intID = Int32.Parse(dr["id"].ToString()); int intPlatform = Int32.Parse(dr["platformid"].ToString()); int intClass = Int32.Parse(dr["classid"].ToString()); int intEnvir = Int32.Parse(dr["environmentid"].ToString()); double dblQuantity = double.Parse(dr["quantity"].ToString()) + double.Parse(dr["recovery_number"].ToString()); int intModel = 0; int intServerModel = oForecast.GetModelAsset(intID); if (intServerModel == 0) { intServerModel = oForecast.GetModel(intID); } if (intServerModel == 0) { // Get the model selected in the equipment dropdown (if not server) intModel = Int32.Parse(dr["modelid"].ToString()); } double dblAmp = 0.00; double dblReplicate = 0.00; string strModel = ""; if (intServerModel > 0) { dblAmp = (double.Parse(oModelsProperties.Get(intServerModel, "amp")) * dblQuantity); double.TryParse(oModelsProperties.Get(intServerModel, "replicate_times"), out dblReplicate); if (intModel == 0) { intModel = Int32.Parse(oModelsProperties.Get(intServerModel, "modelid")); } strModel = oModelsProperties.Get(intServerModel, "name"); } else if (intModel > 0) { strModel = oModel.Get(intModel, "name"); } else { DataSet dsVendor = oForecast.GetAnswer(intID); if (dsVendor.Tables[0].Rows.Count > 0 && dsVendor.Tables[0].Rows[0]["modelname"].ToString() != "") { dblAmp = (double.Parse(dsVendor.Tables[0].Rows[0]["amp"].ToString()) * dblQuantity); strModel = dsVendor.Tables[0].Rows[0]["modelname"].ToString(); } } if (intModel == 0) { strModel = "Solution Unavailable"; } // STORAGE DataSet dsStorage = oForecast.GetStorage(intID); double dblStorage = 0.00; if (dsStorage.Tables[0].Rows.Count > 0) { double dblHigh = double.Parse(dsStorage.Tables[0].Rows[0]["high_total"].ToString()) + double.Parse(dsStorage.Tables[0].Rows[0]["high_qa"].ToString()) + double.Parse(dsStorage.Tables[0].Rows[0]["high_test"].ToString()) + (double.Parse(dsStorage.Tables[0].Rows[0]["high_replicated"].ToString()) * dblReplicate) + double.Parse(dsStorage.Tables[0].Rows[0]["high_ha"].ToString()); double dblStandard = double.Parse(dsStorage.Tables[0].Rows[0]["standard_total"].ToString()) + double.Parse(dsStorage.Tables[0].Rows[0]["standard_qa"].ToString()) + double.Parse(dsStorage.Tables[0].Rows[0]["standard_test"].ToString()) + (double.Parse(dsStorage.Tables[0].Rows[0]["standard_replicated"].ToString()) * dblReplicate) + double.Parse(dsStorage.Tables[0].Rows[0]["standard_ha"].ToString()); double dblLow = double.Parse(dsStorage.Tables[0].Rows[0]["low_total"].ToString()) + double.Parse(dsStorage.Tables[0].Rows[0]["low_qa"].ToString()) + double.Parse(dsStorage.Tables[0].Rows[0]["low_test"].ToString()) + (double.Parse(dsStorage.Tables[0].Rows[0]["low_replicated"].ToString()) * dblReplicate) + double.Parse(dsStorage.Tables[0].Rows[0]["low_ha"].ToString()); dblStorage = dblHigh + dblStandard + dblLow; } sb.Append("<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"background-color:"); sb.Append(boolChange ? "#FFFFFF" : "#F6F6F6"); sb.Append("\">"); sb.Append("<tr><td>"); sb.Append("<table width=\"100%\" cellpadding=\"5\" cellspacing=\"2\" border=\"0\">"); sb.Append("<tr><td valign=\"top\" nowrap>Nickname:</td><td>"); sb.Append(dr["name"].ToString()); sb.Append("</td></tr>"); sb.Append("<tr><td valign=\"top\" nowrap>Platform:</td><td>"); sb.Append(oPlatform.GetName(intPlatform)); sb.Append("</td></tr>"); oTable.AddCell(new Cell(new Phrase("Nickname:", oFontBold))); oTable.AddCell(new Cell(new Phrase(dr["name"].ToString(), oFont))); oTable.AddCell(new Cell(new Phrase("Platform:", oFontBold))); oTable.AddCell(new Cell(new Phrase(oPlatform.GetName(intPlatform), oFont))); oTable.AddCell(new Cell(new Phrase("Model:", oFontBold))); oTable.AddCell(new Cell(new Phrase(strModel, oFont))); oTable.AddCell(new Cell(new Phrase("Commitment Date:", oFontBold))); oTable.AddCell(new Cell(new Phrase((dr["implementation"].ToString() == "" ? "" : DateTime.Parse(dr["implementation"].ToString()).ToShortDateString()), oFont))); oTable.AddCell(new Cell(new Phrase("Quantity:", oFontBold))); oTable.AddCell(new Cell(new Phrase(dblQuantity.ToString(), oFont))); string strPDF = oModel.Get(intModel, "pdf"); sb.Append("<tr><td valign=\"top\" nowrap>Model:</td><td width=\"100%\">"); sb.Append(strPDF == "" ? strModel : "<a href=\"javascript:void(0);\" onclick=\"OpenNewWindowMAX('" + strPDF.Replace("\\", "\\\\") + "');\">" + strModel + "</a>"); sb.Append("</td></tr>"); sb.Append("<tr><td valign=\"top\" nowrap>Commitment Date:</td><td width=\"100%\">"); sb.Append(dr["implementation"].ToString() == "" ? "" : DateTime.Parse(dr["implementation"].ToString()).ToShortDateString()); sb.Append("</td></tr>"); sb.Append("<tr><td valign=\"top\" nowrap>Quantity:</td><td width=\"100%\"><a href=\"javascript:void(0);\" onclick=\"OpenNewWindow('/frame/forecast/forecast_print_quantity.aspx?id="); sb.Append(intID.ToString()); sb.Append("',275,200);\">"); sb.Append(dblQuantity.ToString()); sb.Append("</a></td></tr>"); double dblA = 0.00; DataSet dsA = oForecast.GetAcquisitions(intModel, 1); foreach (DataRow drA in dsA.Tables[0].Rows) { dblA += double.Parse(drA["cost"].ToString()); } sb.Append("<tr><td valign=\"top\" nowrap>Acquisition Costs:</td><td width=\"100%\"><a href=\"javascript:void(0);\" onclick=\"OpenNewWindow('/frame/forecast/forecast_print_acquisition.aspx?id="); sb.Append(intID.ToString()); sb.Append("',400,300);\">$"); sb.Append(dblA.ToString("N")); sb.Append("</a></td></tr>"); oTable.AddCell(new Cell(new Phrase("Acquisition Costs:", oFontBold))); oTable.AddCell(new Cell(new Phrase(dblA.ToString("N"), oFont))); double dblO = 0.00; DataSet dsO = oForecast.GetOperations(intModel, 1); foreach (DataRow drO in dsO.Tables[0].Rows) { dblO += double.Parse(drO["cost"].ToString()); } oTable.AddCell(new Cell(new Phrase("Operational Costs:", oFontBold))); oTable.AddCell(new Cell(new Phrase(dblO.ToString("N"), oFont))); oTable.AddCell(new Cell(new Phrase("Storage:", oFontBold))); oTable.AddCell(new Cell(new Phrase(dblStorage.ToString("N") + " GB", oFont))); oTable.AddCell(new Cell(new Phrase("AMPs:", oFontBold))); oTable.AddCell(new Cell(new Phrase(dblAmp.ToString("N") + " AMPs", oFont))); sb.Append("<tr><td valign=\"top\" nowrap>Operational Costs:</td><td width=\"100%\"><a href=\"javascript:void(0);\" onclick=\"OpenNewWindow('/frame/forecast/forecast_print_operational.aspx?id="); sb.Append(intID.ToString()); sb.Append("',400,300);\">$"); sb.Append(dblO.ToString("N")); sb.Append("</a></td></tr>"); sb.Append("<tr><td valign=\"top\" nowrap>Storage:</td><td width=\"100%\"><a href=\"javascript:void(0);\" onclick=\"OpenNewWindow('/frame/forecast/forecast_print_storage.aspx?id="); sb.Append(intID.ToString()); sb.Append("',650,200);\">"); sb.Append(dblStorage.ToString("N")); sb.Append(" GB</a></td></tr>"); sb.Append("<tr><td valign=\"top\" nowrap>AMPs:</td><td width=\"100%\">"); sb.Append(dblAmp.ToString("N")); sb.Append("</td></tr>"); if (Request.QueryString["checked"] != null) { sb.Append("<tr><td valign=\"top\" colspan=\"2\"><b>Questions & Responses</b></td></tr>"); DataSet dsQuestions = oForecast.GetQuestionPlatform(intPlatform, intClass, intEnvir); foreach (DataRow drQuestion in dsQuestions.Tables[0].Rows) { string strResponse = ""; string strResponsePDF = ""; int intQuestion = Int32.Parse(drQuestion["id"].ToString()); DataSet dsAnswers = oForecast.GetAnswerPlatform(intID, intQuestion); foreach (DataRow drAnswer in dsAnswers.Tables[0].Rows) { strResponse += "<tr><td valign=\"top\"></td><td> " + oForecast.GetResponse(Int32.Parse(drAnswer["responseid"].ToString()), "response") + "</td></tr>"; if (strResponsePDF != "") { strResponsePDF += ", "; } strResponsePDF += oForecast.GetResponse(Int32.Parse(drAnswer["responseid"].ToString()), "response"); } if (strResponse != "") { sb.Append("<tr><td valign=\"top\" colspan=\"2\"><table cellpadding=\"1\" cellspacing=\"1\" border=\"0\">"); sb.Append("<tr><td valign=\"top\"><img src=\"/images/help.gif\" align=\"absmiddle\" border=\"0\"/></td><td>"); sb.Append(drQuestion["question"].ToString()); sb.Append("</td></tr>"); Cell oCellQ = new Cell(new Phrase(drQuestion["question"].ToString(), oFontBold)); oCellQ.Colspan = 2; oTable.AddCell(oCellQ); Cell oCellA = new Cell(new Phrase(strResponsePDF, oFont)); oCellA.Colspan = 2; oTable.AddCell(oCellA); sb.Append(strResponse); sb.Append("</table></td></tr>"); } } } sb.Append("</table></td></tr>"); Cell oCellD = new Cell(new Phrase("", oFont)); oCellD.Colspan = 2; oCellD.BackgroundColor = new iTextSharp.text.Color(100, 100, 100); oTable.AddCell(oCellD); sb.Append("<tr height=\"1\"><td colspan=\"2\" style=\"border-bottom:dashed 1px #CCCCCC\"><img src=\"/images/spacer.gif\" border=\"0\" width=\"1\" height=\"1\" /></td></tr>"); sb.Append("</table>"); boolChange = !boolChange; } sb.Append("</td></tr>"); chkQuestions.Checked = (Request.QueryString["checked"] != null); chkQuestions.Attributes.Add("onclick", "WaitDDL('" + divWait.ClientID + "');"); if (Request.QueryString["export"] != null) { doc.Add(oTable); doc.Close(); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "attachment; filename=export.pdf"); Response.End(); Response.Flush(); } } strQuestions = sb.ToString(); } }
private void ExportToPDF() { Document document = new Document(PageSize.A4, 0, 0, 10, 10); System.IO.MemoryStream msReport = new System.IO.MemoryStream(); try { // creation of the different writers PdfWriter writer = PdfWriter.GetInstance(document, msReport); // we add some meta information to the document document.AddAuthor("Maruf"); document.AddSubject("Report"); document.Open(); iTextSharp.text.Table datatable = new iTextSharp.text.Table(7); datatable.Padding = 2; datatable.Spacing = 0; float[] headerwidths = { 15, 15, 15, 15, 10, 15, 15 }; datatable.Widths = headerwidths; // the first cell spans 7 columns Cell cell = new Cell(new Phrase("Location Wise Report", FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD))); cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.Leading = 30; cell.Colspan = 7; cell.Border = Rectangle.NO_BORDER; cell.BackgroundColor = new iTextSharp.text.Color(System.Drawing.Color.Gray); datatable.AddCell(cell); //gvLocation.AllowPaging = false; //gvLocation.DataBind(); int parentGridCount = 0; parentGridCount = 5; //int rowCount = gvFoodTransactionItemRelation.Rows.Count; for (int i = 0; i < parentGridCount; i++) { Cell cellCountry = new Cell(new Phrase("Country : " + "Demo Text", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); cellCountry.HorizontalAlignment = Element.ALIGN_LEFT; cellCountry.Leading = 30; cellCountry.Colspan = 7; cellCountry.Border = Rectangle.NO_BORDER; cellCountry.BackgroundColor = new iTextSharp.text.Color(System.Drawing.Color.WhiteSmoke); Cell cellCity = new Cell(new Phrase("City : " + "Demo Text", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); cellCity.HorizontalAlignment = Element.ALIGN_LEFT; cellCity.Leading = 30; cellCity.Colspan = 7; cellCity.Border = Rectangle.NO_BORDER; cellCity.BackgroundColor = new iTextSharp.text.Color(System.Drawing.Color.WhiteSmoke); Cell cell1 = new Cell(new Phrase("Branch : " + "Demo Text", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); cell1.HorizontalAlignment = Element.ALIGN_LEFT; cell1.Leading = 30; cell1.Colspan = 7; cell1.Border = Rectangle.NO_BORDER; cell1.BackgroundColor = new iTextSharp.text.Color(System.Drawing.Color.WhiteSmoke); datatable.AddCell(cell1); datatable.AddCell(cellCountry); datatable.AddCell(cellCity); datatable.DefaultCellBorderWidth = 1; datatable.DefaultHorizontalAlignment = 1; datatable.DefaultRowspan = 2; datatable.AddCell("Date"); datatable.AddCell("Ref Code"); datatable.AddCell("Amount"); datatable.AddCell("Fees"); datatable.AddCell("Discount"); datatable.AddCell("Total Amount"); datatable.AddCell("Status"); //GridView gvTRANS = (GridView)gvLocation.Rows[i].FindControl("gvTRANS"); for (int j = 0; j < 2; j++) { datatable.DefaultHorizontalAlignment = Element.ALIGN_LEFT; datatable.Alignment = Element.ALIGN_CENTER; datatable.AddCell(new Phrase("Demo Text", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.NORMAL))); datatable.AddCell(new Phrase("Demo Text", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.NORMAL))); datatable.AddCell(new Phrase("Demo Text", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.NORMAL))); datatable.AddCell(new Phrase("Demo Text", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.NORMAL))); datatable.AddCell(new Phrase("Demo Text", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.NORMAL))); datatable.AddCell(new Phrase("Demo Text", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.NORMAL))); datatable.AddCell(new Phrase("Demo Text", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.NORMAL))); } } document.Add(datatable); } catch (Exception e) { Console.Error.WriteLine(e.Message); } // we close the document document.Close(); Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=LocationWiseReport.pdf"); Response.ContentType = "application/pdf"; Response.BinaryWrite(msReport.ToArray()); Response.End(); }
/** * Creates a Table object based on this TableAttributes object. * @return a com.lowagie.text.Table object * @throws BadElementException */ public Table CreateTable() { if (content.Count == 0) { throw new BadElementException("Trying to create a table without rows."); } SimpleCell rowx = (SimpleCell)content[0]; int columns = 0; foreach (SimpleCell cell in rowx.Content) { columns += cell.Colspan; } float[] widths = new float[columns]; float[] widthpercentages = new float[columns]; Table table = new Table(columns); table.Alignment = alignment; table.Spacing = cellspacing; table.Padding = cellpadding; table.CloneNonPositionParameters(this); int pos; foreach (SimpleCell row in content) { pos = 0; foreach (SimpleCell cell in row.Content) { table.AddCell(cell.CreateCell(row)); if (cell.Colspan == 1) { if (cell.Width > 0) { widths[pos] = cell.Width; } if (cell.Widthpercentage > 0) { widthpercentages[pos] = cell.Widthpercentage; } } pos += cell.Colspan; } } float sumWidths = 0f; for (int i = 0; i < columns; i++) { if (widths[i] == 0) { sumWidths = 0; break; } sumWidths += widths[i]; } if (sumWidths > 0) { table.AbsWidth = sumWidths.ToString(); table.Widths = widths; } else { for (int i = 0; i < columns; i++) { if (widthpercentages[i] == 0) { sumWidths = 0; break; } sumWidths += widthpercentages[i]; } if (sumWidths > 0) { table.Widths = widthpercentages; } } if (width > 0) { table.AbsWidth = width.ToString(); } if (widthpercentage > 0) { table.Width = widthpercentage; } return(table); }
private iTextSharp.text.Table GenerateMainTable(DataSet dsMainTable) { // 生成表格 BaseFont bfChinese = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); Font font22B = new Font(bfChinese, 22, iTextSharp.text.Font.BOLD); Font font22 = new Font(bfChinese, 22); Font font20B = new Font(bfChinese, 20, iTextSharp.text.Font.BOLD); Font font20 = new Font(bfChinese, 20); Font font19B = new Font(bfChinese, 19, iTextSharp.text.Font.BOLD); Font font19 = new Font(bfChinese, 19); Font font14B = new Font(bfChinese, 14, iTextSharp.text.Font.BOLD); Font font14 = new Font(bfChinese, 14); Font font13B = new Font(bfChinese, 13, iTextSharp.text.Font.BOLD); Font font13 = new Font(bfChinese, 13); Font font12B = new Font(bfChinese, 12, iTextSharp.text.Font.BOLD); Font font12 = new Font(bfChinese, 12); Font font11B = new Font(bfChinese, 11, iTextSharp.text.Font.BOLD); Font font11 = new Font(bfChinese, 11); Font font10B = new Font(bfChinese, 10, iTextSharp.text.Font.BOLD); Font font10 = new Font(bfChinese, 10); Font font9B = new Font(bfChinese, 9, iTextSharp.text.Font.BOLD); Font font9 = new Font(bfChinese, 9); Font font8B = new Font(bfChinese, 8, iTextSharp.text.Font.BOLD); Font font8 = new Font(bfChinese, 8); int intColumn = 0; intColumn += 1 + 1; intColumn += 1 + 1; intColumn += 1 + 1; iTextSharp.text.Table itbOutput = new iTextSharp.text.Table(intColumn); itbOutput.BorderWidth = 0; itbOutput.Cellpadding = 2; itbOutput.Cellspacing = 0; itbOutput.Width = 100; // 加入表头信息 Cell cellTitle = new Cell(new Paragraph("单位信息", font19B)); cellTitle.BorderWidth = 0; cellTitle.HorizontalAlignment = 1; cellTitle.VerticalAlignment = 1; cellTitle.Colspan = intColumn; itbOutput.AddCell(cellTitle); Cell cellTitleSpace = new Cell(new Paragraph(" ", font20B)); cellTitleSpace.BorderWidth = 0; cellTitleSpace.HorizontalAlignment = 1; cellTitleSpace.VerticalAlignment = 1; cellTitleSpace.Colspan = intColumn; itbOutput.AddCell(cellTitleSpace); itbOutput.AddCell(cellTitleSpace); // 定义分割线 Cell cellBorder = new Cell(new Paragraph("", font10B)); cellBorder.BorderWidth = 0; cellBorder.BorderWidthBottom = 1; cellBorder.HorizontalAlignment = 1; cellBorder.VerticalAlignment = 1; cellBorder.Colspan = intColumn; if (dsMainTable.Tables.Count > 0) { foreach (DataRow drTemp in dsMainTable.Tables[0].Rows) { // 生成主表表格 // 生成一对一相关表表格 itbOutput.AddCell(cellTitleSpace); itbOutput.AddCell(cellTitleSpace); } } return(itbOutput); }
private void UpdatePDF(string strPath) { Document doc = new Document(); Cell cell; string strPhysicalPath = oVariable.DocumentsFolder() + strPath; FileStream fs = new FileStream(strPhysicalPath, FileMode.Create); PdfWriter.GetInstance(doc, fs); iTextSharp.text.Table oTable = new iTextSharp.text.Table(2); oTable.BorderWidth = 0; oTable.BorderColor = new iTextSharp.text.Color(255, 255, 255); oTable.Padding = 2; oTable.Width = 100; iTextSharp.text.Font oFontHeader = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 10, 1); iTextSharp.text.Font oFontBold = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 8, 1); iTextSharp.text.Font oFont = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 8, 0); string strHeader = "ClearView CSRC Information"; HeaderFooter header = new HeaderFooter(new Phrase(strHeader, new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 6)), false); header.Border = iTextSharp.text.Rectangle.NO_BORDER; header.Alignment = 2; doc.Header = header; string strFooter = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(); HeaderFooter footer = new HeaderFooter(new Phrase(strFooter, new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 6)), false); footer.Border = iTextSharp.text.Rectangle.NO_BORDER; footer.Alignment = 2; doc.Footer = footer; doc.Open(); ds = oTPM.GetCSRC(intId); int intRequest = Int32.Parse(ds.Tables[0].Rows[0]["requestid"].ToString()); int intItem = Int32.Parse(ds.Tables[0].Rows[0]["itemid"].ToString()); int intNumber = Int32.Parse(ds.Tables[0].Rows[0]["number"].ToString()); DataSet dsResource = oCustomized.GetTPM(intRequest, intItem, intNumber); cell = new Cell(new Phrase("Project Capital Service Review Committee Report", oFontHeader)); cell.Colspan = 2; cell.BackgroundColor = new iTextSharp.text.Color(169, 162, 141); oTable.AddCell(cell); cell = new Cell(new Phrase("PMM Phase", oFontBold)); cell.Colspan = 2; oTable.AddCell(cell); oTable.AddCell(new Cell(new Phrase("Discovery", oFont))); oTable.AddCell(new Cell(new Phrase((chkDiscovery.Checked ? "Yes" : "No"), oFont))); oTable.AddCell(new Cell(new Phrase("Planning", oFont))); oTable.AddCell(new Cell(new Phrase((chkPlanning.Checked ? "Yes" : "No"), oFont))); oTable.AddCell(new Cell(new Phrase("Execution", oFont))); oTable.AddCell(new Cell(new Phrase((chkExecution.Checked ? "Yes" : "No"), oFont))); oTable.AddCell(new Cell(new Phrase("Closing", oFont))); oTable.AddCell(new Cell(new Phrase((chkClosing.Checked ? "Yes" : "No"), oFont))); cell = new Cell(new Phrase("Discovery", oFontBold)); cell.Colspan = 2; oTable.AddCell(cell); oTable.AddCell(new Cell(new Phrase("Phase start date", oFont))); if (txtCSRCSD.Text == "") { oTable.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable.AddCell(new Cell(new Phrase(GetDate(txtCSRCSD.Text), oFont))); } oTable.AddCell(new Cell(new Phrase("Phase end date", oFont))); if (txtCSRCED.Text == "") { oTable.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable.AddCell(new Cell(new Phrase(GetDate(txtCSRCED.Text), oFont))); } oTable.AddCell(new Cell(new Phrase("Internal Labor", oFont))); if (txtCSRCID.Text == "") { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(txtCSRCID.Text).ToString("F"), oFont))); } oTable.AddCell(new Cell(new Phrase("External Labor", oFont))); if (txtCSRCExD.Text == "") { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(txtCSRCExD.Text).ToString("F"), oFont))); } oTable.AddCell(new Cell(new Phrase("HW/SW/One Time Cost", oFont))); if (txtCSRCHD.Text == "") { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(txtCSRCHD.Text).ToString("F"), oFont))); } cell = new Cell(new Phrase("Planning", oFontBold)); cell.Colspan = 2; oTable.AddCell(cell); oTable.AddCell(new Cell(new Phrase("Phase start date", oFont))); if (txtCSRCSP.Text == "") { oTable.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable.AddCell(new Cell(new Phrase(GetDate(txtCSRCSP.Text), oFont))); } oTable.AddCell(new Cell(new Phrase("Phase end date", oFont))); if (txtCSRCEP.Text == "") { oTable.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable.AddCell(new Cell(new Phrase(GetDate(txtCSRCEP.Text), oFont))); } oTable.AddCell(new Cell(new Phrase("Internal Labor", oFont))); if (txtCSRCIP.Text == "") { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(txtCSRCIP.Text).ToString("F"), oFont))); } oTable.AddCell(new Cell(new Phrase("External Labor", oFont))); if (txtCSRCExP.Text == "") { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(txtCSRCExP.Text).ToString("F"), oFont))); } oTable.AddCell(new Cell(new Phrase("HW/SW/One Time Cost", oFont))); if (txtCSRCHP.Text == "") { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(txtCSRCHP.Text).ToString("F"), oFont))); } cell = new Cell(new Phrase("Execution", oFontBold)); cell.Colspan = 2; oTable.AddCell(cell); oTable.AddCell(new Cell(new Phrase("Phase start date", oFont))); if (txtCSRCSE.Text == "") { oTable.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable.AddCell(new Cell(new Phrase(GetDate(txtCSRCSE.Text), oFont))); } oTable.AddCell(new Cell(new Phrase("Phase end date", oFont))); if (txtCSRCEE.Text == "") { oTable.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable.AddCell(new Cell(new Phrase(GetDate(txtCSRCEE.Text), oFont))); } oTable.AddCell(new Cell(new Phrase("Internal Labor", oFont))); if (txtCSRCIE.Text == "") { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(txtCSRCIE.Text).ToString("F"), oFont))); } oTable.AddCell(new Cell(new Phrase("External Labor", oFont))); if (txtCSRCExE.Text == "") { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(txtCSRCExE.Text).ToString("F"), oFont))); } oTable.AddCell(new Cell(new Phrase("HW/SW/One Time Cost", oFont))); if (txtCSRCHE.Text == "") { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(txtCSRCHE.Text).ToString("F"), oFont))); } cell = new Cell(new Phrase("Closing", oFontBold)); cell.Colspan = 2; oTable.AddCell(cell); oTable.AddCell(new Cell(new Phrase("Phase start date", oFont))); if (txtCSRCSC.Text == "") { oTable.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable.AddCell(new Cell(new Phrase(GetDate(txtCSRCSC.Text), oFont))); } oTable.AddCell(new Cell(new Phrase("Phase end date", oFont))); if (txtCSRCEC.Text == "") { oTable.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable.AddCell(new Cell(new Phrase(GetDate(txtCSRCEC.Text), oFont))); } oTable.AddCell(new Cell(new Phrase("Internal Labor", oFont))); if (txtCSRCIC.Text == "") { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(txtCSRCIC.Text).ToString("F"), oFont))); } oTable.AddCell(new Cell(new Phrase("External Labor", oFont))); if (txtCSRCExC.Text == "") { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(txtCSRCExC.Text).ToString("F"), oFont))); } oTable.AddCell(new Cell(new Phrase("HW/SW/One Time Cost", oFont))); if (txtCSRCHC.Text == "") { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(txtCSRCHC.Text).ToString("F"), oFont))); } doc.Add(oTable); doc.Close(); fs.Close(); }
public void GenerateXMLReport() { try { this.doc.Open(); RenderLogo(); RenderDescription(); RenderReportJobInfo(); iTextSharp.text.Table myTable = new iTextSharp.text.Table(ColList.Count); myTable.Widths = this.Headerwidths; myTable.WidthPercentage = 100; //myTable.Locked = true; //Render Table Headers~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ myTable.DefaultLayout.HorizontalAlignment = Element.ALIGN_LEFT; myTable.DefaultCell.BorderWidth = ReportBorderWidth; myTable.Cellpadding = 1; myTable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE; myTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; myTable.DefaultCell.BackgroundColor = Color.LIGHT_GRAY; myTable.DefaultCell.UseBorderPadding = true; foreach (var x in this.ColList) { myTable.AddCell(new Phrase(x, fntHeading)); } myTable.EndHeaders(); //Render Details~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Font myDetailFont = fntDetails; foreach (var x in this.ReportRows) { for (int i = 0; i < ColList.Count; i++) { myTable.DefaultCell.BackgroundColor = Color.WHITE; if (x.row[i].type == CellType.Number) myTable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT; else myTable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; if (i > ColList.Count - 3) myTable.DefaultCell.BackgroundColor = Color.LIGHT_GRAY; else myTable.DefaultCell.BackgroundColor = Color.WHITE; if (i == ColList.Count - 3) myTable.AddCell(new Phrase(x.row[i].value, footerFont)); else myTable.AddCell(new Phrase(x.row[i].value, myDetailFont)); } } //Footer Totals~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ myTable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT; myTable.DefaultCell.BackgroundColor = Color.WHITE; myTable.DefaultCell.Colspan = 4; myTable.AddCell(new Phrase("Totals", footerFont)); myTable.DefaultCell.Colspan = 1; for (int i = 4; i < FooterList.Count; i++) { myTable.AddCell(new Phrase(FooterList[i], footerFont)); //if ((FooterList[i].Length > 0 && SacoList[i].Length > 0) && (decimal.Parse(FooterList[i]) > decimal.Parse(SacoList[i]))) //{ // myTable.AddCell(new Phrase(FooterList[i], ErrorFont)); //} //else //{ // if (SacoList[i].Trim().Length == 0) // myTable.AddCell(new Phrase(FooterList[i], ErrorFont)); // else // myTable.AddCell(new Phrase(FooterList[i], footerFont)); //} } //Render Saco Totals~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ myTable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT; myTable.DefaultCell.BackgroundColor = Color.BLUE; myTable.DefaultCell.Colspan = 4; myTable.AddCell(new Phrase("Saco Hours", SacoFont)); myTable.DefaultCell.Colspan = 1; for (int i = 4; i < SacoList.Count; i++) { myTable.AddCell(new Phrase(SacoList[i], SacoFont)); } //Render Diff Totals~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ myTable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT; myTable.DefaultCell.BackgroundColor = Color.WHITE; myTable.DefaultCell.Colspan = 4; myTable.AddCell(new Phrase("Diff", footerFont)); myTable.DefaultCell.Colspan = 1; decimal diff = 0M; string cellvalue = ""; decimal sacovalue = 0M; decimal footervalue = 0M; for (int i = 4; i < SacoList.Count; i++) { diff = 0M; sacovalue = (SacoList[i].Length > 0)? decimal.Parse(SacoList[i]) : 0M; footervalue = (FooterList[i].Length >0) ? decimal.Parse(FooterList[i]) : 0M; diff = sacovalue - footervalue; cellvalue = (diff == 0) ? string.Empty : diff.ToString("#0.00"); myTable.AddCell(new Phrase(cellvalue, footerFont)); } //Put in a blank line~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //myTable.DefaultCell.BorderWidth = 0; //myTable.DefaultCell.BackgroundColor = Color.WHITE; //for (int row = 0; row < 10; row++) //{ // for (int i = 0; i < this.SacoList.Count; i++) // { // myTable.AddCell(new Phrase(" ", fntDetails)); // } //} doc.Add(myTable); //Render Signature Section~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //RenderSignatueSection(); #endregion } catch (Exception ex) { throw (new Exception("Error: " + ex.Message)); } doc.Close(); writer.Close(); }
private void ExportToPDF() { Document document = new Document(PageSize.A4, 0, 0, 10, 10); System.IO.MemoryStream msReport = new System.IO.MemoryStream(); try { // creation of the different writers PdfWriter writer = PdfWriter.GetInstance(document, msReport); // we add some meta information to the document document.AddAuthor("Maruf"); document.AddSubject("Report"); document.Open(); iTextSharp.text.Table datatable = new iTextSharp.text.Table(8); datatable.Padding = 2; datatable.Spacing = 0; float[] headerwidths = { 12, 12, 12, 16, 12, 12, 12, 12 }; datatable.Widths = headerwidths; // the first cell spans 7 columns Cell cell = new Cell(new Phrase("Customer Wise SAR Report", FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD))); cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.Leading = 30; cell.Colspan = 8; cell.Border = Rectangle.NO_BORDER; cell.BackgroundColor = new iTextSharp.text.Color(System.Drawing.Color.Gray); datatable.AddCell(cell); int parentGridCount = 0; parentGridCount = gvCustomer.Rows.Count; //int rowCount = gvFoodTransactionItemRelation.Rows.Count; for (int i = 0; i < parentGridCount; i++) { Label lblCUSTNAME = (Label)gvCustomer.Rows[i].FindControl("lblCUSTNAME"); Label lblTRANSTOTALAMOUNT = (Label)gvCustomer.Rows[i].FindControl("lblTRANSTOTALAMOUNT"); Cell cell1 = new Cell(new Phrase("Customer Name : " + lblCUSTNAME.Text, FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); cell1.HorizontalAlignment = Element.ALIGN_LEFT; cell1.Leading = 30; cell1.Colspan = 4; cell1.Border = Rectangle.NO_BORDER; cell1.BackgroundColor = new iTextSharp.text.Color(System.Drawing.Color.WhiteSmoke); datatable.AddCell(cell1); Cell cell4 = new Cell(new Phrase("Total Amount : " + lblTRANSTOTALAMOUNT.Text, FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); cell4.HorizontalAlignment = Element.ALIGN_RIGHT; cell4.Leading = 30; cell4.Colspan = 4; cell4.Border = Rectangle.NO_BORDER; cell4.BackgroundColor = new iTextSharp.text.Color(System.Drawing.Color.WhiteSmoke); datatable.AddCell(cell4); datatable.DefaultCellBorderWidth = 1; datatable.DefaultHorizontalAlignment = 1; datatable.DefaultRowspan = 2; datatable.AddCell("Date"); datatable.AddCell("Ref Code"); datatable.AddCell("Receiver"); datatable.AddCell("Location"); datatable.AddCell("Amount"); datatable.AddCell("Fees"); datatable.AddCell("Discount"); datatable.AddCell("Amount"); GridView gvTRANS = (GridView)gvCustomer.Rows[i].FindControl("gvTRANS"); for (int j = 0; j < gvTRANS.Rows.Count; j++) { datatable.DefaultHorizontalAlignment = Element.ALIGN_LEFT; Label lblTransactionDate = (Label)gvTRANS.Rows[j].FindControl("lblTransactionDate"); Label lblReferenceCode = (Label)gvTRANS.Rows[j].FindControl("lblReferenceCode"); Label lblReceiver = (Label)gvTRANS.Rows[j].FindControl("lblReceiver"); Label lblLocation = (Label)gvTRANS.Rows[j].FindControl("lblLocation"); Label lblSendingAmount = (Label)gvTRANS.Rows[j].FindControl("lblSendingAmount"); Label lblServiceCharge = (Label)gvTRANS.Rows[j].FindControl("lblServiceCharge"); Label lblDiscount = (Label)gvTRANS.Rows[j].FindControl("lblDiscount"); Label lblTotalCharge = (Label)gvTRANS.Rows[j].FindControl("lblTotalCharge"); datatable.Alignment = Element.ALIGN_CENTER; //Cell celllblTransactionDate = new Cell(new Phrase(lblTransactionDate.Text, FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); datatable.AddCell(new Phrase(lblTransactionDate.Text, FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); datatable.AddCell(new Phrase(lblReferenceCode.Text, FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); datatable.AddCell(new Phrase(lblReceiver.Text, FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); datatable.AddCell(new Phrase(lblLocation.Text, FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); datatable.AddCell(new Phrase(lblSendingAmount.Text, FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); datatable.AddCell(new Phrase(lblServiceCharge.Text, FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); datatable.AddCell(new Phrase(lblDiscount.Text, FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); datatable.AddCell(new Phrase(lblTotalCharge.Text, FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); } } document.Add(datatable); } catch (Exception e) { Console.Error.WriteLine(e.Message); } // we close the document document.Close(); Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=CustomerSARReport.pdf"); Response.ContentType = "application/pdf"; Response.BinaryWrite(msReport.ToArray()); Response.End(); }
protected void Button1_Click(object sender, EventArgs e) { HttpContext.Current.Response.ContentType = "Application/PDF"; HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename= District_Master.pdf"); StringWriter sw = new StringWriter(); HtmlTextWriter tw = new HtmlTextWriter(sw); string qry1 = "select Dist_Code,Dist_Name from Dist_List order by Dist_Name"; SqlCommand cmd = new SqlCommand(qry1, con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); iTextSharp.text.Table tb = new iTextSharp.text.Table(2); tb.BorderWidth = 0.6f; tb.BorderColor = new Color(0, 0, 0); tb.CellsFitPage = true; tb.Padding = 2; tb.Width = 90; //Single widths = new Single() [ 5, 5]; //tb.Widths = widths; if (ds.Tables[0].Rows.Count > 0) { DataTable dt; dt = ds.Tables[0]; Paragraph p31 = new Paragraph("District Code", new Font(Font.TIMES_ROMAN, 11, Font.BOLD)); iTextSharp.text.Cell tcell_1 = new iTextSharp.text.Cell(p31); tcell_1.Header = true; tcell_1.HorizontalAlignment = Element.ALIGN_CENTER; tcell_1.BackgroundColor = Color.LIGHT_GRAY; tb.AddCell(tcell_1); tb.EndHeaders(); Paragraph p32 = new Paragraph("District Name", new Font(Font.TIMES_ROMAN, 11, Font.BOLD)); iTextSharp.text.Cell tcell_2 = new iTextSharp.text.Cell(p32); tcell_2.Header = true; tcell_2.HorizontalAlignment = Element.ALIGN_CENTER; tcell_2.BackgroundColor = Color.LIGHT_GRAY; tb.AddCell(tcell_2); tb.EndHeaders(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { Paragraph p11; Paragraph p12; p11 = new Paragraph(ds.Tables[0].Rows[i]["Dist_Code"].ToString(), new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); p12 = new Paragraph(ds.Tables[0].Rows[i]["Dist_Name"].ToString(), new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); iTextSharp.text.Cell tcell_p111 = new iTextSharp.text.Cell(p11); tcell_p111.HorizontalAlignment = Element.ALIGN_CENTER; tb.AddCell(tcell_p111); iTextSharp.text.Cell tcell_p112 = new iTextSharp.text.Cell(p12); tcell_p112.HorizontalAlignment = Element.ALIGN_LEFT; tb.AddCell(tcell_p112); } } StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A4, 2, 2, 2, 1); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, HttpContext.Current.Response.OutputStream); PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream); String pcnt; pcnt = (writer.CurrentPageNumber - 1).ToString(); pcnt = pcnt.Substring(1); pdfDoc.Open(); pdfDoc.Add(new Paragraph(" DISTRICT MASTER")); pdfDoc.Add(tb); pdfDoc.Close(); HttpContext.Current.Response.Write(pdfDoc); HttpContext.Current.Response.End(); }
private void EscrevaProcessosNoDocumento() { Table tabela = new Table(9); tabela.Widths = new Single[] {100, 100, 100, 100, 100, 400, 400, 90, 85}; tabela.Padding = 1; tabela.Spacing = 0; tabela.Width = 100; tabela.AutoFillEmptyCells = true; var corBackgroudHeader = new Color(211, 211, 211); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Número do processo", _Fonte2, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true)); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Data do cadastro", _Fonte2, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true)); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Data do depósito", _Fonte2, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true)); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Data de concessão", _Fonte2, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true)); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Data da vigência", _Fonte2, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true)); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Marca", _Fonte2, Cell.ALIGN_LEFT, 0, corBackgroudHeader, true)); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Cliente", _Fonte2, Cell.ALIGN_LEFT, 0, corBackgroudHeader, true)); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Despacho", _Fonte2, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true)); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Ativo?", _Fonte2, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true)); tabela.EndHeaders(); foreach (var processo in _processos) { tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Processo.ToString(), _Fonte1, Cell.ALIGN_CENTER,0, false)); tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.DataDoCadastro.ToString("dd/MM/yyyy"), _Fonte1, Cell.ALIGN_CENTER, 0, false)); tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.DataDoDeposito.HasValue ? processo.DataDoDeposito.Value.ToString("dd/MM/yyyy") : "", _Fonte1, Cell.ALIGN_CENTER, 0, false)); tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.DataDeConcessao.HasValue ? processo.DataDeConcessao.Value.ToString("dd/MM/yyyy") : "", _Fonte1, Cell.ALIGN_CENTER, 0, false)); tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.DataDaVigencia.HasValue ? processo.DataDaVigencia.Value.ToString("dd/MM/yyyy") : "", _Fonte1, Cell.ALIGN_CENTER, 0, false)); tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Marca.DescricaoDaMarca, _Fonte1, Cell.ALIGN_LEFT,0 , false)); tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Marca.Cliente.Pessoa.Nome, _Fonte1, Cell.ALIGN_LEFT, 0, false)); tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Despacho != null ? processo.Despacho.CodigoDespacho.ToString() : "", _Fonte1, Cell.ALIGN_CENTER, 0, false)); tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Ativo ? "SIM" : "NÃO", _Fonte1, Cell.ALIGN_CENTER, 0, false)); } _documento.Add(tabela); // Chunk linhaQuantidadeDeItens = new Chunk(String.Concat("Quantidade de processos de marcas : ", _processos.Count), _Fonte4); // _documento.Add(linhaQuantidadeDeItens); }
public static string generarPdf(Hashtable htFacturaxion, HttpContext hc) { string pathPdf = htFacturaxion["rutaDocumentoPdf"].ToString(); FileStream fs = new FileStream(pathPdf, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); try { DAL dal = new DAL(); StringBuilder sbConfigFactParms = new StringBuilder(); StringBuilder sbConfigFact = new StringBuilder(); StringBuilder sbDataEmisor = new StringBuilder(); StringBuilder sbOpcionalEncabezado = new StringBuilder(); DataTable dtConfigFact = new DataTable(); DataTable dtDataEmisor = new DataTable(); DataTable dtOpcEncabezado = new DataTable(); _ci.NumberFormat.CurrencyDecimalDigits = 4; _c2.NumberFormat.CurrencyDecimalDigits = 2; electronicDocument = (ElectronicDocument)htFacturaxion["electronicDocument"]; objTimbre = (Data)htFacturaxion["objTimbre"]; timbrar = Convert.ToBoolean(htFacturaxion["timbrar"]); //pathPdf = htFacturaxion["rutaDocumentoPdf"].ToString(); Int64 idCfdi = Convert.ToInt64(htFacturaxion["idCfdi"]); #region "Extraemos los datos del CFDI" sbConfigFactParms. Append("F:I:").Append(Convert.ToInt64(htFacturaxion["idSucursalEmisor"])). Append(";"). Append("F:I:").Append(Convert.ToInt32(htFacturaxion["tipoComprobante"])). Append(";"). Append("F:S:").Append(electronicDocument.Data.Total.Value). Append(";"). Append("F:I:").Append(Convert.ToInt32(htFacturaxion["idMoneda"])). Append(";"). Append("F:I:").Append(Convert.ToInt64(htFacturaxion["idEmisor"])); sbConfigFact. Append("DECLARE @idEmpresa AS INT; SET @idEmpresa = 0; "). Append("SELECT rutaTemplateHeader, CF.rutaLogo, objDesc, posX, posY, fontSize, dbo.convertNumToTextFunction( @2, @3) AS cantidadLetra, "). Append("logoPosX, logoPosY, headerPosX, headerPosY, footerPosX, footerPosY, conceptosColWidth, desgloseColWidth, S.nombreSucursal "). Append("FROM configuracionFacturas CF "). Append("LEFT OUTER JOIN sucursales S ON S.idSucursal = @0 "). Append("LEFT OUTER JOIN configuracionFactDet CFD ON CF.idConFact = CFD.idConFact "). Append("WHERE CF.ST = 1 AND CF.idEmpresa = -1 AND CF.idTipoComp = @1 AND idCFDProcedencia = 1 AND objDesc NOT LIKE 'nuevoLbl%' "); sbDataEmisor. Append("SELECT nombreSucursal FROM sucursales WHERE idSucursal = @0 "); sbOpcionalEncabezado. Append("SELECT campo1 AS observaciones "). //Append("campo2 AS observaciones2"). //Append("campo3 AS observaciones3"). Append("FROM opcionalEncabezado WHERE idCFDI = @0 and ST = 1"); dtConfigFact = dal.QueryDT("DS_FE", sbConfigFact.ToString(), sbConfigFactParms.ToString(), hc); dtDataEmisor = dal.QueryDT("DS_FE", sbDataEmisor.ToString(), "F:I:" + htFacturaxion["idSucursalEmisor"].ToString(), hc); dtOpcEncabezado = dal.QueryDT("DS_FE", sbOpcionalEncabezado.ToString(), "F:I:" + idCfdi, hc); Hashtable htDatosCfdi = new Hashtable(); #region "Dirección Emisor" StringBuilder sbDirEmisor1 = new StringBuilder(); StringBuilder sbDirEmisor2 = new StringBuilder(); StringBuilder sbDirEmisor3 = new StringBuilder(); if (electronicDocument.Data.Emisor.Domicilio.Calle.Value.Length > 0) { sbDirEmisor1.Append("Calle ").Append(electronicDocument.Data.Emisor.Domicilio.Calle.Value).Append(" "); } if (electronicDocument.Data.Emisor.Domicilio.NumeroExterior.Value.Length > 0) { sbDirEmisor1.Append(", No. Ext ").Append(electronicDocument.Data.Emisor.Domicilio.NumeroExterior.Value).Append(" "); } if (electronicDocument.Data.Emisor.Domicilio.NumeroInterior.Value.Length > 0) { sbDirEmisor1.Append(", No. Int ").Append(electronicDocument.Data.Emisor.Domicilio.NumeroInterior.Value); } if (electronicDocument.Data.Emisor.Domicilio.Colonia.Value.Length > 0) { sbDirEmisor2.Append("Col. ").Append(electronicDocument.Data.Emisor.Domicilio.Colonia.Value).Append(" "); } if (electronicDocument.Data.Emisor.Domicilio.CodigoPostal.Value.Length > 0) { sbDirEmisor2.Append(", C.P. ").Append(electronicDocument.Data.Emisor.Domicilio.CodigoPostal.Value).Append(" "); } if (electronicDocument.Data.Emisor.Domicilio.Localidad.Value.Length > 0) { sbDirEmisor2.Append(", ").Append(electronicDocument.Data.Emisor.Domicilio.Localidad.Value); } if (electronicDocument.Data.Emisor.Domicilio.Municipio.Value.Length > 0) { sbDirEmisor3.Append("Mpio. / Del. ").Append(electronicDocument.Data.Emisor.Domicilio.Municipio.Value).Append(" "); } if (electronicDocument.Data.Emisor.Domicilio.Estado.Value.Length > 0) { sbDirEmisor3.Append(", Estado ").Append(electronicDocument.Data.Emisor.Domicilio.Estado.Value).Append(" "); } sbDirEmisor3.Append(", ").Append(electronicDocument.Data.Emisor.Domicilio.Pais.Value); #endregion #region "Dirección Sucursal Expedido En" StringBuilder sbDirExpedido1 = new StringBuilder(); StringBuilder sbDirExpedido2 = new StringBuilder(); StringBuilder sbDirExpedido3 = new StringBuilder(); if (electronicDocument.Data.Emisor.ExpedidoEn.Calle.Value.Length > 0) { sbDirExpedido1.Append("Calle ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Calle.Value).Append(" "); } if (electronicDocument.Data.Emisor.ExpedidoEn.NumeroExterior.Value.Length > 0) { sbDirExpedido1.Append(", No. Ext ").Append(electronicDocument.Data.Emisor.ExpedidoEn.NumeroExterior.Value).Append(" "); } if (electronicDocument.Data.Emisor.ExpedidoEn.NumeroInterior.Value.Length > 0) { sbDirExpedido1.Append(", No. Int ").Append(electronicDocument.Data.Emisor.ExpedidoEn.NumeroInterior.Value); } if (electronicDocument.Data.Emisor.ExpedidoEn.Colonia.Value.Length > 0) { sbDirExpedido2.Append("Col. ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Colonia.Value).Append(" "); } if (electronicDocument.Data.Emisor.ExpedidoEn.CodigoPostal.Value.Length > 0) { sbDirExpedido2.Append(", C.P. ").Append(electronicDocument.Data.Emisor.ExpedidoEn.CodigoPostal.Value).Append(" "); } if (electronicDocument.Data.Emisor.ExpedidoEn.Localidad.Value.Length > 0) { sbDirExpedido2.Append(", ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Localidad.Value); } if (electronicDocument.Data.Emisor.ExpedidoEn.Municipio.Value.Length > 0) { sbDirExpedido3.Append("Mpio. / Del. ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Municipio.Value).Append(" "); } if (electronicDocument.Data.Emisor.ExpedidoEn.Estado.Value.Length > 0) { sbDirExpedido3.Append(", Estado ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Estado.Value).Append(" "); } sbDirExpedido3.Append(", ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Pais.Value); #endregion #region "Dirección Receptor" StringBuilder sbDirReceptor1 = new StringBuilder(); StringBuilder sbDirReceptor2 = new StringBuilder(); StringBuilder sbDirReceptor3 = new StringBuilder(); if (electronicDocument.Data.Receptor.Domicilio.Calle.Value.Length > 0) { sbDirReceptor1.Append("Calle ").Append(electronicDocument.Data.Receptor.Domicilio.Calle.Value).Append(" "); } if (electronicDocument.Data.Receptor.Domicilio.NumeroExterior.Value.Length > 0) { sbDirReceptor1.Append(", No. Ext ").Append(electronicDocument.Data.Receptor.Domicilio.NumeroExterior.Value).Append(" "); } if (electronicDocument.Data.Receptor.Domicilio.NumeroInterior.Value.Length > 0) { sbDirReceptor1.Append(", No. Int ").Append(electronicDocument.Data.Receptor.Domicilio.NumeroInterior.Value); } if (electronicDocument.Data.Receptor.Domicilio.Colonia.Value.Length > 0) { sbDirReceptor2.Append("Col. ").Append(electronicDocument.Data.Receptor.Domicilio.Colonia.Value).Append(" "); } if (electronicDocument.Data.Receptor.Domicilio.CodigoPostal.Value.Length > 0) { sbDirReceptor2.Append(", C.P. ").Append(electronicDocument.Data.Receptor.Domicilio.CodigoPostal.Value).Append(" "); } if (electronicDocument.Data.Receptor.Domicilio.Localidad.Value.Length > 0) { sbDirReceptor2.Append(", ").Append(electronicDocument.Data.Receptor.Domicilio.Localidad.Value); } if (electronicDocument.Data.Receptor.Domicilio.Municipio.Value.Length > 0) { sbDirReceptor3.Append("Mpio. / Del. ").Append(electronicDocument.Data.Receptor.Domicilio.Municipio.Value).Append(" "); } if (electronicDocument.Data.Receptor.Domicilio.Estado.Value.Length > 0) { sbDirReceptor3.Append(", Estado ").Append(electronicDocument.Data.Receptor.Domicilio.Estado.Value).Append(" "); } sbDirReceptor3.Append(", ").Append(electronicDocument.Data.Receptor.Domicilio.Pais.Value); #endregion htDatosCfdi.Add("rfcEmisor", electronicDocument.Data.Emisor.Rfc.Value); htDatosCfdi.Add("rfcEmpresa", electronicDocument.Data.Emisor.Rfc.Value); htDatosCfdi.Add("nombreEmisor", "Razón Social " + electronicDocument.Data.Emisor.Nombre.Value); htDatosCfdi.Add("empresa", "Razón Social " + electronicDocument.Data.Emisor.Nombre.Value); htDatosCfdi.Add("rfcReceptor", electronicDocument.Data.Receptor.Rfc.Value); htDatosCfdi.Add("rfcCliente", electronicDocument.Data.Receptor.Rfc.Value); htDatosCfdi.Add("nombreReceptor", "Razón Social " + electronicDocument.Data.Receptor.Nombre.Value); htDatosCfdi.Add("cliente", "Razón Social " + electronicDocument.Data.Receptor.Nombre.Value); htDatosCfdi.Add("sucursal", "Sucursal " + dtDataEmisor.Rows[0]["nombreSucursal"]); htDatosCfdi.Add("serie", electronicDocument.Data.Serie.Value); htDatosCfdi.Add("folio", electronicDocument.Data.Folio.Value); htDatosCfdi.Add("fechaCfdi", electronicDocument.Data.Fecha.Value); htDatosCfdi.Add("fechaFactura", electronicDocument.Data.Fecha.Value); htDatosCfdi.Add("UUID", objTimbre.Uuid.Value.ToUpper()); htDatosCfdi.Add("folioFiscal", objTimbre.Uuid.Value); htDatosCfdi.Add("direccionEmisor1", sbDirEmisor1.ToString()); htDatosCfdi.Add("direccionEmpresa1", sbDirEmisor1.ToString()); htDatosCfdi.Add("direccionEmisor2", sbDirEmisor2.ToString()); htDatosCfdi.Add("direccionEmpresa2", sbDirEmisor2.ToString()); htDatosCfdi.Add("direccionEmisor3", sbDirEmisor3.ToString()); htDatosCfdi.Add("direccionEmpresa3", sbDirEmisor3.ToString()); htDatosCfdi.Add("direccionExpedido1", sbDirExpedido1.ToString()); htDatosCfdi.Add("direccionSucursal1", sbDirExpedido1.ToString()); htDatosCfdi.Add("direccionExpedido2", sbDirExpedido2.ToString()); htDatosCfdi.Add("direccionSucursal2", sbDirExpedido2.ToString()); htDatosCfdi.Add("direccionExpedido3", sbDirExpedido3.ToString()); htDatosCfdi.Add("direccionSucursal3", sbDirExpedido3.ToString()); htDatosCfdi.Add("direccionReceptor1", sbDirReceptor1.ToString()); htDatosCfdi.Add("direccionCliente1", sbDirReceptor1.ToString()); htDatosCfdi.Add("direccionReceptor2", sbDirReceptor2.ToString()); htDatosCfdi.Add("direccionCliente2", sbDirReceptor2.ToString()); htDatosCfdi.Add("direccionReceptor3", sbDirReceptor3.ToString()); htDatosCfdi.Add("direccionCliente3", sbDirReceptor3.ToString()); #endregion #region "Creamos el Objeto Documento y Tipos de Letra" Document document = new Document(PageSize.LETTER, 15, 15, 15, 40); document.AddAuthor("Facturaxion"); document.AddCreator("r3Take"); document.AddCreationDate(); //pdfPageEventHandlerProbell pageEventHandler = new pdfPageEventHandlerProbell(); PdfWriter writer = PdfWriter.GetInstance(document, fs); writer.SetFullCompression(); writer.ViewerPreferences = PdfWriter.PageModeUseNone; //writer.PageEvent = pageEventHandler; PdfPageEventHandlerSoliplas sol = new PdfPageEventHandlerSoliplas(); writer.PageEvent = sol; writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_7); azul = new Color(22, 111, 168); azul1 = new Color(43, 145, 175); blanco = new Color(255, 255, 255); Link = new Color(7, 73, 208); gris = new Color(236, 236, 236); grisOX = new Color(220, 215, 220); rojo = new Color(230, 7, 7); lbAzul = new Color(43, 145, 175); EM = BaseFont.CreateFont(@"C:\Windows\Fonts\VERDANA.TTF", BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); f5 = new Font(EM, 5); f5B = new Font(EM, 5, Font.BOLD); f5BBI = new Font(EM, 5, Font.BOLDITALIC); f6 = new Font(EM, 6); f6B = new Font(EM, 6, Font.BOLD); f6L = new Font(EM, 6, Font.BOLD, Link); f5L = new Font(EM, 5, Font.BOLD, lbAzul); titulo = new Font(EM, 6, Font.BOLD, blanco); folio = new Font(EM, 6, Font.BOLD, rojo); PdfPCell cell; Paragraph par; Cell cel; dSaltoLinea = new Chunk("\n\n "); #endregion PdfPTable encabezado = new PdfPTable(3); encabezado.WidthPercentage = 100; encabezado.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; encabezado.SetWidths(new int[3] { 30, 10, 60 }); encabezado.DefaultCell.Border = 0; encabezado.LockedWidth = true; pathIMGLOGO = @"C:\Inetpub\repositorioFacturaxion\imagesFacturaEspecial\SOLIPLAS\logoSoliplas.png"; pathIMGFX = @"C:\Inetpub\repositorioFacturaxion\imagesFacturaEspecial\SOLIPLAS\cfdifx.png"; Image imgLogo = Image.GetInstance(pathIMGLOGO); imgLogo.ScalePercent(48f); Image imgFx = Image.GetInstance(pathIMGFX); imgFx.ScalePercent(25f); #region "Construimos el encabezado y Detalles del documento" //Encabezado Folio Fiscal Table encabezadoFolio = new Table(3); float[] headerEncabezadoFolio = { 60, 10, 30 }; encabezadoFolio.Widths = headerEncabezadoFolio; encabezadoFolio.WidthPercentage = 100F; encabezadoFolio.Padding = 1; encabezadoFolio.Spacing = 1; encabezadoFolio.BorderWidth = 0; encabezadoFolio.DefaultCellBorder = 0; encabezadoFolio.BorderColor = gris; cel = new Cell(imgFx); cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; encabezadoFolio.AddCell(cel); cel = new Cell(new Phrase("Folio Fiscal", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoFolio.AddCell(cel); cel = new Cell(new Phrase(htDatosCfdi["folioFiscal"].ToString().ToUpper(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = azul; encabezadoFolio.AddCell(cel); //Encabezado Comprobante Table encabezadoComprobante = new Table(6); float[] headerEncabezadoComprobante = { 30,40,5,5,10,10 }; encabezadoComprobante.Widths = headerEncabezadoComprobante; encabezadoComprobante.WidthPercentage = 100F; encabezadoComprobante.Padding = 1; encabezadoComprobante.Spacing = 1; encabezadoComprobante.BorderWidth = 0; encabezadoComprobante.DefaultCellBorder = 0; encabezadoComprobante.BorderColor = gris; //LOGO DELA EMPRESA cel = new Cell(imgLogo); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 4; //cel.Colspan = 2; encabezadoComprobante.AddCell(cel); //EMISOR StringBuilder emisor = new StringBuilder(); emisor. Append("RFC: "). Append(htDatosCfdi["rfcEmisor"].ToString().ToUpper()).Append("\n"). Append(htDatosCfdi["nombreEmisor"]).Append("\n"). Append(htDatosCfdi["direccionEmisor1"].ToString().ToUpper()).Append("\n"). Append(htDatosCfdi["direccionEmisor2"].ToString().ToUpper()).Append("\n"). Append(htDatosCfdi["direccionEmisor3"].ToString().ToUpper()).Append("\n"); cel = new Cell(new Phrase(emisor.ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_RIGHT; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.Rowspan = 4; cel.Colspan = 3; encabezadoComprobante.AddCell(cel); // Serie cel = new Cell(new Phrase("Serie", titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; //cel.Colspan = 3; encabezadoComprobante.AddCell(cel); // Folio cel = new Cell(new Phrase("Folio", titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezadoComprobante.AddCell(cel); cel = new Cell(new Phrase(htDatosCfdi["serie"].ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezadoComprobante.AddCell(cel); cel = new Cell(new Phrase(htDatosCfdi["folio"].ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezadoComprobante.AddCell(cel); // Fecha de emisión del comprobante cel = new Cell(new Phrase("Fecha", titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; encabezadoComprobante.AddCell(cel); cel = new Cell(new Phrase(htDatosCfdi["fechaFactura"].ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; encabezadoComprobante.AddCell(cel); Table encabezadoComprobante1 = new Table(2); float[] headerEncabezadoComprobante1 = { 50, 50 }; encabezadoComprobante1.Widths = headerEncabezadoComprobante1; encabezadoComprobante1.WidthPercentage = 100F; encabezadoComprobante1.Padding = 1; encabezadoComprobante1.Spacing = 1; encabezadoComprobante1.BorderWidth = 0; encabezadoComprobante1.DefaultCellBorder = 0; encabezadoComprobante1.BorderColor = gris; //Datos discales del cliente cel = new Cell(new Phrase("Datos Fiscales del Cliente", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoComprobante1.AddCell(cel); //Expedido en: cel = new Cell(new Phrase("Expedido en:", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoComprobante1.AddCell(cel); //Receptor StringBuilder cliente = new StringBuilder(); cliente. Append("\nRFC: "). Append(htDatosCfdi["rfcCliente"].ToString().ToUpper()).Append("\n"). Append(htDatosCfdi["cliente"]).Append("\n"). Append(htDatosCfdi["direccionCliente1"].ToString().ToUpper()).Append("\n"). Append(htDatosCfdi["direccionCliente2"].ToString().ToUpper()).Append("\n"). Append(htDatosCfdi["direccionCliente3"].ToString().ToUpper()).Append("\n"). Append("\n"); cel = new Cell(new Phrase(cliente.ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.Rowspan = 5; encabezadoComprobante1.AddCell(cel); //Expedido en: StringBuilder expedido = new StringBuilder(); expedido. //Append(htDatosCfdi["sucursal"]).Append("\n"). Append(htDatosCfdi["direccionExpedido1"].ToString().ToUpper()).Append("\n"). Append(htDatosCfdi["direccionExpedido2"].ToString().ToUpper()).Append("\n"). Append(htDatosCfdi["direccionExpedido3"].ToString().ToUpper()).Append("\n"). Append("\n"); cel = new Cell(new Phrase(expedido.ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.UseBorderPadding = true; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.Rowspan = 5; encabezadoComprobante1.AddCell(cel); #endregion sol.encabezado = encabezado; sol.dSaltoLinea = dSaltoLinea; #region "Tabla Detalle" Table encabezadoDetalle = new Table(6); float[] headerEncabezadoDetalle = { 7, 8, 11, 52, 13, 13 }; encabezadoDetalle.Widths = headerEncabezadoDetalle; encabezadoDetalle.WidthPercentage = 100F; encabezadoDetalle.Padding = 1; encabezadoDetalle.Spacing = 1; encabezadoDetalle.BorderWidth = 0; encabezadoDetalle.DefaultCellBorder = 0; encabezadoDetalle.BorderColor = gris; // Número cel = new Cell(new Phrase("Cantidad", titulo)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Còdigo de Barras cel = new Cell(new Phrase("Unidad", titulo)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Código cel = new Cell(new Phrase("Código", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Descripción cel = new Cell(new Phrase("Descripción", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Precio Unitario cel = new Cell(new Phrase("Precio Unitario", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Importe cel = new Cell(new Phrase("Importe", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BackgroundColor = azul; encabezadoDetalle.AddCell(cel); // Creamos la tabla para insertar los conceptos de detalle de la factura PdfPTable tableConceptos = new PdfPTable(6); int[] colWithsConceptos = new int[6]; //String[] arrColWidthConceptos = dtConfigFact.Rows[0]["conceptosColWidth"].ToString().Split(new Char[] { ',' }); String[] arrColWidthConceptos = { "12", "8", "15", "51", "13", "17" }; for (int i = 0; i < arrColWidthConceptos.Length; i++) { colWithsConceptos.SetValue(Convert.ToInt32(arrColWidthConceptos[i]), i); } tableConceptos.SetWidths(colWithsConceptos); tableConceptos.WidthPercentage = 100F; int numConceptos = electronicDocument.Data.Conceptos.Count; PdfPCell cellConceptos = new PdfPCell(); PdfPCell cellMontos = new PdfPCell(); for (int i = 0; i < numConceptos; i++) { cellConceptos = new PdfPCell(new Phrase(" "+ electronicDocument.Data.Conceptos[i].Cantidad.Value.ToString(), new Font(Font.HELVETICA, 7, Font.NORMAL))); cellConceptos.Border = 0; cellConceptos.HorizontalAlignment = PdfCell.ALIGN_LEFT; tableConceptos.AddCell(cellConceptos); cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Unidad.Value, new Font(Font.HELVETICA, 7, Font.NORMAL))); cellConceptos.Border = 0; cellConceptos.HorizontalAlignment = PdfCell.ALIGN_LEFT; tableConceptos.AddCell(cellConceptos); cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].NumeroIdentificacion.Value, new Font(Font.HELVETICA, 7, Font.NORMAL))); cellConceptos.Border = 0; cellConceptos.HorizontalAlignment = PdfPCell.ALIGN_LEFT; tableConceptos.AddCell(cellConceptos); cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Descripcion.Value, new Font(Font.HELVETICA, 7, Font.NORMAL))); cellConceptos.Border = 0; tableConceptos.AddCell(cellConceptos); cellMontos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].ValorUnitario.Value.ToString("C", _ci), new Font(Font.HELVETICA, 7, Font.NORMAL))); cellMontos.Border = 0; cellMontos.HorizontalAlignment = PdfCell.ALIGN_RIGHT; tableConceptos.AddCell(cellMontos); cellMontos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Importe.Value.ToString("C", _ci), new Font(Font.HELVETICA, 7, Font.NORMAL))); cellMontos.Border = 0; cellMontos.HorizontalAlignment = PdfCell.ALIGN_RIGHT; tableConceptos.AddCell(cellMontos); } dSaltoLinea = new Chunk("\n\n "); #endregion #region "Construimos el Comentarios" Table comentarios = new Table(7); float[] headerwidthsComentarios = { 18, 18, 28, 28, 7, 5, 5 }; comentarios.Widths = headerwidthsComentarios; comentarios.WidthPercentage = 100; comentarios.Padding = 1; comentarios.Spacing = 1; comentarios.BorderWidth = 0; comentarios.DefaultCellBorder = 0; comentarios.BorderColor = gris; cel = new Cell(new Phrase("Observaciones:", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Cantidad:", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Sub Total", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.SubTotal.Value.ToString("C", _c2), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase(dtOpcEncabezado.Rows[0]["observaciones"].ToString(), f5)); cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; cel.Rowspan = 3; comentarios.AddCell(cel); cel = new Cell(new Phrase(dtConfigFact.Rows[0]["cantidadLetra"].ToString(), f5));//CE26 cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; cel.Rowspan = 3; comentarios.AddCell(cel); cel = new Cell(new Phrase("Descuento",f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Descuento.Value.ToString("C", _c2), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); double importe = 0; double tasa = 0; for (int i = 0; i < electronicDocument.Data.Impuestos.Traslados.Count; i++) { if (electronicDocument.Data.Impuestos.Traslados[i].Tipo.Value == "IVA") { importe = electronicDocument.Data.Impuestos.Traslados[i].Importe.Value; tasa = electronicDocument.Data.Impuestos.Traslados[i].Tasa.Value; break; } } cel = new Cell(new Phrase("IVA " + tasa.ToString() + " %", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.TotalTraslados.Value.ToString("C", _c2), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Total", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Total.Value.ToString("C", _c2), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); #endregion #region "Construimos Tabla Datos CFDi" DefaultSplitCharacter split = new DefaultSplitCharacter(); Table adicional = new Table(3); float[] headerwidthsAdicional = { 20, 25, 55 }; adicional.Widths = headerwidthsAdicional; adicional.WidthPercentage = 100; adicional.Padding = 1; adicional.Spacing = 1; adicional.BorderWidth = (float).5; adicional.DefaultCellBorder = 1; adicional.BorderColor = gris; if (timbrar) { #region "Generamos Quick Response Code" byte[] bytesQRCode = new byte[0]; if (timbrar) { // Generamos el Quick Response Code (QRCode) string re = electronicDocument.Data.Emisor.Rfc.Value; string rr = electronicDocument.Data.Receptor.Rfc.Value; string tt = String.Format("{0:F6}", electronicDocument.Data.Total.Value); string id = objTimbre.Uuid.Value; StringBuilder sbCadenaQRCode = new StringBuilder(); sbCadenaQRCode. Append("?"). Append("re=").Append(re). Append("&"). Append("rr=").Append(rr). Append("&"). Append("tt=").Append(tt). Append("&"). Append("id=").Append(id); BarcodeLib.Barcode.QRCode.QRCode barcode = new BarcodeLib.Barcode.QRCode.QRCode(); barcode.Data = sbCadenaQRCode.ToString(); barcode.ModuleSize = 3; barcode.LeftMargin = 0; barcode.RightMargin = 10; barcode.TopMargin = 0; barcode.BottomMargin = 0; barcode.Encoding = BarcodeLib.Barcode.QRCode.QRCodeEncoding.Auto; barcode.Version = BarcodeLib.Barcode.QRCode.QRCodeVersion.Auto; barcode.ECL = BarcodeLib.Barcode.QRCode.ErrorCorrectionLevel.L; bytesQRCode = barcode.drawBarcodeAsBytes(); } #endregion Image imageQRCode = Image.GetInstance(bytesQRCode); imageQRCode.Alignment = (Image.TEXTWRAP | Image.ALIGN_LEFT); imageQRCode.ScaleToFit(90f, 90f); imageQRCode.IndentationLeft = 9f; imageQRCode.SpacingAfter = 9f; imageQRCode.BorderColorTop = Color.WHITE; cel = new Cell(imageQRCode); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 6; adicional.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("SELLO DIGITAL DEL EMISOR\n", f5L)); par.Add(new Chunk(electronicDocument.Data.Sello.Value, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Colspan = 2; adicional.AddCell(cel); cel = new Cell(new Phrase("FOLIO FISCAL:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase(objTimbre.Uuid.Value.ToUpper(), f5)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("FECHA Y HORA DE CERTIFICACION:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); string[] fechaTimbrado = Convert.ToDateTime(objTimbre.FechaTimbrado.Value).GetDateTimeFormats('s'); cel = new Cell(new Phrase(fechaTimbrado[0], f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL SAT:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase(objTimbre.NumeroCertificadoSat.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL EMISOR:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; adicional.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.NumeroCertificado.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = (float).5; adicional.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("TIPO DE COMPROBANTE: ", f5L)); par.Add(new Chunk(electronicDocument.Data.TipoComprobante.Value + " | ", f5)); par.Add(new Chunk("Moneda: ", f5L)); par.Add(new Chunk(electronicDocument.Data.Moneda.Value + " | ", f5)); par.Add(new Chunk("TASA DE CAMBIO: ", f5L)); string tasaCambio = electronicDocument.Data.TipoCambio.Value; string regimenes = ""; if (tasaCambio.Length > 0) { par.Add(new Chunk(Convert.ToDouble(tasaCambio).ToString("C", _ci) + " | ", f5)); } else { par.Add(new Chunk(" | ", f5)); } par.Add(new Chunk("FORMA DE PAGO: ", f5L)); par.Add(new Chunk(electronicDocument.Data.FormaPago.Value + " | ", f5)); par.Add(new Chunk("MÉTODO DE PAGO: ", f5L)); par.Add(new Chunk(electronicDocument.Data.MetodoPago.Value, f5)); if (electronicDocument.Data.Emisor.Regimenes.Count > 0) { for (int u = 0; u < electronicDocument.Data.Emisor.Regimenes.Count; u++) regimenes += electronicDocument.Data.Emisor.Regimenes[u].Regimen.Value.ToString() + ","; par.Add(new Chunk(" | ", f5)); par.Add(new Chunk("RÉGIMEN FISCAL: ", f5L)); par.Add(new Chunk(regimenes.Substring(0, regimenes.Length - 1).ToString(), f5)); par.Add(new Chunk(" | ", f5)); } if (electronicDocument.Data.CondicionesPago.Value.ToString().Length > 0) { par.Add(new Chunk(" | ", f5)); par.Add(new Chunk("CONDICIONES DE PAGO: ", f5L)); par.Add(new Chunk(electronicDocument.Data.CondicionesPago.Value.ToString(), f5)); par.Add(new Chunk(" | ", f5)); } if (electronicDocument.Data.NumeroCuentaPago.Value.ToString().Length > 0) { par.Add(new Chunk(" | ", f5)); par.Add(new Chunk("No. CUENTA: ", f5L)); par.Add(new Chunk(electronicDocument.Data.NumeroCuentaPago.Value, f5)); par.Add(new Chunk(" | ", f5)); } cel.BorderColor = gris; cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; cel.BorderColor = gris; adicional.AddCell(cel); if (electronicDocument.Data.LugarExpedicion.Value.Length > 0) { par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("LUGAR EXPEDICIÓN: ", f5L)); par.Add(new Chunk(electronicDocument.Data.LugarExpedicion.Value, f5)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 3; adicional.AddCell(cel); } par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("CADENA ORIGINAL DEL COMPLEMENTO DE CERTIFICACIÓN DIGITAL DEL SAT\n", f5L)); par.Add(new Chunk(electronicDocument.FingerPrintPac, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Colspan = 3; adicional.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 0f); par.Add(new Chunk("SELLO DIGITAL DEL SAT\n", f5L)); par.Add(new Chunk(objTimbre.SelloSat.Value, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 3; adicional.AddCell(cel); } #endregion #region "Construimos Tabla del Footer" PdfPTable footer = new PdfPTable(1); footer.WidthPercentage = 100; footer.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; cell = new PdfPCell(new Phrase("", f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.BorderWidthBottom = 0; footer.AddCell(cell); cell = new PdfPCell(new Phrase("ESTE DOCUMENTO ES UNA REPRESENTACIÓN IMPRESA DE UN CFDI", titulo)); cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = azul; cell.BorderWidthTop = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.BorderWidthBottom = 0; footer.AddCell(cell); #endregion sol.encFolioFiscal = encabezadoFolio; sol.encComprobante = encabezadoComprobante; sol.encComprobante1 = encabezadoComprobante1; sol.encTitulos = encabezadoDetalle; sol.adicional = adicional; sol.footer = footer; document.Open(); document.Add(tableConceptos); document.Add(comentarios); document.Add(adicional); string filePdfExt = pathPdf.Replace(_rutaDocs, _rutaDocsExt); string urlPathFilePdf = filePdfExt.Replace(@"\", "/"); document.Close(); writer.Close(); fs.Close(); //Subimos Archivo al Azure string res = App_Code.com.Facturaxion.facturaEspecial.wAzure.azureUpDownLoad(1, pathPdf); return "1#" + urlPathFilePdf; } catch (Exception ex) { fs.Flush(); fs.Close(); File.Delete(pathPdf); return "0#" + ex.Message; } }
/// <summary> /// overloading per passare nome e cognome dell'utente loggato,in modo da evidenziare le trasmissioni di cui l'utente è destinatario /// Dimitri /// </summary> /// <param name="tableTmp"></param> /// <param name="dt"></param> /// <param name="docPDF"></param> /// <param name="infoUt"></param> /// <returns></returns> protected static DocumentPDF printCustomTable(StampaVO.Table tableTmp, DataTable dt, DocumentPDF docPDF, DocsPaVO.utente.InfoUtente infoUt) { if (dt == null) { return(docPDF); } //** Operazioni Preliminari //reupero del numero di colonne dal DataTable int col = tableTmp.columns.Length; int col_visible = 0; for (int j = 0; j < tableTmp.columns.Length; j++) { if (tableTmp.columns[j].visible) { col_visible++; } } try { //creazione della tabella iTextSharp.text.Table aTable = new iTextSharp.text.Table(col_visible); //Adattamento delle colonne al contenuto aTable.Padding = tableTmp.padding; aTable.Spacing = tableTmp.spacing; //aTable.WidthPercentage = 100; aTable.Width = 100; aTable.Alignment = Utils.getAlign(tableTmp.align); int[] widths = getColWidths(tableTmp, col_visible); aTable.SetWidths(widths); //aTable.hasToFitPageCells(); aTable.TableFitsPage = true; //** Aggiunta automatica dell'header della tabella for (int k = 0; k < col; k++) { if (((StampaVO.Column)tableTmp.columns[k]).visible) { StampaVO.Font font = tableTmp.headerTable.font; Font font1 = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(font.style), Utils.getColor(font.color)); string testo = ((StampaVO.Column)tableTmp.columns[k]).alias; string[] testoSplit = testo.Split(';'); string testo_1 = string.Empty; if (testoSplit.Length > 1) { testo_1 = @testoSplit[0] + "\n" + testoSplit[1]; } else { testo_1 = testoSplit[0]; } Cell c = new Cell(new Phrase(testo_1, font1)); if (((StampaVO.Column)tableTmp.columns[k]).name == "DESCR" || ((StampaVO.Column)tableTmp.columns[k]).name == "MITT_UT" || ((StampaVO.Column)tableTmp.columns[k]).name == "DEST" || ((StampaVO.Column)tableTmp.columns[k]).name == "NOTE_GENER") { c.HorizontalAlignment = Utils.getAlign("LEFT"); } else { c.HorizontalAlignment = Utils.getAlign(tableTmp.headerTable.align); } c.VerticalAlignment = Utils.getAlign(tableTmp.headerTable.vAlign); c.NoWrap = true; c.BackgroundColor = Utils.getColor(tableTmp.headerTable.bgColor); aTable.AddCell(c); } } aTable.EndHeaders(); //** Popolamento automatico della tabella //Scansione dei dati for (int i = 0; i < dt.Rows.Count; i++) { //Creazione delle celle for (int h = 0; h < col; h++) { if (((StampaVO.Column)tableTmp.columns[h]).visible) { StampaVO.Font font = tableTmp.dataTable.font; string style = font.style; string column_name = tableTmp.columns[h].name; string evidenziaDest = ""; if (dt.Rows[i]["SYSTEM_ID_DEST_UT"].ToString() == infoUt.idPeople && column_name == "DEST_UT") { evidenziaDest = " *"; style = "BOLD"; } Font font1 = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(style), Utils.getColor(font.color)); // Font font1 = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(font.style), Utils.getColor(font.color)); Cell c1; if (column_name == "ID_REG_PROTO_ANNO") { string s = string.Empty; if (dt.Rows[i]["COD_REG"].ToString() != "") { s = @dt.Rows[i]["ID"].ToString() + "\n" + dt.Rows[i]["COD_REG"].ToString() + " - " + dt.Rows[i]["NUM_PROTO"].ToString() + " - " + dt.Rows[i]["ANNO"].ToString(); } else { s = dt.Rows[i]["ID"].ToString() + "\n Non Protocollato"; } c1 = new Cell(new Phrase(s, font1)); c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align); c1.VerticalAlignment = Utils.getAlign(tableTmp.columns[h].vAlign); aTable.AddCell(c1, new System.Drawing.Point(i + 1, h)); } if (column_name == "MITT_UT") { string s = @dt.Rows[i][column_name].ToString(); c1 = new Cell(new Phrase(s, font1)); c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align); c1.VerticalAlignment = Utils.getAlign(tableTmp.columns[h].vAlign); aTable.AddCell(c1, new System.Drawing.Point(i + 1, h)); } if (column_name == "MITT_RU") { string s = dt.Rows[i]["MITT_RU"].ToString(); c1 = new Cell(new Phrase(s, font1)); c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align); c1.VerticalAlignment = Utils.getAlign(tableTmp.columns[h].vAlign); aTable.AddCell(c1, new System.Drawing.Point(i + 1, h)); } //Aggiunta note individuali alle generali if (column_name == "NOTE_GENER") { if (dt.Rows[i]["NOTE_INDIVID"] != null) { string s = @dt.Rows[i]["NOTE_GENER"].ToString() + Environment.NewLine + "--------------" + Environment.NewLine; if (dt.Rows[i]["SYSTEM_ID_MITT_UT"].ToString() == infoUt.idPeople) { s += dt.Rows[i]["NOTE_INDIVID"].ToString(); } c1 = new Cell(new Phrase(s, font1)); c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align); c1.VerticalAlignment = Utils.getAlign(tableTmp.columns[h].vAlign); aTable.AddCell(c1, new System.Drawing.Point(i + 1, h)); } } if (column_name == "DEST_UT") { if (dt.Rows[i]["DEST_UT"] != null) { string s = @dt.Rows[i]["DEST_UT"].ToString() + evidenziaDest; c1 = new Cell(new Phrase(s, font1)); c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align); c1.VerticalAlignment = Utils.getAlign(tableTmp.columns[h].vAlign); aTable.AddCell(c1, new System.Drawing.Point(i + 1, h)); } } if (column_name != "ID_REG_PROTO_ANNO" && column_name != "MITT_UT" && column_name != "MITT_RU" && column_name != "NUM_PROTO" && column_name != "ANNO" && column_name != "NOTE_GENER" && column_name != "DEST_UT") { c1 = new Cell(new Phrase(dt.Rows[i][column_name].ToString(), font1)); c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align); c1.VerticalAlignment = Utils.getAlign(tableTmp.columns[h].vAlign); aTable.AddCell(c1, new System.Drawing.Point(i + 1, h)); } } } } // aTable.Complete(); // aTable.FlushContent(); docPDF.Add(aTable); } catch (Exception ex) { docPDF.Close(); writer.Close(); throw new ReportException(ErrorCode.IncompletePDFFile, "Errore nella scrittura dei dati: " + ex.Message); } return(docPDF); }
private Table ObtenhaTabelaInformacoesRevista(IRevistaDePatente revista) { var tabela = new Table(1); tabela.Widths = new Single[] { 100 }; tabela.Padding = 0; tabela.Spacing = 0; tabela.Width = 100; tabela.AutoFillEmptyCells = true; tabela.Border = 0; tabela.EndHeaders(); if(revista.DataPublicacao.HasValue && revista.DataPublicacao.Value != DateTime.MinValue) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout43.IdentificadorCampo + " " + revista.DataPublicacao.Value.ToString("dd/MM/yyyy"), _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (revista.DataDeDeposito.HasValue && revista.DataDeDeposito.Value != DateTime.MinValue) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout22.IdentificadorCampo + " " + revista.DataDeDeposito.Value.ToString("dd/MM/yyyy"), _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.NumeroProcessoDaPatente)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout11.IdentificadorCampo + " " + revista.NumeroProcessoDaPatente, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.NumeroDoPedido)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout21.IdentificadorCampo + " " + revista.NumeroDoProcessoFormatado, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (revista.DataDaPublicacaoDoPedido.HasValue && revista.DataDaPublicacaoDoPedido.Value != DateTime.MinValue) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout43.IdentificadorCampo + " " + revista.DataDaPublicacaoDoPedido.Value.ToString("dd/MM/yyyy"), _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (revista.DataDeConcessao.HasValue && revista.DataDeConcessao.Value != DateTime.MinValue) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout45.IdentificadorCampo + " " + revista.DataDeConcessao.Value.ToString("dd/MM/yyyy"), _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.PrioridadeUnionista)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout43.IdentificadorCampo + " " + revista.DataPublicacao.Value.ToString("dd/MM/yyyy"), _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.ClassificacaoInternacional)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout51.IdentificadorCampo + " " + revista.ClassificacaoInternacional, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Titulo)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout54.IdentificadorCampo + " " + revista.Titulo, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Resumo)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout57.IdentificadorCampo + " " + revista.Resumo, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.DadosDoPedidoDaPatente)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout61.IdentificadorCampo + " " + revista.DadosDoPedidoDaPatente, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.DadosDoPedidoOriginal)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout62.IdentificadorCampo + " " + revista.DadosDoPedidoOriginal, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.PrioridadeInterna)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout66.IdentificadorCampo + " " + revista.PrioridadeInterna, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Depositante)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout71.IdentificadorCampo + " " + revista.Depositante, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Inventor)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout72.IdentificadorCampo + " " + revista.Inventor, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Titular)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout73.IdentificadorCampo + " " + revista.Titular + " " + revista.UFTitular + " " + revista.PaisTitular, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Procurador)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout74.IdentificadorCampo + " " + revista.Procurador, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.PaisesDesignados)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout81.IdentificadorCampo + " " + revista.PaisesDesignados, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (revista.DataInicioFaseNacional.HasValue && revista.DataInicioFaseNacional.Value != DateTime.MinValue) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout85.IdentificadorCampo + " " + revista.DataInicioFaseNacional.Value.ToString("dd/MM/yyyy"), _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.DadosDepositoInternacional)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout86.IdentificadorCampo + " " + revista.DadosDepositoInternacional, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.DadosPublicacaoInternacional)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.Layout87.IdentificadorCampo + " " + revista.DadosPublicacaoInternacional, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.CodigoDoDespacho)) { var despacho = FabricaGenerica.GetInstancia().CrieObjeto<IDespachoDePatentes>(); using (var servico = FabricaGenerica.GetInstancia().CrieObjeto<IServicoDeDespachoDePatentes>()) despacho = servico.ObtenhaDespachoPeloCodigo(revista.CodigoDoDespacho); if(despacho != null) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutCD.IdentificadorCampo + " " + despacho.Codigo + " - " + despacho.Titulo, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } } if (!string.IsNullOrEmpty(revista.ResponsavelPagamentoImpostoDeRenda)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutRP.IdentificadorCampo + " " + revista.ResponsavelPagamentoImpostoDeRenda, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Complemento)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutCO.IdentificadorCampo + " " + revista.Complemento, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Decisao)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutDE.IdentificadorCampo + " " + revista.Decisao, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Recorrente)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutRE.IdentificadorCampo + " " + revista.Recorrente, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.NumeroDoProcesso)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutNP.IdentificadorCampo + " " + revista.NumeroDoProcessoFormatado, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Cedente)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutCE.IdentificadorCampo + " " + revista.Cedente, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Cessionaria)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutCS.IdentificadorCampo + " " + revista.Cessionaria, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.UltimaInformacao)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutUI.IdentificadorCampo + " " + revista.UltimaInformacao, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.CertificadoDeAverbacao)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutCA.IdentificadorCampo + " " + revista.CertificadoDeAverbacao, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.PaisCedente)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutPE.IdentificadorCampo + " " + revista.PaisCedente, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.PaisDaCessionaria)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutPS.IdentificadorCampo + " " + revista.PaisDaCessionaria, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Setor)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutSE.IdentificadorCampo + " " + revista.Setor, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.EnderecoDaCessionaria)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutES.IdentificadorCampo + " " + revista.EnderecoDaCessionaria, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.NaturezaDoDocumento)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutND.IdentificadorCampo + " " + revista.NaturezaDoDocumento, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.MoedaDePagamento)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutMO.IdentificadorCampo + " " + revista.MoedaDePagamento, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Valor)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutVA.IdentificadorCampo + " " + revista.Valor, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Pagamento)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutPG.IdentificadorCampo + " " + revista.Pagamento, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Prazo)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutPZ.IdentificadorCampo + " " + revista.Prazo, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.ServicosIsentosDeAverbacao)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutIA.IdentificadorCampo + " " + revista.ServicosIsentosDeAverbacao, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Criador)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutCR.IdentificadorCampo + " " + revista.Criador, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Linguagem)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutLG.IdentificadorCampo + " " + revista.Linguagem, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.CampoDeAplicacao)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutCP.IdentificadorCampo + " " + revista.CampoDeAplicacao, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.TipoDePrograma)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutTP.IdentificadorCampo + " " + revista.TipoDePrograma, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (revista.DataDaCriacao.HasValue && revista.DataDaCriacao.Value != DateTime.MinValue) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutDL.IdentificadorCampo + " " + revista.DataDaCriacao.Value.ToString("dd/MM/yyyy"), _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.RegimeDeGuarda)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutRG.IdentificadorCampo + " " + revista.RegimeDeGuarda, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Requerente)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutRQ.IdentificadorCampo + " " + revista.Requerente, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Redacao)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutRD.IdentificadorCampo + " " + revista.Redacao, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Criador)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutCR.IdentificadorCampo + " " + revista.Criador, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Criador)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutCR.IdentificadorCampo + " " + revista.Criador, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } if (!string.IsNullOrEmpty(revista.Criador)) { var celula = new Cell(new Phrase(" " + LayoutRevistaPatente.LayoutCR.IdentificadorCampo + " " + revista.Criador, _Fonte1)); celula.DisableBorderSide(0); tabela.AddCell(celula); } return tabela; }
public PrinterJob Build(ReportType reportType, int copies) { var reportConfig = Managers.PrintingManager.ReportConfig; var logger = Managers.PrintingManager.Logger; logger.LogVerbose(Message.Common_DebugCall); _totalPagesCount = 0; _currentPageNumber = 0; var fileName = FileUtils.GetUniqueName( Managers.FileSystemManager.GetDataDirectoryPath(FileType.Report), String.Format("{0}.{1:yyyyMMdd}.", "PrintJob", DateTime.Now), "pdf", 6); var filePath = Path.Combine(Managers.FileSystemManager.GetDataDirectoryPath(FileType.Report), fileName); using (var stream = new MemoryStream()) { try { _pdfDocument = new Document(PageSize.A4); _pdfDocument.ClaspFooter = ClaspFooter; PdfWriter writer = PdfWriter.GetInstance(_pdfDocument, stream); writer.PageEvent = new PdfEventHelper(this); _pdfDocument.SetMargins(Margins[0], Margins[1], Margins[2], Margins[3]); var fontFileName = Path.Combine(reportConfig.Font.Path, TemplateFont.ToString().ToLower() + FONT_FILE_EXTENSION); BaseFont baseFont = BaseFont.CreateFont(fontFileName, FONT_CODEPAGE, true); _font = new Font(baseFont, _defaultFontSize, Font.NORMAL); if (Headers.ContainsKey(PageSection.PageHeader) && Headers[PageSection.PageHeader].Count > 0) { logger.LogVerbose(Message.PrintingPdfBuilderStartEvent, "Создание PageHeader"); var head = new HeaderFooter(MakeParagraph(Headers[PageSection.PageHeader]), false); head.Border = Border; _pdfDocument.Header = head; logger.LogVerbose(Message.PrintingPdfBuilderEndEvent, "Создание PageHeader"); } if (Headers.ContainsKey(PageSection.PageFooter) && Headers[PageSection.PageFooter].Count > 0) { logger.LogVerbose(Message.PrintingPdfBuilderStartEvent, "Создание PageFooter"); Paragraph footParagraph = MakeParagraph(Headers[PageSection.PageFooter]); if (PageNumbered) { footParagraph.Add(new Phrase(Chunk.NEWLINE)); footParagraph.Add(new Phrase(Chunk.NEWLINE)); } var foot = new HeaderFooter(footParagraph, false); foot.Border = Border; _pdfDocument.Footer = foot; logger.LogVerbose(Message.PrintingPdfBuilderEndEvent, "Создание PageFooter"); } try { _pdfDocument.Open(); } catch (Exception ex) { throw new Exception("Ошибка формирования PDF", ex); } if (Headers.ContainsKey(PageSection.Header)) { logger.LogVerbose(Message.PrintingPdfBuilderStartEvent, "Создание Header"); _pdfDocument.Add(MakeParagraph(Headers[PageSection.Header])); logger.LogVerbose(Message.PrintingPdfBuilderEndEvent, "Создание Header"); } if (Data != null) { int dataTablesCount = Data.Tables.Cast <DataTable>().Count(table => !table.TableName.StartsWith("C")); for (int tableIndex = 0; tableIndex < dataTablesCount; tableIndex++) { float tableFactor = (_pdfDocument.Right - _pdfDocument.Left) / 100; string tableName = tableIndex.ToString(); logger.LogVerbose(Message.PrintingPdfBuilderStartEvent, "Создание Таблицы " + tableName); if (Data.Tables.Contains(tableName) && Data.Tables[tableName] != null) { var currentTable = Data.Tables[tableName]; int serviceColumnCount = currentTable.Columns.Cast <DataColumn>().Count( c => c.ColumnName.StartsWith(ServiceTableColumns.SERVICE_COLUMN_PREFIX)); int dataColumns = currentTable.Columns.Count - serviceColumnCount; if (currentTable.Rows.Count > 0) { Table tbl = MakeTable(dataColumns, currentTable.Rows.Count); foreach (DataRow row in currentTable.Rows) { if (((ServiceMode)row[ServiceTableColumns.ServiceMode] & ServiceMode.ResetPageCounter) > 0) { _currentPageNumber = 0; } TableDotted = (bool)row[ServiceTableColumns.IsTableDotted]; if (((ServiceMode)row[ServiceTableColumns.ServiceMode] & ServiceMode.PageBreak) > 0) { if (row == currentTable.Rows.Cast <DataRow>().Last() && !Data.Tables.Contains((tableIndex + 1).ToString())) { continue; } _pdfDocument.Add(tbl); _pdfDocument.NewPage(); tbl = MakeTable(dataColumns, currentTable.Rows.Count); } var colLines = new string[dataColumns]; var colWidths = new float[dataColumns]; var colAligns = new LineAlign?[dataColumns]; int fontSize = _defaultFontSize; bool bold = false; bool italic = false; LineAlign lineAlign = LineAlign.Left; for (int columnIndex = 0; columnIndex < currentTable.Columns.Count; columnIndex++) { switch (currentTable.Columns[columnIndex].ColumnName) { case ServiceTableColumns.FontSize: fontSize = (int)(row.ItemArray[columnIndex]); break; case ServiceTableColumns.IsBold: bold = (bool)(row.ItemArray[columnIndex]); break; case ServiceTableColumns.IsItalic: italic = (bool)(row.ItemArray[columnIndex]); break; case ServiceTableColumns.Align: lineAlign = (LineAlign)(row.ItemArray[columnIndex]); break; default: if (!currentTable.Columns[columnIndex] .ColumnName.StartsWith(ServiceTableColumns.SERVICE_COLUMN_PREFIX)) { colLines[columnIndex] = row.ItemArray[columnIndex].ToString(); if (Data.Tables["C" + tableIndex] != null) { DataRow[] columnProps = Data.Tables["C" + tableIndex] .Select(ServiceTableColumns.Name + " = '" + currentTable.Columns[columnIndex].ColumnName + "'"); if (columnProps.Length > 0) { colWidths[columnIndex] = (int)columnProps[0][ServiceTableColumns.Width]; if (columnProps[0][ServiceTableColumns.Align] != DBNull.Value) { colAligns[columnIndex] = (LineAlign)columnProps[0][ServiceTableColumns.Align]; } } } } break; } } Font tempFont = GetFont(fontSize, bold, italic, baseFont); var cellLeading = (float)Math.Round(tempFont.Size * DBL_LEADING_FONT); tbl.Widths = colWidths; for (int columnIndex = 0; columnIndex < dataColumns; columnIndex++) { float cellWidth = tableFactor * colWidths[columnIndex]; colLines[columnIndex] = TextAlign( colLines[columnIndex], tempFont, colAligns[columnIndex] ?? lineAlign, cellWidth, (row != currentTable.Rows.Cast <DataRow>().First() && TableDotted) ? '.' : ' '); var cell = new Cell(new Phrase(cellLeading, colLines[columnIndex], tempFont)) { Border = Border, Leading = cellLeading, }; tbl.AddCell(cell); } } logger.LogVerbose(Message.PrintingPdfBuilderEndEvent, "Создание Таблицы " + tableName); logger.LogVerbose(Message.PrintingPdfBuilderStartEvent, "Добавление Таблицы " + tableName); _pdfDocument.Add(tbl); logger.LogVerbose(Message.PrintingPdfBuilderEndEvent, "Добавление Таблицы " + tableName); } } } } if (Headers.ContainsKey(PageSection.Footer) && Headers[PageSection.Footer].Count > 0) { logger.LogVerbose(Message.PrintingPdfBuilderStartEvent, "Создание Footer"); _pdfDocument.Add(new Phrase(Chunk.NEWLINE)); _pdfDocument.Add(MakeParagraph(Headers[PageSection.Footer])); logger.LogVerbose(Message.PrintingPdfBuilderEndEvent, "Создание Footer"); } _pdfDocument.Close(); var size = (stream.ToArray().Length / FileUtils.BYTES_IN_KB) + 1; if (!Managers.FileSystemManager.ReserveDiskSpace(filePath, size)) { throw new ApplicationException("Недостаточно места на диске для сохранения отчета"); } File.WriteAllBytes(filePath, stream.ToArray()); SystemHelper.SyncFileSystem(); logger.LogVerbose(Message.Common_DebugReturn); return(new PrinterJob(reportType, filePath, _totalPagesCount, copies)); } catch (Exception ex) { Managers.PrintingManager.Logger.LogError(Message.PrintingPdfBuildFailed, ex); } } return(null); }
public void GenerateXMLReport() { try { this.doc.Open(); RenderLogo(); //RenderHeaderAddress(); RenderReportJobInfo(); RenderProjectsReports(); #region Add Details Table float[] DetailsHeaderwidths = this.Headerwidths; // percentage iTextSharp.text.Table JobDetailstable = new iTextSharp.text.Table(DetailsHeaderwidths.Length); JobDetailstable.Padding = 1; JobDetailstable.DefaultCell.BorderWidth = 1; JobDetailstable.Widths = DetailsHeaderwidths; JobDetailstable.WidthPercentage = 100; JobDetailstable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; JobDetailstable.DefaultCell.BackgroundColor = Color.LIGHT_GRAY; foreach (var x in this.ColList) { JobDetailstable.AddCell(new Phrase(x, fntHeading)); } JobDetailstable.EndHeaders(); Font myDetailFont = fntDetails; foreach (var x in this.ReportRows) { for (int i = 0; i < ColList.Count; i++) { JobDetailstable.DefaultCell.BackgroundColor = Color.WHITE; if (x.row[i].type == CellType.Number) { JobDetailstable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT; } else { JobDetailstable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; } JobDetailstable.AddCell(new Phrase(x.row[i].value, myDetailFont)); } } JobDetailstable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; Cell cell = new Cell(new Paragraph("Total", myDetailFont)); cell.BackgroundColor = Color.LIGHT_GRAY; cell.BorderWidth = 1; cell.Colspan = 3; JobDetailstable.AddCell(cell); JobDetailstable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT; JobDetailstable.DefaultCell.BackgroundColor = Color.LIGHT_GRAY; JobDetailstable.AddCell(new Phrase(this.total, myDetailFont)); doc.Add(JobDetailstable); #endregion } catch (Exception ex) { //MessageBox.Show("Error: " + ex.Message); } doc.Close(); writer.Close(); }
protected void Download_Click(object sender, EventArgs e) { // Check condition if (!GridView1.Columns[GridView1.Columns.Count - 1].Visible) { // Create PDF Document String Path = Server.MapPath("~\\Bangdiem\\DKHP\\DKHP_" + userName + ".pdf"); Document myDocument = new Document(PageSize.A4, 5, 5, 30, 10); if (!File.Exists(Path)) { PdfWriter.GetInstance(myDocument, new FileStream(Path, FileMode.CreateNew)); // Open document myDocument.Open(); BaseFont bf = BaseFont.CreateFont(Server.MapPath(@"~\Font\TIMES.TTF"), BaseFont.IDENTITY_H, true); iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 12); iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(Server.MapPath("~/images/UIT.png")); image.Alignment = iTextSharp.text.Image.UNDERLYING; image.ScaleToFit(30f, 30f); Chunk c1 = new Chunk("TRƯỜNG ĐẠI HỌC CÔNG NGHỆ THÔNG TIN", font); c1.SetUnderline(0.5f, -4f); Paragraph Header = new Paragraph(15); Header.IndentationLeft = 15; Header.Alignment = 3; Header.Font = font; Header.Add(image); Header.SpacingBefore = 5f; Header.Add(" ĐẠI HỌC QUỐC GIA THÀNH PHỐ HỒ CHÍ MINH \n "); Header.Add(c1); Header.Add("\n\n\n"); myDocument.Add(Header); // Add gridview to iTextSharp.text.Table table = new iTextSharp.text.Table(5); // set table style properties table.BorderWidth = 1; table.BorderColor = Color.DARK_GRAY; table.Padding = 4; table.Alignment = 1; table.Width = 90; // set *column* widths float[] widths = { 0.05f, 0.23f, 0.17f, 0.45f, 0.1f }; table.Widths = widths; string[] col = { "TT", "Mã Lớp", "Mã Môn", "Tên Môn Học", "Số TC" }; font = new iTextSharp.text.Font(bf, 13, 1); // create the *table* header row for (int i = 0; i < col.Length; ++i) { Cell cell = new Cell(new Phrase(col[i], font)); cell.Header = true; cell.HorizontalAlignment = 1; table.AddCell(cell); } table.EndHeaders(); int sum = 0; font = new iTextSharp.text.Font(bf, 12); int order = 0; foreach (GridViewRow row in GridView1.Rows) { Cell c = new Cell(new Phrase((++order).ToString(), font)); c.HorizontalAlignment = 1; table.AddCell(c); c = new Cell(new Phrase(row.Cells[1].Text, font)); c.HorizontalAlignment = 1; table.AddCell(c); c = new Cell(new Phrase(((HiddenField)row.FindControl("SubID")).Value, font)); c.HorizontalAlignment = 1; table.AddCell(c); c = new Cell(new Phrase(" " + ((LinkButton)row.FindControl("SubNm")).Text, font)); table.AddCell(c); c = new Cell(new Phrase(row.Cells[3].Text, font)); c.HorizontalAlignment = 1; try { sum += Int16.Parse(row.Cells[3].Text); } catch (Exception ex) { } table.AddCell(c); } font = new iTextSharp.text.Font(bf, 14); Paragraph p = new Paragraph("ĐĂNG KÍ HỌC PHẦN HK " + getTerm() + " " + getYear() + " \n", font); p.Alignment = 1; p.Add("MSSV : " + userName); myDocument.Add(p); font = new iTextSharp.text.Font(bf, 12); c1 = new Chunk("\n\nHọ Tên : ", font); font = new iTextSharp.text.Font(bf, 12, 2); Chunk c2 = new Chunk(((Label)StudentData.Items[0].FindControl("StuNmLB")).Text, font); font = new iTextSharp.text.Font(bf, 12); Chunk c3 = new Chunk(" Khoa : ", font); font = new iTextSharp.text.Font(bf, 12, 2); Chunk c4 = new Chunk(((Label)StudentData.Items[0].FindControl("DeptLB")).Text, font); Paragraph p2 = new Paragraph(); p2.IndentationLeft = 30f; p2.Alignment = 3; p2.Add(c1); p2.Add(c2); p2.Add(c3); p2.Add(c4); myDocument.Add(p2); // Add Gridview myDocument.Add(table); if (sum > 25) { myDocument.Close(); if (File.Exists(Path)) try { File.Delete(Path); } catch (Exception ex) { } return; } font = new iTextSharp.text.Font(bf, 12); p = new Paragraph(String.Format("Tổng số TC : {0} ", sum.ToString()), font); p.Alignment = 2; myDocument.Add(p); // Add sign font = new iTextSharp.text.Font(bf, 13); p = new Paragraph("\n\n\n Chữ ký SV", font); p.Add(" Chữ ký PĐT\n\n"); p.Add(" ......................."); p.Add(" ........................\n"); myDocument.Add(p); // Check List<string> DateL = new List<string>(); List<string> Derror = new List<string>(); String error = ""; bool first = true; foreach (GridViewRow grow in GridView1.Rows) { string Date = ((Label)grow.FindControl("Day")).Text; string Period = ((Label)grow.FindControl("Period")).Text; string[] dates = Date.Replace("<br/>", ",").Split(','); string[] periods = Period.Replace("<br/>", ",").Split(','); for (int i = 0; i < dates.Length; i++) { string dateandperiod = dates[i] + periods[i]; if (DateL.Contains(dateandperiod)) // Error on samq datetime { if (!Derror.Contains(dateandperiod)) { if (first) { error += "Thứ " + dates[i] + " ca " + periods[i]; first = false; } else error += ", Thứ " + dates[i] + " ca " + periods[i]; Derror.Add(dateandperiod); } } else DateL.Add(dateandperiod); } } if (error != "") { font = new iTextSharp.text.Font(bf, 12); p = new Paragraph("\n\n Ghi chú : trùng giờ học ", font); p.Add("\n (" + error + ")"); myDocument.Add(p); } font = new iTextSharp.text.Font(bf, 11); p = new Paragraph("\n In vào :" + DateTime.UtcNow.ToShortTimeString() + " " + DateTime.UtcNow.ToShortDateString(), font); p.Add("\n Chú ý : Sinh viên \n không được tự ý thay đổi nội dung file này."); myDocument.Add(p); // Close document myDocument.Close(); // Check connection and trangfer file using (SqlConnection scon = new SqlConnection(ConnectionString)) { scon.Open(); using (SqlCommand scom = new SqlCommand("Insert into DownloadLog values(@StuID,getdate())", scon)) { scom.Parameters.Add("@StuID", userName); try { scom.ExecuteNonQuery(); } catch (Exception ex) { using (SqlCommand scom1 = new SqlCommand("Update Downloadlog set log = getdate() where StuID = @StuID", scon)) { try { scom1.Parameters.Add("@StuID", userName); scom1.ExecuteNonQuery(); } catch (Exception ex1) { } } } } } } Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "application/pdf"; Response.AddHeader ("Content-Disposition", "attachment; filename = DKHP_" + userName + ".pdf"); Response.TransmitFile(Path); Response.End(); Response.Flush(); Response.Clear(); } }
public static void PYU960326AG7(Document document, ElectronicDocument electronicDocument, Data objTimbre, pdfPageEventHandlerPfizer pageEventHandler, DataTable dtEncabezado, DataTable dtDetalle, Hashtable htCFDI, HttpContext hc) { try { //DAL dal = new DAL(); #region "Construimos el Documento" #region "Construimos el Encabezado" Table encabezado = new Table(7); float[] headerwidthsEncabezado = { 9, 18, 28, 28, 5, 7, 5 }; encabezado.Widths = headerwidthsEncabezado; encabezado.WidthPercentage = 100; encabezado.Padding = 1; encabezado.Spacing = 1; encabezado.BorderWidth = 0; encabezado.DefaultCellBorder = 0; encabezado.BorderColor = gris; Image imgLogo = Image.GetInstance(pathIMGLOGO); imgLogo.ScalePercent(47f); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(1f, 1f); par.Add(new Chunk(imgLogo, 0, 0)); par.Add(new Chunk("", f6)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 5; cel.Colspan = 2; encabezado.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(8f, 9f); par.Add(new Chunk(htCFDI["nombreEmisor"].ToString().ToUpper(), f6B)); par.Add(new Chunk("\nRFC " + htCFDI["rfcEmisor"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor1"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor2"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor3"].ToString().ToUpper(), f6)); par.Add(new Chunk("\nTel. (52) 55 5081-8500", f6)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 5; encabezado.AddCell(cel); StringBuilder expedido = new StringBuilder(); expedido. Append("Lugar de Expedición México DF\n"). Append(htCFDI["sucursal"]).Append("\n"). Append(htCFDI["direccionExpedido1"].ToString().ToUpper()).Append("\n"). Append(htCFDI["direccionExpedido2"].ToString().ToUpper()).Append("\n"). Append(htCFDI["direccionExpedido3"].ToString().ToUpper()).Append("\n"); cel = new Cell(new Phrase(expedido.ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.Rowspan = 4; encabezado.AddCell(cel); cel = new Cell(new Phrase(htCFDI["tipoDoc"].ToString(), titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase(htCFDI["serie"].ToString().ToUpper() + electronicDocument.Data.Folio.Value, f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase("Día", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("Mes", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("Año", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); string[] fechaCFDI = Convert.ToDateTime(htCFDI["fechaCfdi"].ToString()).GetDateTimeFormats(); string HORAS = fechaCFDI[103]; string DIA = Convert.ToDateTime(htCFDI["fechaCfdi"]).Day.ToString(); string MES = Convert.ToDateTime(htCFDI["fechaCfdi"]).ToString("MMMM").ToUpper(); string ANIO = Convert.ToDateTime(htCFDI["fechaCfdi"]).Year.ToString(); cel = new Cell(new Phrase(DIA, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(MES, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(ANIO, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezado.AddCell(cel); //cel = new Cell(new Phrase("No. y Año de Aprobación: " + dtEncabezado.Rows[0]["NoAp"].ToString() + " " + dtEncabezado.Rows[0]["AnoAp"].ToString(), f6)); cel = new Cell(new Phrase("", f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); //cel = new Cell(new Phrase(HORAS, f6)); cel = new Cell(new Phrase("", f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase("CLIENTE", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BackgroundColor = azul; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; encabezado.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Receptor.Nombre.Value, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase("Termino Pago: " + electronicDocument.Data.CondicionesPago.Value, f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 1f); par.Add(new Chunk("R.F.C. " + electronicDocument.Data.Receptor.Rfc.Value + "\n", f5)); par.Add(new Chunk(htCFDI["direccionReceptor1"] + "\n", f5)); par.Add(new Chunk(htCFDI["direccionReceptor2"] + "\n", f5)); par.Add(new Chunk(htCFDI["direccionReceptor3"] + "\n", f5)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; cel.Rowspan = 5; cel.Colspan = 2; encabezado.AddCell(cel); #region "Consignado a" string nombreEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-NOMBRE"].ToString();//CE string calleEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-CALLE"].ToString();//CE 10, 11, 12 string coloniaEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-COLONIA"].ToString();//CE13 string cpEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-CP"].ToString();//CE18 string municEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-MUNIC"].ToString();//CE15 string estadoEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-ESTADO"].ToString();//CE16 string paisEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-PAIS"].ToString();//CE17 string localidadEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-LOCAL"].ToString();//CE14 string saltoEntregado = "\n"; string separador = ", "; string espacio = " "; if (nombreEntregado.Length > 0) nombreEntregado = nombreEntregado + saltoEntregado; else nombreEntregado = "" + saltoEntregado; if (calleEntregado.Length > 0) calleEntregado = calleEntregado + saltoEntregado; else calleEntregado = "" + saltoEntregado; if (coloniaEntregado.Length > 0) coloniaEntregado = coloniaEntregado + espacio; else coloniaEntregado = "" + espacio; if (cpEntregado.Length > 0) cpEntregado = ", CP " + cpEntregado + saltoEntregado; else cpEntregado = "" + separador + saltoEntregado; if (municEntregado.Length > 0) municEntregado = municEntregado + separador; else municEntregado = ""; if (localidadEntregado.Length > 0) localidadEntregado = localidadEntregado + saltoEntregado; else localidadEntregado = "" + saltoEntregado; if (estadoEntregado.Length > 0) estadoEntregado = estadoEntregado + espacio; else estadoEntregado = "" + espacio; if (paisEntregado.Length > 0) paisEntregado = paisEntregado + ""; else paisEntregado = ""; #endregion par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 1f); par.Add(new Chunk("Consignado a:\n", f5B)); par.Add(new Chunk(calleEntregado, f5)); par.Add(new Chunk(coloniaEntregado, f5)); par.Add(new Chunk(cpEntregado, f5)); par.Add(new Chunk(municEntregado, f5)); par.Add(new Chunk(localidadEntregado, f5)); par.Add(new Chunk(estadoEntregado, f5)); par.Add(new Chunk(paisEntregado, f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Rowspan = 5; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Cliente No:\n", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["clienteNo"].ToString(), f5)); par.Add(new Chunk("\nContacto:\n", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["contacto"].ToString(), f5)); par.Add(new Chunk("\nTeléfono:\n", f5B)); par.Add(new Chunk("" + "\n", f5)); //if (htCFDI["serie"].ToString() == "C" || htCFDI["serie"].ToString() == "D") //{ // par.Add(new Chunk("Zona:\n", f5B)); // par.Add(new Chunk(dtEncabezado.Rows[0]["zona"].ToString(), f5)); //} cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 5; encabezado.AddCell(cel); //if (htCFDI["serie"].ToString() == "C") //{ // par = new Paragraph(); // par.SetLeading(7f, 1f); // par.Add(new Chunk("Vencimiento: ", f5B)); // par.Add(new Chunk(dtEncabezado.Rows[0]["vencimiento"].ToString(), f5B)); //CE27 // cel = new Cell(par); // cel.VerticalAlignment = Element.ALIGN_MIDDLE; // cel.HorizontalAlignment = Element.ALIGN_CENTER; // cel.BorderWidthTop = 0; // cel.BorderWidthLeft = 0; // cel.BorderWidthRight = (float).5; // cel.BorderWidthBottom = (float).5; // cel.BorderColor = gris; // cel.Colspan = 3; // encabezado.AddCell(cel); //} par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Vencimiento: ", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["vencimiento"].ToString(), f5B)); //CE27 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Moneda: ", f5B)); par.Add(new Chunk(electronicDocument.Data.Moneda.Value, f5)); cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); //if (htCFDI["serie"].ToString() == "D" || htCFDI["serie"].ToString() == "L" || htCFDI["serie"].ToString() == "N") // par.Add(new Chunk("Referencia: ", f5B)); //else // par.Add(new Chunk("Orden Compra: ", f5B)); par.Add(new Chunk("Orden Compra: ", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["referencia"].ToString(), f5));//CE33 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); //if (htCFDI["serie"].ToString() == "N") //{ // par = new Paragraph(); // par.SetLeading(7f, 1f); // par.Add(new Chunk("Fecha Referencia: ", f5B)); // par.Add(new Chunk(dtEncabezado.Rows[0]["fechaRefDoc"].ToString(), f5));//CE34 // cel = new Cell(par); // cel.VerticalAlignment = Element.ALIGN_MIDDLE; // cel.HorizontalAlignment = Element.ALIGN_CENTER; // cel.BorderWidthTop = 0; // cel.BorderWidthLeft = 0; // cel.BorderWidthRight = (float).5; // cel.BorderWidthBottom = 0; // cel.BorderColor = gris; // cel.Colspan = 3; // encabezado.AddCell(cel); //} par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Pedido: ", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["pedido"].ToString(), f5));//CE19 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("División: ", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["division"].ToString(), f5));//CE20 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); #endregion #region "Construimos Tablas de Partidas" #region "Construimos Encabezados de Partidas" Table encabezadoPartidas = new Table(7); float[] headerwidthsEncabesadoPartidas = { 5, 10, 10, 40, 11, 12, 12 }; encabezadoPartidas.Widths = headerwidthsEncabesadoPartidas; encabezadoPartidas.WidthPercentage = 100; encabezadoPartidas.Padding = 1; encabezadoPartidas.Spacing = 1; encabezadoPartidas.BorderWidth = (float).5; encabezadoPartidas.DefaultCellBorder = 1; encabezadoPartidas.BorderColor = gris; cel = new Cell(new Phrase("No.", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Código", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Descripción", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; cel.Colspan = 2; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Cantidad", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Precio Unitario", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Importe", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); #endregion #region "Construimos Contenido de las Partidas" Table partidas = new Table(7); float[] headerwidthsPartidas = { 5, 10, 10, 40, 11, 12, 12 }; partidas.Widths = headerwidthsPartidas; partidas.WidthPercentage = 100; partidas.Padding = 1; partidas.Spacing = 1; partidas.BorderWidth = 0; partidas.DefaultCellBorder = 0; partidas.BorderColor = gris; if (dtEncabezado.Rows.Count > 0) { for (int i = 0; i < electronicDocument.Data.Conceptos.Count; i++) { cel = new Cell(new Phrase((i + 1).ToString(), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 2; partidas.AddCell(cel); cel = new Cell(new Phrase(dtDetalle.Rows[i]["codeLocal"].ToString(), f5));//CD1 cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 2; partidas.AddCell(cel); #region "Descripción" cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Descripcion.Value, f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; partidas.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Cantidad.Value + " " + electronicDocument.Data.Conceptos[i].Unidad.Value, f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 2; partidas.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].ValorUnitario.Value.ToString("C", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 2; partidas.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Importe.Value.ToString("C", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 2; partidas.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Lote\n", f5L)); par.Add(new Chunk(dtDetalle.Rows[i]["lote"].ToString().Replace("*", "\n"), f5));//CD3 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; partidas.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Cantidad\n", f5L)); par.Add(new Chunk(dtDetalle.Rows[i]["cantidad"].ToString().Replace("*", "\n"), f5));//CD4 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; partidas.AddCell(cel); #endregion } } #endregion #endregion #region "Construimos el Comentarios" Table comentarios = new Table(7); float[] headerwidthsComentarios = { 9, 18, 28, 28, 7, 5, 5 }; comentarios.Widths = headerwidthsComentarios; comentarios.WidthPercentage = 100; comentarios.Padding = 1; comentarios.Spacing = 1; comentarios.BorderWidth = 0; comentarios.DefaultCellBorder = 0; comentarios.BorderColor = gris; cel = new Cell(new Phrase("Cantidad:", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 3; comentarios.AddCell(cel); cel = new Cell(new Phrase(dtEncabezado.Rows[0]["cantidadLetra"].ToString(), f5));//CE26 cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; cel.Rowspan = 3; comentarios.AddCell(cel); cel = new Cell(new Phrase("Sub Total", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.SubTotal.Value.ToString("C", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); double importe = 0; double tasa = 0; for (int i = 0; i < electronicDocument.Data.Impuestos.Traslados.Count; i++) { if (electronicDocument.Data.Impuestos.Traslados[i].Tipo.Value == "IVA") { importe = electronicDocument.Data.Impuestos.Traslados[i].Importe.Value; tasa = electronicDocument.Data.Impuestos.Traslados[i].Tasa.Value; break; } } cel = new Cell(new Phrase("IVA " + tasa + " %", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.TotalTraslados.Value.ToString("C", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Total", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Total.Value.ToString("C", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Observaciones:", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Rowspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase(dtEncabezado.Rows[0]["observaciones"].ToString(), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; cel.Rowspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Descuento Pronto Pago", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Descuento.Value.ToString("C", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Importe Pago Neto", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Descuento.Value.ToString("C", _ci), f5));//Duda cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.FormaPago.Value.ToUpper(), f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 7; comentarios.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 7; comentarios.AddCell(cel); #endregion #region "Construimos Tabla de Datos CFDI" DefaultSplitCharacter split = new DefaultSplitCharacter(); Table adicional = new Table(3); float[] headerwidthsAdicional = { 20, 25, 55 }; adicional.Widths = headerwidthsAdicional; adicional.WidthPercentage = 100; adicional.Padding = 1; adicional.Spacing = 1; adicional.BorderWidth = (float).5; adicional.DefaultCellBorder = 1; adicional.BorderColor = gris; if (timbrar) { #region "Generamos Quick Response Code" byte[] bytesQRCode = new byte[0]; if (timbrar) { // Generamos el Quick Response Code (QRCode) string re = electronicDocument.Data.Emisor.Rfc.Value; string rr = electronicDocument.Data.Receptor.Rfc.Value; string tt = String.Format("{0:F6}", electronicDocument.Data.Total.Value); string id = objTimbre.Uuid.Value; StringBuilder sbCadenaQRCode = new StringBuilder(); sbCadenaQRCode. Append("?"). Append("re=").Append(re). Append("&"). Append("rr=").Append(rr). Append("&"). Append("tt=").Append(tt). Append("&"). Append("id=").Append(id); BarcodeLib.Barcode.QRCode.QRCode barcode = new BarcodeLib.Barcode.QRCode.QRCode(); barcode.Data = sbCadenaQRCode.ToString(); barcode.ModuleSize = 3; barcode.LeftMargin = 0; barcode.RightMargin = 10; barcode.TopMargin = 0; barcode.BottomMargin = 0; barcode.Encoding = BarcodeLib.Barcode.QRCode.QRCodeEncoding.Auto; barcode.Version = BarcodeLib.Barcode.QRCode.QRCodeVersion.Auto; barcode.ECL = BarcodeLib.Barcode.QRCode.ErrorCorrectionLevel.L; bytesQRCode = barcode.drawBarcodeAsBytes(); } #endregion Image imageQRCode = Image.GetInstance(bytesQRCode); imageQRCode.Alignment = (Image.TEXTWRAP | Image.ALIGN_LEFT); imageQRCode.ScaleToFit(90f, 90f); imageQRCode.IndentationLeft = 9f; imageQRCode.SpacingAfter = 9f; imageQRCode.BorderColorTop = Color.WHITE; cel = new Cell(imageQRCode); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 6; adicional.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("SELLO DIGITAL DEL EMISOR\n", f5L)); par.Add(new Chunk(electronicDocument.Data.Sello.Value, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Colspan = 2; adicional.AddCell(cel); cel = new Cell(new Phrase("FOLIO FISCAL:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase(objTimbre.Uuid.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("FECHA Y HORA DE CERTIFICACION:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); string[] fechaTimbrado = Convert.ToDateTime(objTimbre.FechaTimbrado.Value).GetDateTimeFormats('s'); cel = new Cell(new Phrase(fechaTimbrado[0], f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL SAT:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase(objTimbre.NumeroCertificadoSat.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL EMISOR:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; adicional.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.NumeroCertificado.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = (float).5; adicional.AddCell(cel); string lbRegimen = "REGIMEN FISCAL APLICABLE: "; StringBuilder regimenes = new StringBuilder(); if (electronicDocument.Data.Emisor.Regimenes.IsAssigned) { for (int i = 0; i < electronicDocument.Data.Emisor.Regimenes.Count; i++) { regimenes.Append(electronicDocument.Data.Emisor.Regimenes[i].Regimen.Value).Append("\n"); } } else { regimenes.Append(""); lbRegimen = ""; } string cuenta = electronicDocument.Data.NumeroCuentaPago.IsAssigned ? electronicDocument.Data.NumeroCuentaPago.Value : ""; par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("TIPO DE COMPROBANTE: ", f5L)); par.Add(new Chunk(electronicDocument.Data.TipoComprobante.Value + " | ", f5)); par.Add(new Chunk("Moneda: ", f5L)); par.Add(new Chunk(electronicDocument.Data.Moneda.Value + " | ", f5)); par.Add(new Chunk("TASA DE CAMBIO: ", f5L)); string tasaCambio = electronicDocument.Data.TipoCambio.Value; if (tasaCambio.Length > 0) { par.Add(new Chunk(Convert.ToDouble(tasaCambio).ToString("C", _ci) + " | ", f5)); } else { par.Add(new Chunk(" | ", f5)); } par.Add(new Chunk("FORMA DE PAGO: ", f5L)); par.Add(new Chunk(electronicDocument.Data.FormaPago.Value + "\n", f5)); par.Add(new Chunk("MÉTODO DE PAGO: ", f5L)); par.Add(new Chunk(electronicDocument.Data.MetodoPago.Value + " | ", f5)); par.Add(new Chunk("NÚMERO DE CUENTA: ", f5L)); par.Add(new Chunk(cuenta + " | ", f5)); par.Add(new Chunk(lbRegimen, f5L)); par.Add(new Chunk(regimenes.ToString(), f5)); cel.BorderColor = gris; cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; cel.BorderColor = gris; adicional.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("CADENA ORIGINAL DEL COMPLEMENTO DE CERTIFICACIÓN DIGITAL DEL SAT\n", f5L)); par.Add(new Chunk(electronicDocument.FingerPrintPac, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Colspan = 3; adicional.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 0f); par.Add(new Chunk("SELLO DIGITAL DEL SAT\n", f5L)); par.Add(new Chunk(objTimbre.SelloSat.Value, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 3; adicional.AddCell(cel); } #endregion #region "Construimos Tabla Adicional Datos de Pago" Table pago = new Table(5); float[] headerwidthsPago = { 40, 10, 20, 10, 20 }; pago.Widths = headerwidthsPago; pago.WidthPercentage = 100; pago.Padding = 1; pago.Spacing = 1; pago.BorderWidth = (float).5; pago.DefaultCellBorder = 1; pago.BorderColor = gris; cel = new Cell(new Phrase("Para ejecutar su pago para consultas", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Para efectuar su pago", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; pago.AddCell(cel); cel = new Cell(new Phrase("Información del Cliente", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; pago.AddCell(cel); string[] ejecutarPago = dtEncabezado.Rows[0]["paraConsultas"].ToString().Split(new Char[] { '*' });//CE23 string[] pagoDatos = dtEncabezado.Rows[0]["efectuarPago"].ToString().Split(new Char[] { '*' });//CE21 par = new Paragraph(); par.SetLeading(7f, 0f); if (ejecutarPago.Length > 0) par.Add(new Chunk(ejecutarPago[0] + "\n", f5)); else par.Add(new Chunk("\n", f5)); if (ejecutarPago.Length > 1) par.Add(new Chunk(ejecutarPago[1] + "\n", f5)); else par.Add(new Chunk("\n", f5)); if (ejecutarPago.Length > 2) par.Add(new Chunk(ejecutarPago[2] + "\n", f5)); else par.Add(new Chunk("\n", f5)); if (ejecutarPago.Length > 3) par.Add(new Chunk(ejecutarPago[3] + "\n", f5)); else par.Add(new Chunk("\n", f5)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Rowspan = 6; pago.AddCell(cel); cel = new Cell(new Phrase("Banco:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); if (pagoDatos.Length > 0) par.Add(new Chunk(pagoDatos[0], f5)); else par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Cliente:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Receptor.Nombre.Value, f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Cuenta:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); if (pagoDatos.Length > 1) par.Add(new Chunk(pagoDatos[1], f5)); else par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("No. Cliente:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase(dtEncabezado.Rows[0]["clienteNo"].ToString(), f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); //if (htCFDI["serie"].ToString() == "B" || htCFDI["serie"].ToString() == "D" || htCFDI["serie"].ToString() == "J" || htCFDI["serie"].ToString() == "L" || htCFDI["serie"].ToString() == "N") //{ // cel = new Cell(new Phrase("", f5)); // cel.BorderWidthTop = 0; // cel.BorderWidthRight = 0; // cel.BorderWidthLeft = 0; // cel.BorderWidthBottom = 0; // cel.Colspan = 2; // pago.AddCell(cel); //} //else //{ // cel = new Cell(new Phrase("SWIFT:", f5L)); // cel.HorizontalAlignment = Element.ALIGN_RIGHT; // cel.BorderWidthTop = 0; // cel.BorderWidthRight = 0; // cel.BorderWidthLeft = 0; // cel.BorderWidthBottom = 0; // pago.AddCell(cel); // cel = new Cell(new Phrase(pagoDatos[3], f5)); // cel.BorderWidthTop = 0; // cel.BorderWidthRight = 0; // cel.BorderWidthLeft = 0; // cel.BorderWidthBottom = 0; // pago.AddCell(cel); //} cel = new Cell(new Phrase("", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Factura No:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase(htCFDI["serie"].ToString().ToUpper() + "-" + electronicDocument.Data.Folio.Value.ToString(), f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Moneda:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); if (pagoDatos.Length > 4) par.Add(new Chunk(pagoDatos[4], f5)); else par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Fecha Factura", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); string[] fechaFactura = Convert.ToDateTime(objTimbre.FechaTimbrado.Value).GetDateTimeFormats('s'); cel = new Cell(new Phrase(DIA + "/" + MES + "/" + ANIO, f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Beneficiario:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); if (pagoDatos.Length > 5) par.Add(new Chunk(pagoDatos[5], f5)); else par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Valor Total:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Total.Value.ToString("C", _ci), f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; pago.AddCell(cel); cel = new Cell(new Phrase("Dirección:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; pago.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); if (pagoDatos.Length > 4) par.Add(new Chunk(dtEncabezado.Rows[0]["direccionPie"].ToString(), f5));//CE22 else par.Add(new Chunk("", f5)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; pago.AddCell(cel); //if (htCFDI["serie"].ToString() == "C") //{ // cel = new Cell(new Phrase("Fecha Vencimiento:", f5L)); // cel.HorizontalAlignment = Element.ALIGN_RIGHT; // cel.BorderColor = gris; // cel.BorderWidthTop = 0; // cel.BorderWidthRight = 0; // cel.BorderWidthLeft = 0; // cel.BorderWidthBottom = (float).5; // pago.AddCell(cel); // cel = new Cell(new Phrase(dtEncabezado.Rows[0]["vencimiento"].ToString(), f5B)); // cel.BorderWidthTop = 0; // cel.BorderWidthRight = 0; // cel.BorderWidthLeft = 0; // cel.BorderWidthBottom = (float).5; // cel.BorderColor = gris; // pago.AddCell(cel); //} //else //{ // cel = new Cell(new Phrase("Moneda:", f5L)); // cel.HorizontalAlignment = Element.ALIGN_RIGHT; // cel.BorderColor = gris; // cel.BorderWidthTop = 0; // cel.BorderWidthRight = 0; // cel.BorderWidthLeft = 0; // cel.BorderWidthBottom = (float).5; // pago.AddCell(cel); // cel = new Cell(new Phrase(electronicDocument.Data.Moneda.Value, f5)); // cel.BorderWidthTop = 0; // cel.BorderWidthRight = 0; // cel.BorderWidthLeft = 0; // cel.BorderWidthBottom = (float).5; // cel.BorderColor = gris; // pago.AddCell(cel); //} cel = new Cell(new Phrase("Moneda:", f5L)); cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; pago.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Moneda.Value, f5)); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; pago.AddCell(cel); #endregion #region "Construimos Tabla del Footer" PdfPTable footer = new PdfPTable(1); footer.WidthPercentage = 100; footer.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; cell = new PdfPCell(new Phrase("", f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.BorderWidthBottom = 0; footer.AddCell(cell); cell = new PdfPCell(new Phrase("ESTE DOCUMENTO ES UNA REPRESENTACIÓN IMPRESA DE UN CFDI", titulo)); cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = azul; cell.BorderWidthTop = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.BorderWidthBottom = 0; footer.AddCell(cell); #endregion pageEventHandler.encabezado = encabezado; pageEventHandler.encPartidas = encabezadoPartidas; pageEventHandler.footer = footer; document.Open(); document.Add(partidas); document.Add(comentarios); document.Add(adicional); document.Add(pago); #endregion } catch (Exception ex) { string exe = ex.Message; } }
private void ExportCSRCtoPDF(int id) { oVariables = new Variables(intEnvironment); Document doc = new Document(); Cell cell; iTextSharp.text.Table oTable = new iTextSharp.text.Table(2); oTable.BorderWidth = 0; oTable.BorderColor = new iTextSharp.text.Color(255, 255, 255); oTable.Padding = 2; oTable.Width = 100; iTextSharp.text.Font oFontHeader = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 10, 1); iTextSharp.text.Font oFontBold = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 8, 1); iTextSharp.text.Font oFont = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 8, 0); ds = oTPM.GetCSRC(id); int intRequest = Int32.Parse(ds.Tables[0].Rows[0]["requestid"].ToString()); int intItem = Int32.Parse(ds.Tables[0].Rows[0]["itemid"].ToString()); int intNumber = Int32.Parse(ds.Tables[0].Rows[0]["number"].ToString()); DataSet dsResource = oCustomized.GetTPM(intRequest, intItem, intNumber); string strFile = DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + "_" + intProfile.ToString() + ".pdf"; string strPath = oVariables.UploadsFolder() + strFile; string strVirtualPath = oVariables.UploadsFolder() + strFile; FileStream fs = new FileStream(strPath, FileMode.Create); PdfWriter.GetInstance(doc, fs); // PdfWriter.GetInstance(doc, Response.OutputStream); string strHeader = "ClearView CSRC Information"; HeaderFooter header = new HeaderFooter(new Phrase(strHeader, new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 6)), false); header.Border = iTextSharp.text.Rectangle.NO_BORDER; header.Alignment = 2; doc.Header = header; string strFooter = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(); HeaderFooter footer = new HeaderFooter(new Phrase(strFooter, new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 6)), false); footer.Border = iTextSharp.text.Rectangle.NO_BORDER; footer.Alignment = 2; doc.Footer = footer; doc.Open(); cell = new Cell(new Phrase("Project Capital Service Review Committee Report", oFontHeader)); cell.Colspan = 2; cell.BackgroundColor = new iTextSharp.text.Color(169, 162, 141); oTable.AddCell(cell); cell = new Cell(new Phrase("PMM Phase", oFontBold)); cell.Colspan = 2; oTable.AddCell(cell); oTable.AddCell(new Cell(new Phrase("Discovery", oFont))); oTable.AddCell(new Cell(new Phrase((ds.Tables[0].Rows[0]["d"].ToString() == "1" ? "Yes" : "No"), oFont))); oTable.AddCell(new Cell(new Phrase("Planning", oFont))); oTable.AddCell(new Cell(new Phrase((ds.Tables[0].Rows[0]["p"].ToString() == "1" ? "Yes" : "No"), oFont))); oTable.AddCell(new Cell(new Phrase("Execution", oFont))); oTable.AddCell(new Cell(new Phrase((ds.Tables[0].Rows[0]["e"].ToString() == "1" ? "Yes" : "No"), oFont))); oTable.AddCell(new Cell(new Phrase("Closing", oFont))); oTable.AddCell(new Cell(new Phrase((ds.Tables[0].Rows[0]["c"].ToString() == "1" ? "Yes" : "No"), oFont))); cell = new Cell(new Phrase("Discovery", oFontBold)); cell.Colspan = 2; oTable.AddCell(cell); oTable.AddCell(new Cell(new Phrase("Phase start date", oFont))); if (ds.Tables[0].Rows[0]["ds"] == DBNull.Value) { oTable.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable.AddCell(new Cell(new Phrase(GetDate(ds.Tables[0].Rows[0]["ds"].ToString()), oFont))); } oTable.AddCell(new Cell(new Phrase("Phase end date", oFont))); if (ds.Tables[0].Rows[0]["de"] == DBNull.Value) { oTable.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable.AddCell(new Cell(new Phrase(GetDate(ds.Tables[0].Rows[0]["de"].ToString()), oFont))); } oTable.AddCell(new Cell(new Phrase("Internal Labor", oFont))); if (ds.Tables[0].Rows[0]["di"] == DBNull.Value) { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(ds.Tables[0].Rows[0]["di"].ToString()).ToString("F"), oFont))); } oTable.AddCell(new Cell(new Phrase("External Labor", oFont))); if (ds.Tables[0].Rows[0]["dex"] == DBNull.Value) { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(ds.Tables[0].Rows[0]["dex"].ToString()).ToString("F"), oFont))); } oTable.AddCell(new Cell(new Phrase("HW/SW/One Time Cost", oFont))); if (ds.Tables[0].Rows[0]["dh"] == DBNull.Value) { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(ds.Tables[0].Rows[0]["dh"].ToString()).ToString("F"), oFont))); } cell = new Cell(new Phrase("Planning", oFontBold)); cell.Colspan = 2; oTable.AddCell(cell); oTable.AddCell(new Cell(new Phrase("Phase start date", oFont))); if (ds.Tables[0].Rows[0]["ps"] == DBNull.Value) { oTable.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable.AddCell(new Cell(new Phrase(GetDate(ds.Tables[0].Rows[0]["ps"].ToString()), oFont))); } oTable.AddCell(new Cell(new Phrase("Phase end date", oFont))); if (ds.Tables[0].Rows[0]["pe"] == DBNull.Value) { oTable.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable.AddCell(new Cell(new Phrase(GetDate(ds.Tables[0].Rows[0]["pe"].ToString()), oFont))); } oTable.AddCell(new Cell(new Phrase("Internal Labor", oFont))); if (ds.Tables[0].Rows[0]["pi"] == DBNull.Value) { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(ds.Tables[0].Rows[0]["pi"].ToString()).ToString("F"), oFont))); } oTable.AddCell(new Cell(new Phrase("External Labor", oFont))); if (ds.Tables[0].Rows[0]["pex"] == DBNull.Value) { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(ds.Tables[0].Rows[0]["pex"].ToString()).ToString("F"), oFont))); } oTable.AddCell(new Cell(new Phrase("HW/SW/One Time Cost", oFont))); if (ds.Tables[0].Rows[0]["ph"] == DBNull.Value) { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(ds.Tables[0].Rows[0]["ph"].ToString()).ToString("F"), oFont))); } cell = new Cell(new Phrase("Execution", oFontBold)); cell.Colspan = 2; oTable.AddCell(cell); oTable.AddCell(new Cell(new Phrase("Phase start date", oFont))); if (ds.Tables[0].Rows[0]["es"] == DBNull.Value) { oTable.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable.AddCell(new Cell(new Phrase(GetDate(ds.Tables[0].Rows[0]["es"].ToString()), oFont))); } oTable.AddCell(new Cell(new Phrase("Phase end date", oFont))); if (ds.Tables[0].Rows[0]["ee"] == DBNull.Value) { oTable.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable.AddCell(new Cell(new Phrase(GetDate(ds.Tables[0].Rows[0]["ee"].ToString()), oFont))); } oTable.AddCell(new Cell(new Phrase("Internal Labor", oFont))); if (ds.Tables[0].Rows[0]["ei"] == DBNull.Value) { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(ds.Tables[0].Rows[0]["ei"].ToString()).ToString("F"), oFont))); } oTable.AddCell(new Cell(new Phrase("External Labor", oFont))); if (ds.Tables[0].Rows[0]["eex"] == DBNull.Value) { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(ds.Tables[0].Rows[0]["eex"].ToString()).ToString("F"), oFont))); } oTable.AddCell(new Cell(new Phrase("HW/SW/One Time Cost", oFont))); if (ds.Tables[0].Rows[0]["eh"] == DBNull.Value) { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(ds.Tables[0].Rows[0]["eh"].ToString()).ToString("F"), oFont))); } cell = new Cell(new Phrase("Closing", oFontBold)); cell.Colspan = 2; oTable.AddCell(cell); oTable.AddCell(new Cell(new Phrase("Phase start date", oFont))); if (ds.Tables[0].Rows[0]["cs"] == DBNull.Value) { oTable.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable.AddCell(new Cell(new Phrase(GetDate(ds.Tables[0].Rows[0]["cs"].ToString()), oFont))); } oTable.AddCell(new Cell(new Phrase("Phase end date", oFont))); if (ds.Tables[0].Rows[0]["ce"] == DBNull.Value) { oTable.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable.AddCell(new Cell(new Phrase(GetDate(ds.Tables[0].Rows[0]["ce"].ToString()), oFont))); } oTable.AddCell(new Cell(new Phrase("Internal Labor", oFont))); if (ds.Tables[0].Rows[0]["ci"] == DBNull.Value) { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(ds.Tables[0].Rows[0]["ci"].ToString()).ToString("F"), oFont))); } oTable.AddCell(new Cell(new Phrase("External Labor", oFont))); if (ds.Tables[0].Rows[0]["cex"] == DBNull.Value) { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(ds.Tables[0].Rows[0]["cex"].ToString()).ToString("F"), oFont))); } oTable.AddCell(new Cell(new Phrase("HW/SW/One Time Cost", oFont))); if (ds.Tables[0].Rows[0]["ch"] == DBNull.Value) { oTable.AddCell(new Cell(new Phrase("$0.0", oFont))); } else { oTable.AddCell(new Cell(new Phrase("$" + GetFloat(ds.Tables[0].Rows[0]["ch"].ToString()).ToString("F"), oFont))); } doc.Add(oTable); doc.Close(); fs.Close(); string strURL = oVariables.UploadsFolder() + strFile; oTPM.UpdateCSRCPath(id, oVariables.UploadsFolder() + strFile); strAttachement += "<tr><td><a href=\"" + strURL + "\" target=\"_blank\"><img src=\"/images/icons/pdf.gif \" align=\"absmiddle\" border=\"0\" /> View PCR Document (" + ds.Tables[0].Rows[0]["name"] + ")</a></td></tr> "; //Response.ContentType = "application/pdf"; //Response.AddHeader("Content-Disposition", "attachment; filename=closure_form.pdf"); //Response.End(); //Response.Flush(); }
public void OnStartPage(PdfWriter writer, Document document) { var pessoaJuridica = empresa.Pessoa as IPessoaJuridica; Chunk imagem; if (!string.IsNullOrEmpty(pessoaJuridica.Logomarca)) { var imghead = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath(pessoaJuridica.Logomarca)); imagem = new Chunk(imghead, 0, 0); } else imagem = new Chunk(""); var dadosEmpresa = new Phrase(); dadosEmpresa.Add(pessoaJuridica.NomeFantasia + Environment.NewLine); if (pessoaJuridica.Enderecos.Count > 0) { var endereco = pessoaJuridica.Enderecos[0]; dadosEmpresa.Add(endereco.ToString()); } if (pessoaJuridica.Telefones.Count > 0) { var telefone = pessoaJuridica.Telefones[0]; dadosEmpresa.Add("Telefone " + telefone); } var tabelaHeader = new Table(2); tabelaHeader.Border = 0; tabelaHeader.Width = 100; var cell = new Cell(new Phrase(imagem)); cell.Border = 0; cell.Width = 30; tabelaHeader.AddCell(cell); var cell1 = new Cell(dadosEmpresa); cell1.Border = 0; cell1.Width = 70; tabelaHeader.AddCell(cell1); var linhaVazia = new Cell(new Phrase("\n", font2)); linhaVazia.Colspan = 2; linhaVazia.DisableBorderSide(1); tabelaHeader.AddCell(linhaVazia); document.Add(tabelaHeader); // Adicionando linha que informa o número da revista var tabelaNumeroDaRevista = new Table(1); tabelaNumeroDaRevista.Border = 0; tabelaNumeroDaRevista.Width = 100; var celulaNumeroDaRevista = new Cell(new Phrase("Processos de clientes publicados na revista de marcas: " + _numeroDaRevistaSelecionada, font3)); celulaNumeroDaRevista.Border = 0; celulaNumeroDaRevista.Width = 70; celulaNumeroDaRevista.Colspan = 1; tabelaNumeroDaRevista.AddCell(celulaNumeroDaRevista); var linhaVaziaNumeroRevista = new Cell(new Phrase("\n", font2)); linhaVaziaNumeroRevista.Border = 0; linhaVaziaNumeroRevista.Width = 70; linhaVaziaNumeroRevista.Colspan = 1; linhaVaziaNumeroRevista.DisableBorderSide(1); tabelaNumeroDaRevista.AddCell(linhaVaziaNumeroRevista); document.Add(tabelaNumeroDaRevista); }
protected void btnPDF_Click1(object sender, EventArgs e) { Document MyDocumnet = new Document(PageSize.A4, 30, 30, 30, 30); System.IO.MemoryStream MyReport = new System.IO.MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(MyDocumnet, MyReport); MyDocumnet.AddAuthor("Report"); MyDocumnet.AddSubject("My Firsr Pdf"); MyDocumnet.Open(); #region Header iTextSharp.text.Table tblHeader = new iTextSharp.text.Table(4); tblHeader.Width = 100; tblHeader.Padding = 2; tblHeader.Spacing = 1; tblHeader.Border = iTextSharp.text.Rectangle.NO_BORDER; int[] tblWidths = { 25, 15, 20, 20 }; tblHeader.SetWidths(tblWidths); Cell cellHeader = new Cell(new Phrase("Roche Professional Services", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellHeader.HorizontalAlignment = Element.ALIGN_LEFT; cellHeader.VerticalAlignment = Element.ALIGN_TOP; cellHeader.Leading = 8; cellHeader.Colspan = 1; cellHeader.Border = Rectangle.NO_BORDER; tblHeader.AddCell(cellHeader); cellHeader = new Cell(new Phrase(" Clarify case id:", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellHeader.HorizontalAlignment = Element.ALIGN_RIGHT; cellHeader.VerticalAlignment = Element.ALIGN_BOTTOM; cellHeader.Leading = 8; cellHeader.Colspan = 1; cellHeader.Border = Rectangle.NO_BORDER; tblHeader.AddCell(cellHeader); cellHeader = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellHeader.HorizontalAlignment = Element.ALIGN_RIGHT; cellHeader.VerticalAlignment = Element.ALIGN_BOTTOM; cellHeader.Leading = 8; cellHeader.Colspan = 1; cellHeader.Border = Rectangle.BOTTOM_BORDER; tblHeader.AddCell(cellHeader); iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(Server.MapPath("Intel_logo.png")); img.ScaleAbsolute(30, 15); cellHeader = new Cell(img); cellHeader.HorizontalAlignment = Element.ALIGN_RIGHT; cellHeader.VerticalAlignment = Element.ALIGN_TOP; cellHeader.Leading = 8; cellHeader.Colspan = 1; cellHeader.Border = Rectangle.NO_BORDER; tblHeader.AddCell(cellHeader); cellHeader = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellHeader.HorizontalAlignment = Element.ALIGN_RIGHT; cellHeader.VerticalAlignment = Element.ALIGN_BOTTOM; cellHeader.Leading = 8; cellHeader.Colspan = 2; cellHeader.Border = Rectangle.NO_BORDER; tblHeader.AddCell(cellHeader); MyDocumnet.Add(tblHeader); #endregion #region table1 iTextSharp.text.Table tbl1 = new iTextSharp.text.Table(3); tbl1.Width = 100; tbl1.Padding = 3; tbl1.Spacing = 1; tbl1.Border = iTextSharp.text.Rectangle.NO_BORDER; int[] tbl1Widths = { 10, 30, 30 }; tbl1.SetWidths(tbl1Widths); Cell cellTbl1 = new Cell(new Phrase("Report No.", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellTbl1.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl1.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl1.Leading = 8; cellTbl1.Colspan = 1; cellTbl1.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY; cellTbl1.Border = Rectangle.BOX; tbl1.AddCell(cellTbl1); cellTbl1 = new Cell(new Phrase("Instrument Serial No.", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellTbl1.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl1.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl1.Leading = 8; cellTbl1.Colspan = 1; cellTbl1.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY; cellTbl1.Border = Rectangle.BOX; tbl1.AddCell(cellTbl1); cellTbl1 = new Cell(new Phrase("Visit Date", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellTbl1.HorizontalAlignment = Element.ALIGN_CENTER; cellTbl1.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl1.Leading = 8; cellTbl1.Colspan = 1; cellTbl1.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY; cellTbl1.Border = Rectangle.BOX; tbl1.AddCell(cellTbl1); cellTbl1 = new Cell(new Phrase("02154", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellTbl1.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl1.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl1.Leading = 8; cellTbl1.Colspan = 1; cellTbl1.Border = Rectangle.BOX; tbl1.AddCell(cellTbl1); cellTbl1 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellTbl1.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl1.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl1.Leading = 8; cellTbl1.Colspan = 1; cellTbl1.Border = Rectangle.BOX; tbl1.AddCell(cellTbl1); cellTbl1 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellTbl1.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl1.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl1.Leading = 8; cellTbl1.Colspan = 1; cellTbl1.Border = Rectangle.BOX; tbl1.AddCell(cellTbl1); cellTbl1 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellTbl1.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl1.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl1.Leading = 8; cellTbl1.Colspan = 3; cellTbl1.Border = Rectangle.NO_BORDER; tbl1.AddCell(cellTbl1); MyDocumnet.Add(tbl1); #endregion #region table2 iTextSharp.text.Table tbl2 = new iTextSharp.text.Table(4); tbl2.Width = 100; tbl2.Padding = 3; tbl2.Spacing = 1; tbl2.Border = iTextSharp.text.Rectangle.NO_BORDER; int[] tbl2Widths = { 10, 10, 10, 20 }; tbl2.SetWidths(tbl2Widths); Cell cellTbl2 = new Cell(new Phrase("Charge Type:", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellTbl2.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl2.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl2.Leading = 8; cellTbl2.Colspan = 4; cellTbl2.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY; cellTbl2.Border = Rectangle.BOX; tbl2.AddCell(cellTbl2); cellTbl2 = new Cell(new Phrase("[ ] Service Contract", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK))); cellTbl2.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl2.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl2.Leading = 8; cellTbl2.Colspan = 1; cellTbl2.Border = Rectangle.BOX; tbl2.AddCell(cellTbl2); cellTbl2 = new Cell(new Phrase("[ ] Ad-hoc", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK))); cellTbl2.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl2.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl2.Leading = 8; cellTbl2.Colspan = 1; cellTbl2.Border = Rectangle.BOX; tbl2.AddCell(cellTbl2); cellTbl2 = new Cell(new Phrase("[ ] Placement/Rental", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK))); cellTbl2.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl2.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl2.Leading = 8; cellTbl2.Colspan = 1; cellTbl2.Border = Rectangle.BOX; tbl2.AddCell(cellTbl2); cellTbl2 = new Cell(new Phrase("[ ] Other(Pls specify):", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK))); cellTbl2.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl2.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl2.Leading = 8; cellTbl2.Colspan = 1; cellTbl2.Border = Rectangle.BOX; tbl2.AddCell(cellTbl2); cellTbl2 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellTbl2.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl2.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl2.Leading = 8; cellTbl2.Colspan = 4; cellTbl2.Border = Rectangle.NO_BORDER; tbl2.AddCell(cellTbl2); MyDocumnet.Add(tbl2); #endregion #region table3 iTextSharp.text.Table tbl3 = new iTextSharp.text.Table(5); tbl3.Width = 100; tbl3.Padding = 3; tbl3.Spacing = 1; tbl3.Border = iTextSharp.text.Rectangle.NO_BORDER; int[] tbl3Widths = { 10, 10, 10, 10, 10 }; tbl3.SetWidths(tbl3Widths); Cell cellTbl3 = new Cell(new Phrase("Call Details:", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl3.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl3.Leading = 8; cellTbl3.Colspan = 5; cellTbl3.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY; cellTbl3.Border = Rectangle.BOX; tbl3.AddCell(cellTbl3); cellTbl3 = new Cell(new Phrase("Call Received Date :", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK))); cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl3.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl3.Leading = 8; cellTbl3.Colspan = 1; cellTbl3.Border = Rectangle.BOX; tbl3.AddCell(cellTbl3); cellTbl3 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK))); cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl3.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl3.Leading = 8; cellTbl3.Colspan = 1; cellTbl3.Border = Rectangle.BOX; tbl3.AddCell(cellTbl3); cellTbl3 = new Cell(new Phrase("Call Attended Dates :", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK))); cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl3.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl3.Leading = 8; cellTbl3.Colspan = 1; cellTbl3.Border = Rectangle.BOX; tbl3.AddCell(cellTbl3); cellTbl3 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK))); cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl3.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl3.Leading = 8; cellTbl3.Colspan = 1; cellTbl3.Border = Rectangle.BOX; tbl3.AddCell(cellTbl3); cellTbl3 = new Cell(new Phrase("Travel Hours ", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK))); cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl3.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl3.Leading = 8; cellTbl3.Colspan = 1; cellTbl3.Rowspan = 2; cellTbl3.Border = Rectangle.BOX; tbl3.AddCell(cellTbl3); //2nd Row cellTbl3 = new Cell(new Phrase("Time :", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK))); cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl3.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl3.Leading = 8; cellTbl3.Colspan = 1; cellTbl3.Border = Rectangle.BOX; tbl3.AddCell(cellTbl3); cellTbl3 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK))); cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl3.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl3.Leading = 8; cellTbl3.Colspan = 1; cellTbl3.Border = Rectangle.BOX; tbl3.AddCell(cellTbl3); cellTbl3 = new Cell(new Phrase("Time :", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK))); cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl3.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl3.Leading = 8; cellTbl3.Colspan = 1; cellTbl3.Border = Rectangle.BOX; tbl3.AddCell(cellTbl3); cellTbl3 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK))); cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl3.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl3.Leading = 8; cellTbl3.Colspan = 1; cellTbl3.Border = Rectangle.BOX; tbl3.AddCell(cellTbl3); //2nd row end------------ cellTbl3 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl3.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl3.Leading = 8; cellTbl3.Colspan = 4; cellTbl3.Border = Rectangle.NO_BORDER; tbl3.AddCell(cellTbl3); MyDocumnet.Add(tbl3); #endregion //----------------------------------------------------------------------------------------------------------------------------------------------------------------- #region table4 iTextSharp.text.Table tbl4 = new iTextSharp.text.Table(1); tbl4.Width = 100; tbl4.Padding = 3; tbl4.Spacing = 1; tbl4.Border = iTextSharp.text.Rectangle.NO_BORDER; int[] tbl4Widths = { 50 }; tbl4.SetWidths(tbl4Widths); Cell cellTbl4 = new Cell(new Phrase("Problem Description : \n \n\n\n\n\n", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellTbl4.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl4.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl4.Leading = 8; cellTbl4.Colspan = 1; //cellTbl4.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY; cellTbl4.Border = Rectangle.BOX; tbl4.AddCell(cellTbl4); cellTbl4 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellTbl4.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl4.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl4.Leading = 8; cellTbl4.Colspan = 1; cellTbl4.Border = Rectangle.NO_BORDER; tbl4.AddCell(cellTbl4); MyDocumnet.Add(tbl4); #endregion //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- iTextSharp.text.Table tbl5 = new iTextSharp.text.Table(1); tbl5.Width = 100; tbl5.Padding = 3; tbl5.Spacing = 1; tbl5.Border = iTextSharp.text.Rectangle.NO_BORDER; int[] tbl5Widths = { 50 }; tbl5.SetWidths(tbl5Widths); Cell cellTbl5 = new Cell(new Phrase("Action Summary : \n \n\n\n\n\n", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellTbl5.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl5.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl5.Leading = 8; cellTbl5.Colspan = 1; //cellTbl4.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY; cellTbl5.Border = Rectangle.BOX; tbl5.AddCell(cellTbl5); cellTbl5 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellTbl5.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl5.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl5.Leading = 8; cellTbl5.Colspan = 1; cellTbl5.Border = Rectangle.NO_BORDER; tbl5.AddCell(cellTbl5); MyDocumnet.Add(tbl5); //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- iTextSharp.text.Table tbl6 = new iTextSharp.text.Table(1); tbl6.Width = 100; tbl6.Padding = 3; tbl6.Spacing = 1; tbl6.Border = iTextSharp.text.Rectangle.NO_BORDER; int[] tbl6Widths = { 50 }; tbl6.SetWidths(tbl6Widths); Cell cellTbl6 = new Cell(new Phrase("Service Eng remark : \n \n\n\n\n\n", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellTbl6.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl6.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl6.Leading = 8; cellTbl6.Colspan = 1; //cellTbl4.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY; cellTbl6.Border = Rectangle.BOX; tbl6.AddCell(cellTbl6); cellTbl6 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellTbl6.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl6.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl6.Leading = 8; cellTbl6.Colspan = 1; cellTbl6.Border = Rectangle.NO_BORDER; tbl6.AddCell(cellTbl6); MyDocumnet.Add(tbl6); //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //Other tables #region table11 iTextSharp.text.Table tbl11 = new iTextSharp.text.Table(5); tbl11.Width = 100; tbl11.Padding = 3; tbl11.Spacing = 1; tbl11.Border = iTextSharp.text.Rectangle.NO_BORDER; int[] tbl11Widths = { 40, 1, 30, 1, 40 }; tbl11.SetWidths(tbl11Widths); Cell cellTbl11 = new Cell(new Phrase("Service Engineer/Application Specialist Name:", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK))); cellTbl11.HorizontalAlignment = Element.ALIGN_CENTER; cellTbl11.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl11.Leading = 8; cellTbl11.Colspan = 1; cellTbl11.Border = Rectangle.BOX; tbl11.AddCell(cellTbl11); cellTbl11 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK))); cellTbl11.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl11.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl11.Leading = 8; cellTbl11.Colspan = 1; cellTbl11.Border = Rectangle.NO_BORDER; tbl11.AddCell(cellTbl11); cellTbl11 = new Cell(new Phrase("3 SP Address Seal", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK))); cellTbl11.HorizontalAlignment = Element.ALIGN_CENTER; cellTbl11.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl11.Leading = 8; cellTbl11.Colspan = 1; cellTbl11.Border = Rectangle.BOX; tbl11.AddCell(cellTbl11); cellTbl11 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK))); cellTbl11.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl11.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl11.Leading = 8; cellTbl11.Colspan = 1; cellTbl11.Border = Rectangle.NO_BORDER; tbl11.AddCell(cellTbl11); cellTbl11 = new Cell(new Phrase("Customer's/Users Name:", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK))); cellTbl11.HorizontalAlignment = Element.ALIGN_CENTER; cellTbl11.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl11.Leading = 8; cellTbl11.Colspan = 1; cellTbl11.Border = Rectangle.BOX; tbl11.AddCell(cellTbl11); ///Row 2 cellTbl11 = new Cell(new Phrase(" \n", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK))); cellTbl11.HorizontalAlignment = Element.ALIGN_CENTER; cellTbl11.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl11.Leading = 8; cellTbl11.Colspan = 1; cellTbl11.Border = Rectangle.BOX; tbl11.AddCell(cellTbl11); cellTbl11 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK))); cellTbl11.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl11.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl11.Leading = 8; cellTbl11.Colspan = 1; cellTbl11.Border = Rectangle.NO_BORDER; tbl11.AddCell(cellTbl11); cellTbl11 = new Cell(new Phrase(" \n", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK))); cellTbl11.HorizontalAlignment = Element.ALIGN_CENTER; cellTbl11.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl11.Leading = 8; cellTbl11.Colspan = 1; cellTbl11.Rowspan = 4; cellTbl11.Border = Rectangle.BOX; tbl11.AddCell(cellTbl11); cellTbl11 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK))); cellTbl11.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl11.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl11.Leading = 8; cellTbl11.Colspan = 1; cellTbl11.Border = Rectangle.NO_BORDER; tbl11.AddCell(cellTbl11); cellTbl11 = new Cell(new Phrase(" \n", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK))); cellTbl11.HorizontalAlignment = Element.ALIGN_CENTER; cellTbl11.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl11.Leading = 8; cellTbl11.Colspan = 1; cellTbl11.Border = Rectangle.BOX; tbl11.AddCell(cellTbl11); //Row cellTbl11 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellTbl11.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl11.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl11.Leading = 8; cellTbl11.Colspan = 2; cellTbl11.Border = Rectangle.NO_BORDER; tbl11.AddCell(cellTbl11); cellTbl11 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK))); cellTbl11.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl11.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl11.Leading = 8; cellTbl11.Colspan = 2; cellTbl11.Border = Rectangle.NO_BORDER; tbl11.AddCell(cellTbl11); //Row cellTbl11 = new Cell(new Phrase("Service Engineer/Application Specialist Name:", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK))); cellTbl11.HorizontalAlignment = Element.ALIGN_CENTER; cellTbl11.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl11.Leading = 8; cellTbl11.Colspan = 1; cellTbl11.Border = Rectangle.BOX; tbl11.AddCell(cellTbl11); cellTbl11 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK))); cellTbl11.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl11.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl11.Leading = 8; cellTbl11.Colspan = 1; cellTbl11.Border = Rectangle.NO_BORDER; tbl11.AddCell(cellTbl11); cellTbl11 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK))); cellTbl11.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl11.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl11.Leading = 8; cellTbl11.Colspan = 1; cellTbl11.Border = Rectangle.NO_BORDER; tbl11.AddCell(cellTbl11); cellTbl11 = new Cell(new Phrase("Customer's/Users Name:", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK))); cellTbl11.HorizontalAlignment = Element.ALIGN_CENTER; cellTbl11.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl11.Leading = 8; cellTbl11.Colspan = 1; cellTbl11.Border = Rectangle.BOX; tbl11.AddCell(cellTbl11); cellTbl11 = new Cell(new Phrase(" \n", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK))); cellTbl11.HorizontalAlignment = Element.ALIGN_CENTER; cellTbl11.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl11.Leading = 8; cellTbl11.Colspan = 1; cellTbl11.Border = Rectangle.BOX; tbl11.AddCell(cellTbl11); cellTbl11 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK))); cellTbl11.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl11.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl11.Leading = 8; cellTbl11.Colspan = 1; cellTbl11.Border = Rectangle.NO_BORDER; tbl11.AddCell(cellTbl11); cellTbl11 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK))); cellTbl11.HorizontalAlignment = Element.ALIGN_LEFT; cellTbl11.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl11.Leading = 8; cellTbl11.Colspan = 1; cellTbl11.Border = Rectangle.NO_BORDER; tbl11.AddCell(cellTbl11); cellTbl11 = new Cell(new Phrase(" \n", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK))); cellTbl11.HorizontalAlignment = Element.ALIGN_CENTER; cellTbl11.VerticalAlignment = Element.ALIGN_MIDDLE; cellTbl11.Leading = 8; cellTbl11.Colspan = 1; cellTbl11.Border = Rectangle.BOX; tbl11.AddCell(cellTbl11); MyDocumnet.Add(tbl11); #endregion MyDocumnet.Close(); Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=Q5533.pdf"); Response.ContentType = "application/pdf"; Response.BinaryWrite(MyReport.ToArray()); Response.End(); }
private iTextSharp.text.Table GenerateMainTable(DataSet dsMainTable) { // 生成表格 BaseFont bfChinese = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); Font font22B = new Font(bfChinese, 22, iTextSharp.text.Font.BOLD); Font font22 = new Font(bfChinese, 22); Font font20B = new Font(bfChinese, 20, iTextSharp.text.Font.BOLD); Font font20 = new Font(bfChinese, 20); Font font19B = new Font(bfChinese, 19, iTextSharp.text.Font.BOLD); Font font19 = new Font(bfChinese, 19); Font font14B = new Font(bfChinese, 14, iTextSharp.text.Font.BOLD); Font font14 = new Font(bfChinese, 14); Font font13B = new Font(bfChinese, 13, iTextSharp.text.Font.BOLD); Font font13 = new Font(bfChinese, 13); Font font12B = new Font(bfChinese, 12, iTextSharp.text.Font.BOLD); Font font12 = new Font(bfChinese, 12); Font font11B = new Font(bfChinese, 11, iTextSharp.text.Font.BOLD); Font font11 = new Font(bfChinese, 11); Font font10B = new Font(bfChinese, 10, iTextSharp.text.Font.BOLD); Font font10 = new Font(bfChinese, 10); Font font9B = new Font(bfChinese, 9, iTextSharp.text.Font.BOLD); Font font9 = new Font(bfChinese, 9); Font font8B = new Font(bfChinese, 8, iTextSharp.text.Font.BOLD); Font font8 = new Font(bfChinese, 8); int intColumn = 0; intColumn += 1 + 1; intColumn += 1 + 1; iTextSharp.text.Table itbOutput = new iTextSharp.text.Table(intColumn); itbOutput.BorderWidth = 0; itbOutput.Cellpadding = 2; itbOutput.Cellspacing = 0; itbOutput.Width = 100; // 加入表头信息 Cell cellTitle = new Cell(new Paragraph("用户组信息", font19B)); cellTitle.BorderWidth = 0; cellTitle.HorizontalAlignment = 1; cellTitle.VerticalAlignment = 1; cellTitle.Colspan = intColumn; itbOutput.AddCell(cellTitle); Cell cellTitleSpace = new Cell(new Paragraph(" ", font20B)); cellTitleSpace.BorderWidth = 0; cellTitleSpace.HorizontalAlignment = 1; cellTitleSpace.VerticalAlignment = 1; cellTitleSpace.Colspan = intColumn; itbOutput.AddCell(cellTitleSpace); itbOutput.AddCell(cellTitleSpace); // 定义分割线 Cell cellBorder = new Cell(new Paragraph("", font10B)); cellBorder.BorderWidth = 0; cellBorder.BorderWidthBottom = 1; cellBorder.HorizontalAlignment = 1; cellBorder.VerticalAlignment = 1; cellBorder.Colspan = intColumn; if (dsMainTable.Tables.Count > 0) { foreach (DataRow drTemp in dsMainTable.Tables[0].Rows) { // 生成主表表格 // 显示用户组编号标题 iTextSharp.text.Cell cellUserGroupIDTitle = new Cell(new Paragraph("用户组编号", font11B)); cellUserGroupIDTitle.BorderWidth = 0.5F; cellUserGroupIDTitle.HorizontalAlignment = 1; cellUserGroupIDTitle.Rowspan = 1; cellUserGroupIDTitle.Colspan = 1; cellUserGroupIDTitle.Width = 100 / intColumn; cellUserGroupIDTitle.VerticalAlignment = Cell.ALIGN_MIDDLE; itbOutput.AddCell(cellUserGroupIDTitle); // 显示用户组编号值 iTextSharp.text.Cell cellUserGroupIDContent = new Cell(new Paragraph(FunctionManager.RemoveTags(GetValue(drTemp["UserGroupID"], null)), font10)); cellUserGroupIDContent.Rowspan = 1; cellUserGroupIDContent.Colspan = 1; cellUserGroupIDContent.Width = 100 / intColumn; cellUserGroupIDContent.VerticalAlignment = Cell.ALIGN_MIDDLE; cellUserGroupIDContent.HorizontalAlignment = 1; cellUserGroupIDContent.BorderWidthTop = 0.5F; cellUserGroupIDContent.BorderWidthLeft = 0.5F; cellUserGroupIDContent.BorderWidthBottom = 0.5F; cellUserGroupIDContent.BorderWidthRight = 0.5F; itbOutput.AddCell(cellUserGroupIDContent); // 显示用户组名称标题 iTextSharp.text.Cell cellUserGroupNameTitle = new Cell(new Paragraph("用户组名称", font11B)); cellUserGroupNameTitle.BorderWidth = 0.5F; cellUserGroupNameTitle.HorizontalAlignment = 1; cellUserGroupNameTitle.Rowspan = 1; cellUserGroupNameTitle.Colspan = 1; cellUserGroupNameTitle.Width = 100 / intColumn; cellUserGroupNameTitle.VerticalAlignment = Cell.ALIGN_MIDDLE; itbOutput.AddCell(cellUserGroupNameTitle); // 显示用户组名称值 iTextSharp.text.Cell cellUserGroupNameContent = new Cell(new Paragraph(FunctionManager.RemoveTags(GetValue(drTemp["UserGroupName"], null)), font10)); cellUserGroupNameContent.Rowspan = 1; cellUserGroupNameContent.Colspan = 1; cellUserGroupNameContent.Width = 100 / intColumn; cellUserGroupNameContent.VerticalAlignment = Cell.ALIGN_MIDDLE; cellUserGroupNameContent.HorizontalAlignment = 1; cellUserGroupNameContent.BorderWidthTop = 0.5F; cellUserGroupNameContent.BorderWidthLeft = 0.5F; cellUserGroupNameContent.BorderWidthBottom = 0.5F; cellUserGroupNameContent.BorderWidthRight = 0.5F; itbOutput.AddCell(cellUserGroupNameContent); // 显示内容标题 iTextSharp.text.Cell cellUserGroupContentTitle = new Cell(new Paragraph("内容", font11B)); cellUserGroupContentTitle.BorderWidth = 0.5F; cellUserGroupContentTitle.HorizontalAlignment = 1; cellUserGroupContentTitle.Rowspan = 1; cellUserGroupContentTitle.Colspan = 1; cellUserGroupContentTitle.Width = 100 / intColumn; cellUserGroupContentTitle.VerticalAlignment = Cell.ALIGN_MIDDLE; itbOutput.AddCell(cellUserGroupContentTitle); // 显示内容值 iTextSharp.text.Cell cellUserGroupContentContent = new Cell(new Paragraph(FunctionManager.RemoveTags(GetValue(drTemp["UserGroupContent"], null)), font10)); cellUserGroupContentContent.Rowspan = 1; cellUserGroupContentContent.Colspan = 3; cellUserGroupContentContent.Width = 100 / intColumn; cellUserGroupContentContent.VerticalAlignment = Cell.ALIGN_MIDDLE; cellUserGroupContentContent.HorizontalAlignment = 1; cellUserGroupContentContent.BorderWidthTop = 0.5F; cellUserGroupContentContent.BorderWidthLeft = 0.5F; cellUserGroupContentContent.BorderWidthBottom = 0.5F; cellUserGroupContentContent.BorderWidthRight = 0.5F; itbOutput.AddCell(cellUserGroupContentContent); // 显示备注标题 iTextSharp.text.Cell cellUserGroupRemarkTitle = new Cell(new Paragraph("备注", font11B)); cellUserGroupRemarkTitle.BorderWidth = 0.5F; cellUserGroupRemarkTitle.HorizontalAlignment = 1; cellUserGroupRemarkTitle.Rowspan = 1; cellUserGroupRemarkTitle.Colspan = 1; cellUserGroupRemarkTitle.Width = 100 / intColumn; cellUserGroupRemarkTitle.VerticalAlignment = Cell.ALIGN_MIDDLE; itbOutput.AddCell(cellUserGroupRemarkTitle); // 显示备注值 iTextSharp.text.Cell cellUserGroupRemarkContent = new Cell(new Paragraph(FunctionManager.RemoveTags(GetValue(drTemp["UserGroupRemark"], null)), font10)); cellUserGroupRemarkContent.Rowspan = 1; cellUserGroupRemarkContent.Colspan = 3; cellUserGroupRemarkContent.Width = 100 / intColumn; cellUserGroupRemarkContent.VerticalAlignment = Cell.ALIGN_MIDDLE; cellUserGroupRemarkContent.HorizontalAlignment = 1; cellUserGroupRemarkContent.BorderWidthTop = 0.5F; cellUserGroupRemarkContent.BorderWidthLeft = 0.5F; cellUserGroupRemarkContent.BorderWidthBottom = 0.5F; cellUserGroupRemarkContent.BorderWidthRight = 0.5F; itbOutput.AddCell(cellUserGroupRemarkContent); // 显示系统默认页标题 iTextSharp.text.Cell cellDefaultPageTitle = new Cell(new Paragraph("系统默认页", font11B)); cellDefaultPageTitle.BorderWidth = 0.5F; cellDefaultPageTitle.HorizontalAlignment = 1; cellDefaultPageTitle.Rowspan = 1; cellDefaultPageTitle.Colspan = 1; cellDefaultPageTitle.Width = 100 / intColumn; cellDefaultPageTitle.VerticalAlignment = Cell.ALIGN_MIDDLE; itbOutput.AddCell(cellDefaultPageTitle); // 显示系统默认页值 iTextSharp.text.Cell cellDefaultPageContent = new Cell(new Paragraph(FunctionManager.RemoveTags(GetValue(drTemp["DefaultPage"], null)), font10)); cellDefaultPageContent.Rowspan = 1; cellDefaultPageContent.Colspan = 3; cellDefaultPageContent.Width = 100 / intColumn; cellDefaultPageContent.VerticalAlignment = Cell.ALIGN_MIDDLE; cellDefaultPageContent.HorizontalAlignment = 1; cellDefaultPageContent.BorderWidthTop = 0.5F; cellDefaultPageContent.BorderWidthLeft = 0.5F; cellDefaultPageContent.BorderWidthBottom = 0.5F; cellDefaultPageContent.BorderWidthRight = 0.5F; itbOutput.AddCell(cellDefaultPageContent); // 显示更新时间标题 iTextSharp.text.Cell cellUpdateDateTitle = new Cell(new Paragraph("更新时间", font11B)); cellUpdateDateTitle.BorderWidth = 0.5F; cellUpdateDateTitle.HorizontalAlignment = 1; cellUpdateDateTitle.Rowspan = 1; cellUpdateDateTitle.Colspan = 1; cellUpdateDateTitle.Width = 100 / intColumn; cellUpdateDateTitle.VerticalAlignment = Cell.ALIGN_MIDDLE; itbOutput.AddCell(cellUpdateDateTitle); // 显示更新时间值 iTextSharp.text.Cell cellUpdateDateContent = new Cell(new Paragraph(FunctionManager.RemoveTags(GetValue(drTemp["UpdateDate"], null)), font10)); cellUpdateDateContent.Rowspan = 1; cellUpdateDateContent.Colspan = 3; cellUpdateDateContent.Width = 100 / intColumn; cellUpdateDateContent.VerticalAlignment = Cell.ALIGN_MIDDLE; cellUpdateDateContent.HorizontalAlignment = 1; cellUpdateDateContent.BorderWidthTop = 0.5F; cellUpdateDateContent.BorderWidthLeft = 0.5F; cellUpdateDateContent.BorderWidthBottom = 0.5F; cellUpdateDateContent.BorderWidthRight = 0.5F; itbOutput.AddCell(cellUpdateDateContent); // 生成一对一相关表表格 itbOutput.AddCell(cellTitleSpace); itbOutput.AddCell(cellTitleSpace); } } return(itbOutput); }
public void GenerateXMLReport() { try { this.doc.Open(); RenderLogo(); //RenderHeaderAddress(); RenderReportJobInfo(); RenderProjectsReports(); #region Add Details Table float[] DetailsHeaderwidths = this.Headerwidths; // percentage iTextSharp.text.Table JobDetailstable = new iTextSharp.text.Table(DetailsHeaderwidths.Length); JobDetailstable.Padding = 1; JobDetailstable.DefaultCell.BorderWidth = 1; JobDetailstable.Widths = DetailsHeaderwidths; JobDetailstable.WidthPercentage = 100; JobDetailstable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; JobDetailstable.DefaultCell.BackgroundColor = Color.LIGHT_GRAY; foreach (var x in this.ColList) { JobDetailstable.AddCell(new Phrase(x, fntHeading)); } JobDetailstable.EndHeaders(); Font myDetailFont = fntDetails; foreach (var x in this.ReportRows) { for (int i = 0; i < ColList.Count; i++) { JobDetailstable.DefaultCell.BackgroundColor = Color.WHITE; if(x.row[i].type == CellType.Number) JobDetailstable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT; else JobDetailstable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; JobDetailstable.AddCell(new Phrase(x.row[i].value, myDetailFont)); } } JobDetailstable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; Cell cell = new Cell(new Paragraph("Total", myDetailFont)); cell.BackgroundColor = Color.LIGHT_GRAY; cell.BorderWidth = 1; cell.Colspan = 3; JobDetailstable.AddCell(cell); JobDetailstable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT; JobDetailstable.DefaultCell.BackgroundColor = Color.LIGHT_GRAY; JobDetailstable.AddCell(new Phrase(this.total, myDetailFont)); doc.Add(JobDetailstable); #endregion } catch (Exception ex) { //MessageBox.Show("Error: " + ex.Message); } doc.Close(); writer.Close(); }
private Table ObtenhaTabelaCelulaProcesso(IRevistaDePatente revista) { var tabela = new Table(1); var corBackgroudHeader = new Color(211, 211, 211); tabela.Widths = new Single[] { 100 }; tabela.Padding = 0; tabela.Spacing = 0; tabela.Width = 100; tabela.AutoFillEmptyCells = true; tabela.Border = 0; tabela.EndHeaders(); var celula1 = new Cell(new Phrase("Processo " + revista.NumeroDoProcessoFormatado, _Fonte3)); celula1.DisableBorderSide(0); celula1.BackgroundColor = corBackgroudHeader; tabela.AddCell(celula1); return tabela; }
private iTextSharp.text.Table GenerateMainTable(DataSet dsMainTable) { // 生成表格 BaseFont bfChinese = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); Font font22B = new Font(bfChinese, 22, iTextSharp.text.Font.BOLD); Font font22 = new Font(bfChinese, 22); Font font20B = new Font(bfChinese, 20, iTextSharp.text.Font.BOLD); Font font20 = new Font(bfChinese, 20); Font font19B = new Font(bfChinese, 19, iTextSharp.text.Font.BOLD); Font font19 = new Font(bfChinese, 19); Font font14B = new Font(bfChinese, 14, iTextSharp.text.Font.BOLD); Font font14 = new Font(bfChinese, 14); Font font13B = new Font(bfChinese, 13, iTextSharp.text.Font.BOLD); Font font13 = new Font(bfChinese, 13); Font font12B = new Font(bfChinese, 12, iTextSharp.text.Font.BOLD); Font font12 = new Font(bfChinese, 12); Font font11B = new Font(bfChinese, 11, iTextSharp.text.Font.BOLD); Font font11 = new Font(bfChinese, 11); Font font10B = new Font(bfChinese, 10, iTextSharp.text.Font.BOLD); Font font10 = new Font(bfChinese, 10); Font font9B = new Font(bfChinese, 9, iTextSharp.text.Font.BOLD); Font font9 = new Font(bfChinese, 9); Font font8B = new Font(bfChinese, 8, iTextSharp.text.Font.BOLD); Font font8 = new Font(bfChinese, 8); int intColumn = 0; intColumn += 1 + 1; intColumn += 1 + 1; iTextSharp.text.Table itbOutput = new iTextSharp.text.Table(intColumn); itbOutput.BorderWidth = 0; itbOutput.Cellpadding = 2; itbOutput.Cellspacing = 0; itbOutput.Width = 100; // 加入表头信息 Cell cellTitle = new Cell(new Paragraph("Dictionary", font19B)); cellTitle.BorderWidth = 0; cellTitle.HorizontalAlignment = 1; cellTitle.VerticalAlignment = 1; cellTitle.Colspan = intColumn; itbOutput.AddCell(cellTitle); Cell cellTitleSpace = new Cell(new Paragraph(" ", font20B)); cellTitleSpace.BorderWidth = 0; cellTitleSpace.HorizontalAlignment = 1; cellTitleSpace.VerticalAlignment = 1; cellTitleSpace.Colspan = intColumn; itbOutput.AddCell(cellTitleSpace); itbOutput.AddCell(cellTitleSpace); // 定义分割线 Cell cellBorder = new Cell(new Paragraph("", font10B)); cellBorder.BorderWidth = 0; cellBorder.BorderWidthBottom = 1; cellBorder.HorizontalAlignment = 1; cellBorder.VerticalAlignment = 1; cellBorder.Colspan = intColumn; if (dsMainTable.Tables.Count > 0) { foreach (DataRow drTemp in dsMainTable.Tables[0].Rows) { // 生成主表表格 // 显示代码标题 iTextSharp.text.Cell cellDMTitle = new Cell(new Paragraph("代码", font11B)); cellDMTitle.BorderWidth = 0.5F; cellDMTitle.HorizontalAlignment = 1; cellDMTitle.Rowspan = 1; cellDMTitle.Colspan = 1; cellDMTitle.Width = 100 / intColumn; cellDMTitle.VerticalAlignment = Cell.ALIGN_MIDDLE; itbOutput.AddCell(cellDMTitle); // 显示代码值 iTextSharp.text.Cell cellDMContent = new Cell(new Paragraph(FunctionManager.RemoveTags(GetValue(drTemp["DM"], null)), font10)); cellDMContent.Rowspan = 1; cellDMContent.Colspan = 1; cellDMContent.Width = 100 / intColumn; cellDMContent.VerticalAlignment = Cell.ALIGN_MIDDLE; cellDMContent.HorizontalAlignment = 1; cellDMContent.BorderWidthTop = 0.5F; cellDMContent.BorderWidthLeft = 0.5F; cellDMContent.BorderWidthBottom = 0.5F; cellDMContent.BorderWidthRight = 0.5F; itbOutput.AddCell(cellDMContent); // 显示类型标题 iTextSharp.text.Cell cellLXTitle = new Cell(new Paragraph("类型", font11B)); cellLXTitle.BorderWidth = 0.5F; cellLXTitle.HorizontalAlignment = 1; cellLXTitle.Rowspan = 1; cellLXTitle.Colspan = 1; cellLXTitle.Width = 100 / intColumn; cellLXTitle.VerticalAlignment = Cell.ALIGN_MIDDLE; itbOutput.AddCell(cellLXTitle); // 显示类型值 iTextSharp.text.Cell cellLXContent = new Cell(new Paragraph(GetValue(drTemp["LX_DictionaryType_MC"]), font10)); cellLXContent.Rowspan = 1; cellLXContent.Colspan = 1; cellLXContent.Width = 100 / intColumn; cellLXContent.VerticalAlignment = Cell.ALIGN_MIDDLE; cellLXContent.HorizontalAlignment = 1; cellLXContent.BorderWidthTop = 0.5F; cellLXContent.BorderWidthLeft = 0.5F; cellLXContent.BorderWidthBottom = 0.5F; cellLXContent.BorderWidthRight = 0.5F; itbOutput.AddCell(cellLXContent); // 显示名称标题 iTextSharp.text.Cell cellMCTitle = new Cell(new Paragraph("名称", font11B)); cellMCTitle.BorderWidth = 0.5F; cellMCTitle.HorizontalAlignment = 1; cellMCTitle.Rowspan = 1; cellMCTitle.Colspan = 1; cellMCTitle.Width = 100 / intColumn; cellMCTitle.VerticalAlignment = Cell.ALIGN_MIDDLE; itbOutput.AddCell(cellMCTitle); // 显示名称值 iTextSharp.text.Cell cellMCContent = new Cell(new Paragraph(FunctionManager.RemoveTags(GetValue(drTemp["MC"], null)), font10)); cellMCContent.Rowspan = 1; cellMCContent.Colspan = 1; cellMCContent.Width = 100 / intColumn; cellMCContent.VerticalAlignment = Cell.ALIGN_MIDDLE; cellMCContent.HorizontalAlignment = 1; cellMCContent.BorderWidthTop = 0.5F; cellMCContent.BorderWidthLeft = 0.5F; cellMCContent.BorderWidthBottom = 0.5F; cellMCContent.BorderWidthRight = 0.5F; itbOutput.AddCell(cellMCContent); // 显示上级代码标题 iTextSharp.text.Cell cellSJDMTitle = new Cell(new Paragraph("上级代码", font11B)); cellSJDMTitle.BorderWidth = 0.5F; cellSJDMTitle.HorizontalAlignment = 1; cellSJDMTitle.Rowspan = 1; cellSJDMTitle.Colspan = 1; cellSJDMTitle.Width = 100 / intColumn; cellSJDMTitle.VerticalAlignment = Cell.ALIGN_MIDDLE; itbOutput.AddCell(cellSJDMTitle); // 显示上级代码值 iTextSharp.text.Cell cellSJDMContent = new Cell(new Paragraph(GetValue(drTemp["SJDM_Dictionary_MC"]), font10)); cellSJDMContent.Rowspan = 1; cellSJDMContent.Colspan = 1; cellSJDMContent.Width = 100 / intColumn; cellSJDMContent.VerticalAlignment = Cell.ALIGN_MIDDLE; cellSJDMContent.HorizontalAlignment = 1; cellSJDMContent.BorderWidthTop = 0.5F; cellSJDMContent.BorderWidthLeft = 0.5F; cellSJDMContent.BorderWidthBottom = 0.5F; cellSJDMContent.BorderWidthRight = 0.5F; itbOutput.AddCell(cellSJDMContent); // 显示说明标题 iTextSharp.text.Cell cellSMTitle = new Cell(new Paragraph("说明", font11B)); cellSMTitle.BorderWidth = 0.5F; cellSMTitle.HorizontalAlignment = 1; cellSMTitle.Rowspan = 1; cellSMTitle.Colspan = 1; cellSMTitle.Width = 100 / intColumn; cellSMTitle.VerticalAlignment = Cell.ALIGN_MIDDLE; itbOutput.AddCell(cellSMTitle); // 显示说明值 iTextSharp.text.Cell cellSMContent = new Cell(new Paragraph(FunctionManager.RemoveTags(GetValue(drTemp["SM"], null)), font10)); cellSMContent.Rowspan = 1; cellSMContent.Colspan = 3; cellSMContent.Width = 100 / intColumn; cellSMContent.VerticalAlignment = Cell.ALIGN_MIDDLE; cellSMContent.HorizontalAlignment = 1; cellSMContent.BorderWidthTop = 0.5F; cellSMContent.BorderWidthLeft = 0.5F; cellSMContent.BorderWidthBottom = 0.5F; cellSMContent.BorderWidthRight = 0.5F; itbOutput.AddCell(cellSMContent); // 生成一对一相关表表格 itbOutput.AddCell(cellTitleSpace); itbOutput.AddCell(cellTitleSpace); } } return(itbOutput); }
protected void btnPdf_Click(object sender, EventArgs e) { try { string customerJSON = Request.Form["CustomerJSON"]; DataTable dataTable = JsonConvert.DeserializeObject <DataTable>(customerJSON); string Name = "AccountData"; string[] columnNames = (from dc in dataTable.Columns.Cast <DataColumn>() select dc.ColumnName).ToArray(); int Cell = 0; int count = columnNames.Length; object[] array = new object[count]; dataTable.Rows.Add(array); Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f); System.IO.MemoryStream mStream = new System.IO.MemoryStream(); PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, mStream); int cols = dataTable.Columns.Count; int rows = dataTable.Rows.Count; HeaderFooter header = new HeaderFooter(new Phrase(Name), false); // Remove the border that is set by default header.Border = iTextSharp.text.Rectangle.TITLE; // Align the text: 0 is left, 1 center and 2 right. header.Alignment = Element.ALIGN_CENTER; pdfDoc.Header = header; // Header. pdfDoc.Open(); iTextSharp.text.Table pdfTable = new iTextSharp.text.Table(cols, rows); pdfTable.BorderWidth = 0; pdfTable.Width = 80; pdfTable.Padding = 0; pdfTable.Spacing = 4; //creating table headers //for (int i = 0; i < cols; i++) //{ // Cell cellCols = new Cell(); // Chunk chunkCols = new Chunk(); // cellCols.BackgroundColor = new iTextSharp.text.Color(System.Drawing.ColorTranslator.FromHtml("#548B54")); // iTextSharp.text.Font ColFont = FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.WHITE); // chunkCols = new Chunk(dataTable.Columns[i].ColumnName, ColFont); // cellCols.Add(chunkCols); // pdfTable.AddCell(cellCols); //} for (int k = 0; k < rows; k++) { for (int j = 0; j < cols; j++) { Cell cellRows = new Cell(); //if (k % 2 == 0) //{ // cellRows.BackgroundColor = new iTextSharp.text.Color(System.Drawing.ColorTranslator.FromHtml("#cccccc")); ; //} //else { cellRows.BackgroundColor = new iTextSharp.text.Color(System.Drawing.ColorTranslator.FromHtml("#ffffff")); } iTextSharp.text.Font RowFont = FontFactory.GetFont(FontFactory.HELVETICA, 10); Chunk chunkRows = new Chunk(dataTable.Rows[k][j].ToString(), RowFont); cellRows.Add(chunkRows); pdfTable.AddCell(cellRows); } } pdfDoc.Add(pdfTable); pdfDoc.Close(); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + Name + "_" + DateTime.Now.ToString() + ".pdf"); Response.Clear(); Response.BinaryWrite(mStream.ToArray()); Response.End(); } catch (Exception ex) { } }
private void UpdatePDF(string strPath) { string strPhysicalPath = oVariable.DocumentsFolder() + strPath; Document doc = new Document(); FileStream fs = null; try { fs = new FileStream(strPhysicalPath, FileMode.Create); PdfWriter.GetInstance(doc, fs); string strHeader = "ClearView PCR Information"; HeaderFooter header = new HeaderFooter(new Phrase(strHeader, new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 6)), false); header.Border = iTextSharp.text.Rectangle.NO_BORDER; header.Alignment = 2; doc.Header = header; string strFooter = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(); HeaderFooter footer = new HeaderFooter(new Phrase(strFooter, new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 6)), false); footer.Border = iTextSharp.text.Rectangle.NO_BORDER; footer.Alignment = 2; doc.Footer = footer; doc.Open(); Cell cell; iTextSharp.text.Table oTable = new iTextSharp.text.Table(2); oTable.BorderWidth = 0; oTable.BorderColor = new iTextSharp.text.Color(255, 255, 255); oTable.Padding = 2; oTable.Width = 100; iTextSharp.text.Font oFontHeader = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 10, 1); iTextSharp.text.Font oFontBold = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 8, 1); iTextSharp.text.Font oFont = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 8, 0); cell = new Cell(new Phrase("Project Change Request Report", oFontHeader)); cell.Colspan = 2; cell.BackgroundColor = new iTextSharp.text.Color(169, 162, 141); oTable.AddCell(cell); ds = oTPM.GetPCR(intId); int intRequest = Int32.Parse(ds.Tables[0].Rows[0]["requestid"].ToString()); int intItem = Int32.Parse(ds.Tables[0].Rows[0]["itemid"].ToString()); int intNumber = Int32.Parse(ds.Tables[0].Rows[0]["number"].ToString()); dsResource = oCustomized.GetTPM(intRequest, intItem, intNumber); oTable.AddCell(new Cell(new Phrase("Scope:", oFontBold))); oTable.AddCell(new Cell(new Phrase((chkScope.Checked ? "Yes" : "No"), oFont))); oTable.AddCell(new Cell(new Phrase("Schedule:", oFontBold))); oTable.AddCell(new Cell(new Phrase((chkSchedule.Checked ? "Yes" : "No"), oFont))); oTable.AddCell(new Cell(new Phrase("Financial:", oFontBold))); oTable.AddCell(new Cell(new Phrase((chkFinancial.Checked ? "Yes" : "No"), oFont))); cell = new Cell(new Phrase("Detailed Description of Proposed Change", oFontBold)); cell.Colspan = 2; oTable.AddCell(cell); oTable.AddCell(new Cell(new Phrase("Scope:", oFontBold))); oTable.AddCell(new Cell(new Paragraph(txtScopeComments.Text, oFont))); oTable.AddCell(new Cell(new Phrase("Schedule:", oFontBold))); oTable.AddCell(new Cell(new Paragraph(txtScheduleComments.Text, oFont))); oTable.AddCell(new Cell(new Phrase("Financial:", oFontBold))); oTable.AddCell(new Cell(new Paragraph(txtFinancialComments.Text, oFont))); doc.Add(oTable); //style=\"border:dashed 1px #CCCCCC\" class=\"lightdefault\" iTextSharp.text.Table oTable2 = new iTextSharp.text.Table(3); oTable2.BorderWidth = 0; oTable2.BorderColor = new iTextSharp.text.Color(255, 255, 255); oTable2.Padding = 2; oTable2.Width = 100; cell = new Cell(new Phrase("Schedule Change Details", oFontBold)); cell.Colspan = 3; oTable2.AddCell(cell); oTable2.AddCell(new Cell(new Phrase("Phase", oFontBold))); oTable2.AddCell(new Cell(new Phrase("Approved Dates", oFontBold))); oTable2.AddCell(new Cell(new Phrase("Modified Dates", oFontBold))); oTable2.AddCell(new Cell(new Phrase("Discovery", oFont))); if (dsResource.Tables[0].Rows[0]["appsd"] == DBNull.Value || dsResource.Tables[0].Rows[0]["apped"] == DBNull.Value) { oTable2.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable2.AddCell(new Cell(new Phrase(GetDate(dsResource.Tables[0].Rows[0]["appsd"].ToString()) + " - " + GetDate(dsResource.Tables[0].Rows[0]["apped"].ToString()), oFont))); } oTable2.AddCell(new Cell(new Phrase(GetDate(txtPCRScheduleDS.Text) + " - " + GetDate(txtPCRScheduleDE.Text), oFont))); oTable2.AddCell(new Cell(new Phrase("Planning", oFont))); if (dsResource.Tables[0].Rows[0]["appsp"] == DBNull.Value || dsResource.Tables[0].Rows[0]["appep"] == DBNull.Value) { oTable2.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable2.AddCell(new Cell(new Phrase(GetDate(dsResource.Tables[0].Rows[0]["appsp"].ToString()) + " - " + GetDate(dsResource.Tables[0].Rows[0]["appep"].ToString()), oFont))); } oTable2.AddCell(new Cell(new Phrase(GetDate(txtPCRSchedulePS.Text) + " - " + GetDate(txtPCRSchedulePE.Text), oFont))); oTable2.AddCell(new Cell(new Phrase("Execution", oFont))); if (dsResource.Tables[0].Rows[0]["appse"] == DBNull.Value || dsResource.Tables[0].Rows[0]["appee"] == DBNull.Value) { oTable2.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable2.AddCell(new Cell(new Phrase(GetDate(dsResource.Tables[0].Rows[0]["appse"].ToString()) + " - " + GetDate(dsResource.Tables[0].Rows[0]["appee"].ToString()), oFont))); } oTable2.AddCell(new Cell(new Phrase(GetDate(txtPCRScheduleES.Text) + " - " + GetDate(txtPCRScheduleEE.Text), oFont))); oTable2.AddCell(new Cell(new Phrase("Closing", oFont))); if (dsResource.Tables[0].Rows[0]["appsc"] == DBNull.Value || dsResource.Tables[0].Rows[0]["appec"] == DBNull.Value) { oTable2.AddCell(new Cell(new Phrase("N / A", oFont))); } else { oTable2.AddCell(new Cell(new Phrase(GetDate(dsResource.Tables[0].Rows[0]["appsc"].ToString()) + " - " + GetDate(dsResource.Tables[0].Rows[0]["appec"].ToString()), oFont))); } oTable2.AddCell(new Cell(new Phrase(GetDate(txtPCRScheduleCS.Text) + " - " + GetDate(txtPCRScheduleCE.Text), oFont))); doc.Add(oTable2); iTextSharp.text.Table oTable3 = new iTextSharp.text.Table(3); oTable3.BorderWidth = 0; oTable3.BorderColor = new iTextSharp.text.Color(255, 255, 255); oTable3.Padding = 2; oTable3.Width = 100; cell = new Cell(new Phrase("Financial Change Details", oFontBold)); cell.Colspan = 3; oTable3.AddCell(cell); oTable3.AddCell(new Cell(new Phrase("Phase", oFontBold))); oTable3.AddCell(new Cell(new Phrase("Approved Financials", oFontBold))); oTable3.AddCell(new Cell(new Phrase("Modified Financials", oFontBold))); double dblAppDI = GetFloat(dsResource.Tables[0].Rows[0]["appid"].ToString()); double dblAppDE = GetFloat(dsResource.Tables[0].Rows[0]["appexd"].ToString()); double dblAppDH = GetFloat(dsResource.Tables[0].Rows[0]["apphd"].ToString()); double dblActDI = GetFloat(dsResource.Tables[0].Rows[0]["actid"].ToString()); double dblActDE = GetFloat(dsResource.Tables[0].Rows[0]["acted"].ToString()); double dblActDH = GetFloat(dsResource.Tables[0].Rows[0]["acthd"].ToString()); double dblEstDI = GetFloat(dsResource.Tables[0].Rows[0]["estid"].ToString()); double dblEstDE = GetFloat(dsResource.Tables[0].Rows[0]["ested"].ToString()); double dblEstDH = GetFloat(dsResource.Tables[0].Rows[0]["esthd"].ToString()); double dblForeDI = dblActDI + dblEstDI; double dblForeDE = dblActDE + dblEstDE; double dblForeDH = dblActDH + dblEstDH; double dblAppD = dblAppDI + dblAppDE + dblAppDH; double dblActD = dblActDI + dblActDE + dblActDH; double dblForeD = dblForeDI + dblForeDE + dblForeDH; double dblAppPI = GetFloat(dsResource.Tables[0].Rows[0]["appip"].ToString()); double dblAppPE = GetFloat(dsResource.Tables[0].Rows[0]["appexp"].ToString()); double dblAppPH = GetFloat(dsResource.Tables[0].Rows[0]["apphp"].ToString()); double dblActPI = GetFloat(dsResource.Tables[0].Rows[0]["actip"].ToString()); double dblActPE = GetFloat(dsResource.Tables[0].Rows[0]["actep"].ToString()); double dblActPH = GetFloat(dsResource.Tables[0].Rows[0]["acthp"].ToString()); double dblEstPI = GetFloat(dsResource.Tables[0].Rows[0]["estip"].ToString()); double dblEstPE = GetFloat(dsResource.Tables[0].Rows[0]["estep"].ToString()); double dblEstPH = GetFloat(dsResource.Tables[0].Rows[0]["esthp"].ToString()); double dblForePI = dblActPI + dblEstPI; double dblForePE = dblActPE + dblEstPE; double dblForePH = dblActPH + dblEstPH; double dblAppP = dblAppPI + dblAppPE + dblAppPH; double dblActP = dblActPI + dblActPE + dblActPH; double dblForeP = dblForePI + dblForePE + dblForePH; double dblAppEI = GetFloat(dsResource.Tables[0].Rows[0]["appie"].ToString()); double dblAppEE = GetFloat(dsResource.Tables[0].Rows[0]["appexe"].ToString()); double dblAppEH = GetFloat(dsResource.Tables[0].Rows[0]["apphe"].ToString()); double dblActEI = GetFloat(dsResource.Tables[0].Rows[0]["actie"].ToString()); double dblActEE = GetFloat(dsResource.Tables[0].Rows[0]["actee"].ToString()); double dblActEH = GetFloat(dsResource.Tables[0].Rows[0]["acthe"].ToString()); double dblEstEI = GetFloat(dsResource.Tables[0].Rows[0]["estie"].ToString()); double dblEstEE = GetFloat(dsResource.Tables[0].Rows[0]["estee"].ToString()); double dblEstEH = GetFloat(dsResource.Tables[0].Rows[0]["esthe"].ToString()); double dblForeEI = dblActEI + dblEstEI; double dblForeEE = dblActEE + dblEstEE; double dblForeEH = dblActEH + dblEstEH; double dblAppE = dblAppEI + dblAppEE + dblAppEH; double dblActE = dblActEI + dblActEE + dblActEH; double dblForeE = dblForeEI + dblForeEE + dblForeEH; double dblAppCI = GetFloat(dsResource.Tables[0].Rows[0]["appic"].ToString()); double dblAppCE = GetFloat(dsResource.Tables[0].Rows[0]["appexc"].ToString()); double dblAppCH = GetFloat(dsResource.Tables[0].Rows[0]["apphc"].ToString()); double dblActCI = GetFloat(dsResource.Tables[0].Rows[0]["actic"].ToString()); double dblActCE = GetFloat(dsResource.Tables[0].Rows[0]["actec"].ToString()); double dblActCH = GetFloat(dsResource.Tables[0].Rows[0]["acthc"].ToString()); double dblEstCI = GetFloat(dsResource.Tables[0].Rows[0]["estic"].ToString()); double dblEstCE = GetFloat(dsResource.Tables[0].Rows[0]["estec"].ToString()); double dblEstCH = GetFloat(dsResource.Tables[0].Rows[0]["esthc"].ToString()); double dblForeCI = dblActCI + dblEstCI; double dblForeCE = dblActCE + dblEstCE; double dblForeCH = dblActCH + dblEstCH; double dblAppC = dblAppCI + dblAppCE + dblAppCH; double dblActC = dblActCI + dblActCE + dblActCH; double dblForeC = dblForeCI + dblForeCE + dblForeCH; double dblFD = GetFloat(txtPCRFinancialD.Text); double dblFP = GetFloat(txtPCRFinancialP.Text); double dblFE = GetFloat(txtPCRFinancialE.Text); double dblFC = GetFloat(txtPCRFinancialC.Text); oTable3.AddCell(new Cell(new Phrase("Discovery", oFont))); oTable3.AddCell(new Cell(new Phrase("$" + dblAppD.ToString("N"), oFont))); oTable3.AddCell(new Cell(new Phrase("$" + dblFD.ToString("N"), oFont))); oTable3.AddCell(new Cell(new Phrase("Planning", oFont))); oTable3.AddCell(new Cell(new Phrase("$" + dblAppP.ToString("N"), oFont))); oTable3.AddCell(new Cell(new Phrase("$" + dblFP.ToString("N"), oFont))); oTable3.AddCell(new Cell(new Phrase("Execution", oFont))); oTable3.AddCell(new Cell(new Phrase("$" + dblAppE.ToString("N"), oFont))); oTable3.AddCell(new Cell(new Phrase("$" + dblFE.ToString("N"), oFont))); oTable3.AddCell(new Cell(new Phrase("Closing", oFont))); oTable3.AddCell(new Cell(new Phrase("$" + dblAppC.ToString("N"), oFont))); oTable3.AddCell(new Cell(new Phrase("$" + dblFC.ToString("N"), oFont))); doc.Add(oTable3); iTextSharp.text.Table oTable5 = new iTextSharp.text.Table(4); oTable5.BorderWidth = 0; oTable5.BorderColor = new iTextSharp.text.Color(255, 255, 255); oTable5.Padding = 2; oTable5.Width = 100; cell = new Cell(new Phrase("Detail Of Financial Impact Of Proposed Change", oFontBold)); cell.Colspan = 4; oTable5.AddCell(cell); cell = new Cell(new Phrase("Discovery", oFontBold)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("Current Approved Budget", oFontBold)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("Change in Budget", oFontBold)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("New Budget Total", oFontBold)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); oTable5.AddCell(new Cell(new Phrase("Internal Labor", oFont))); cell = new Cell(new Phrase("$" + dblAppDI.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblActDI.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblForeDI.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); oTable5.AddCell(new Phrase("External Labor", oFont)); cell = new Cell(new Phrase("$" + dblAppDE.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblActDE.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblForeDE.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); oTable5.AddCell(new Phrase("HW/SW/One Time Cost", oFont)); cell = new Cell(new Phrase("$" + dblAppDH.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblActDH.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblForeDH.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); oTable5.AddCell(new Phrase("Total", oFont)); cell = new Cell(new Phrase("$" + dblAppD.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblActD.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblForeD.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(); cell.Colspan = 4; oTable5.AddCell(cell); cell = new Cell(new Phrase("Planning", oFontBold)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("Current Approved Budget", oFontBold)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("Change in Budget", oFontBold)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("New Budget Total", oFontBold)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); oTable5.AddCell(new Cell(new Phrase("Internal Labor", oFont))); cell = new Cell(new Phrase("$" + dblAppPI.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblActPI.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblForePI.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); oTable5.AddCell(new Phrase("External Labor", oFont)); cell = new Cell(new Phrase("$" + dblAppPE.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblActPE.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblForePE.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); oTable5.AddCell(new Phrase("HW/SW/One Time Cost", oFont)); cell = new Cell(new Phrase("$" + dblAppPH.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblActPH.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblForePH.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); oTable5.AddCell(new Phrase("Total", oFont)); cell = new Cell(new Phrase("$" + dblAppP.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblActP.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblForeP.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(); cell.Colspan = 4; oTable5.AddCell(cell); cell = new Cell(new Phrase("Execution", oFontBold)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("Current Approved Budget", oFontBold)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("Change in Budget", oFontBold)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("New Budget Total", oFontBold)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); oTable5.AddCell(new Cell(new Phrase("Internal Labor", oFont))); cell = new Cell(new Phrase("$" + dblAppEI.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblActEI.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblForeEI.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); oTable5.AddCell(new Phrase("External Labor", oFont)); cell = new Cell(new Phrase("$" + dblAppEE.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblActEE.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblForeEE.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); oTable5.AddCell(new Phrase("HW/SW/One Time Cost", oFont)); cell = new Cell(new Phrase("$" + dblAppEH.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblActEH.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblForeEH.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); oTable5.AddCell(new Phrase("Total", oFont)); cell = new Cell(new Phrase("$" + dblAppE.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblActE.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblForeE.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(); cell.Colspan = 4; oTable5.AddCell(cell); cell = new Cell(new Phrase("Closing", oFontBold)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("Current Approved Budget", oFontBold)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("Change in Budget", oFontBold)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("New Budget Total", oFontBold)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); oTable5.AddCell(new Cell(new Phrase("Internal Labor", oFont))); cell = new Cell(new Phrase("$" + dblAppCI.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblActCI.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblForeCI.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); oTable5.AddCell(new Phrase("External Labor", oFont)); cell = new Cell(new Phrase("$" + dblAppCE.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblActCE.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblForeCE.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); oTable5.AddCell(new Phrase("HW/SW/One Time Cost", oFont)); cell = new Cell(new Phrase("$" + dblAppCH.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblActCH.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblForeCH.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); oTable5.AddCell(new Phrase("Total", oFont)); cell = new Cell(new Phrase("$" + dblAppC.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblActC.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); cell = new Cell(new Phrase("$" + dblForeC.ToString("N"), oFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; oTable5.AddCell(cell); doc.Add(oTable5); iTextSharp.text.Table oTable4 = new iTextSharp.text.Table(3); oTable4.BorderWidth = 0; oTable4.BorderColor = new iTextSharp.text.Color(255, 255, 255); oTable4.Padding = 2; oTable4.Width = 100; cell = new Cell(new Phrase("Reason for PCR ", oFontBold)); cell.Colspan = 3; oTable4.AddCell(cell); iTextSharp.text.List list = new List(false, 10); list.IndentationRight = 2.5F; list.ListSymbol = new Chunk("\u2022", FontFactory.GetFont(FontFactory.HELVETICA, 10)); for (int ii = 0; ii < chkPCRReason.Items.Count; ii++) { if (chkPCRReason.Items[ii].Selected == true) { list.Add(new iTextSharp.text.ListItem(chkPCRReason.Items[ii].Value, oFont)); } } cell = new Cell(list); cell.Colspan = 3; oTable4.AddCell(cell); doc.Add(oTable4); } catch { } finally { doc.Close(); fs.Close(); } }
private void EscrevaProcessosNoDocumentoSintetico() { var tabela = new Table(4); tabela.Widths = new Single[] { 60, 100, 60, 100 }; tabela.Padding = 1; tabela.Spacing = 0; tabela.Width = 100; tabela.AutoFillEmptyCells = true; tabela.DefaultCell.Border = Rectangle.NO_BORDER; var corBackgroudHeader = new Color(211, 211, 211); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Número do processo", _Fonte3, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true)); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Patente", _Fonte3, Cell.ALIGN_LEFT, 0, corBackgroudHeader, true)); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Despacho", _Fonte3, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true)); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Cliente", _Fonte3, Cell.ALIGN_LEFT, 0, corBackgroudHeader, true)); tabela.EndHeaders(); foreach (var processo in _processosPatentes) { tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.NumeroDoProcessoFormatado.ToString(), _Fonte1, Cell.ALIGN_CENTER, 0, false)); if (processo.Patente != null && !string.IsNullOrEmpty(processo.Patente.TituloPatente)) tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Patente.TituloPatente, _Fonte1, Cell.ALIGN_LEFT, 0, false)); else tabela.AddCell(iTextSharpUtilidades.CrieCelula(string.Empty, _Fonte1, Cell.ALIGN_LEFT, 0, false)); tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Despacho != null ? processo.Despacho.Codigo : "", _Fonte1, Cell.ALIGN_CENTER, 0, false)); string clientes = string.Empty; if (processo.Patente != null) { clientes = processo.Patente.Clientes.Aggregate(clientes, (current, cliente) => current + (cliente.Pessoa.Nome + " - ")); if (!string.IsNullOrEmpty(clientes)) clientes = clientes.Substring(0, clientes.Length - 3); } tabela.AddCell(iTextSharpUtilidades.CrieCelula(clientes, _Fonte1, Cell.ALIGN_LEFT, 0, false)); } _documento.Add(tabela); }
public static void formatoCED110324NN4(Document document, ElectronicDocument electronicDocument, Data objTimbre, pdfPageEventHandlerCED110324NN4 pageEventHandler, Int64 idCfdi, DataTable dtOpcDet, Hashtable htCFDI, HttpContext hc) { try { DAL dal = new DAL(); #region "Construimos el Documento" #region "Construimos el Encabezado" Table encabezado = new Table(3); float[] headerwidthsEncabezado = { 60, 20, 20 }; encabezado.Widths = headerwidthsEncabezado; encabezado.WidthPercentage = 100; encabezado.Padding = 1; encabezado.Spacing = 1; encabezado.BorderWidth = 0; encabezado.DefaultCellBorder = 0; encabezado.BorderColor = gris; cel = new Cell(new Phrase("COMPROBANTE FISCAL DIGITAL POR INTERNET", f8LA)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(8f, 9f); par.Add(new Chunk(htCFDI["nombreEmisor"].ToString().ToUpper(), f8B)); par.Add(new Chunk("\n\nRFC: " + htCFDI["rfcEmisor"].ToString().ToUpper(), f8L)); par.Add(new Chunk("\n\n" + htCFDI["direccionEmisor1"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor2"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor3"].ToString().ToUpper(), f6)); cel = new Cell(par); cel.BorderWidthTop = 1; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = gris; cel.Rowspan = 4; encabezado.AddCell(cel); cel = new Cell(new Phrase("Serie/Folio", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("Número de Certificado", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(htCFDI["serie"].ToString().ToUpper() + " " + htCFDI["folio"].ToString(), folio)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.NumeroCertificado.Value.ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("Fecha/Hora: ", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(htCFDI["fechaCfdi"].ToString(), f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("Tipo:", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 1; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.TipoComprobante.Value.ToString(), f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("Expedido en: \n", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("FOLIO FISCAL", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = grisOX; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = gris; cel.Colspan = 2; encabezado.AddCell(cel); StringBuilder expedido = new StringBuilder(); expedido. Append(htCFDI["direccionExpedido1"].ToString().ToUpper()).Append("\n"). Append(htCFDI["direccionExpedido2"].ToString().ToUpper()).Append("\n"). Append(htCFDI["direccionExpedido3"].ToString().ToUpper()).Append("\n"); cel = new Cell(new Phrase(expedido.ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; encabezado.AddCell(cel); cel = new Cell(new Phrase(htCFDI["UUID"].ToString(), f7B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = gris; cel.Colspan = 2; encabezado.AddCell(cel); //Tabla Receptor y Encabezados Detalle Table tReceptor = new Table(5); float[] headerwidthsReceptor = { 15, 15, 40, 15, 15 }; tReceptor.Widths = headerwidthsReceptor; tReceptor.WidthPercentage = 100; tReceptor.Padding = 1; tReceptor.Spacing = 1; tReceptor.BorderWidth = 0; tReceptor.DefaultCellBorder = 0; tReceptor.BorderColor = gris; cel = new Cell(new Phrase("Receptor:\n", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 5; tReceptor.AddCell(cel); cel = new Cell(new Phrase(htCFDI["nombreReceptor"].ToString(), f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 5; tReceptor.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 1f); par.Add(new Chunk("R.F.C. " + electronicDocument.Data.Receptor.Rfc.Value + "\n\n", f6)); par.Add(new Chunk(htCFDI["direccionReceptor1"].ToString() + "\n", f6)); par.Add(new Chunk(htCFDI["direccionReceptor2"].ToString() + "\n", f6)); par.Add(new Chunk(htCFDI["direccionReceptor3"].ToString() + "\n", f6)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 1; cel.BorderWidthLeft = 1; cel.BorderWidthBottom = 1; cel.Colspan = 5; tReceptor.AddCell(cel); cel = new Cell(new Phrase("Cantidad\n", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BackgroundColor = grisOX; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = grisOX; tReceptor.AddCell(cel); cel = new Cell(new Phrase("Unidad", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BackgroundColor = grisOX; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = grisOX; tReceptor.AddCell(cel); cel = new Cell(new Phrase("Descripción", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BackgroundColor = grisOX; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = grisOX; tReceptor.AddCell(cel); cel = new Cell(new Phrase("Precio Unitario", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BackgroundColor = grisOX; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = grisOX; tReceptor.AddCell(cel); cel = new Cell(new Phrase("Total", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BackgroundColor = grisOX; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = grisOX; tReceptor.AddCell(cel); #endregion #region "Construimos Tablas de Partidas" // Creamos la tabla para insertar los conceptos de detalle de la factura PdfPTable tableConceptos = new PdfPTable(5); int[] colWithsConceptos = new int[5]; //String[] arrColWidthConceptos = dtConfigFact.Rows[0]["conceptosColWidth"].ToString().Split(new Char[] { ',' }); String[] arrColWidthConceptos = { "15", "15", "40", "15", "15" }; for (int i = 0; i < arrColWidthConceptos.Length; i++) { colWithsConceptos.SetValue(Convert.ToInt32(arrColWidthConceptos[i]), i); } tableConceptos.SetWidths(colWithsConceptos); tableConceptos.WidthPercentage = 100F; int numConceptos = electronicDocument.Data.Conceptos.Count; PdfPCell cellConceptos = new PdfPCell(); PdfPCell cellMontos = new PdfPCell(); for (int i = 0; i < numConceptos; i++) { cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Cantidad.Value.ToString(), new Font(Font.HELVETICA, 7, Font.NORMAL))); cellConceptos.Border = 0; cellConceptos.HorizontalAlignment = PdfCell.ALIGN_LEFT; tableConceptos.AddCell(cellConceptos); cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Unidad.Value, new Font(Font.HELVETICA, 7, Font.NORMAL))); cellConceptos.Border = 0; cellConceptos.HorizontalAlignment = PdfCell.ALIGN_LEFT; tableConceptos.AddCell(cellConceptos); cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Descripcion.Value + "\nNo Identificación: " + dtOpcDet.Rows[i]["noIdent"].ToString(), new Font(Font.HELVETICA, 7, Font.NORMAL))); cellConceptos.Border = 0; tableConceptos.AddCell(cellConceptos); cellMontos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].ValorUnitario.Value.ToString("C", _ci), new Font(Font.HELVETICA, 7, Font.NORMAL))); cellMontos.Border = 0; cellMontos.HorizontalAlignment = PdfCell.ALIGN_JUSTIFIED; tableConceptos.AddCell(cellMontos); cellMontos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Importe.Value.ToString("C", _ci), new Font(Font.HELVETICA, 8, Font.NORMAL))); cellMontos.Border = 0; cellMontos.HorizontalAlignment = PdfCell.ALIGN_JUSTIFIED; tableConceptos.AddCell(cellMontos); } #endregion #region "Construimos el Comentarios" Table comentarios = new Table(4); float[] headerwidthsComentarios = { 25, 25, 35, 15 }; comentarios.Widths = headerwidthsComentarios; comentarios.WidthPercentage = 100; comentarios.Padding = 1; comentarios.Spacing = 1; comentarios.BorderWidth = 0; comentarios.DefaultCellBorder = 0; comentarios.BorderColor = gris; int idMoneda = 1; DataTable dtImporteLetra = dal.QueryDT("DS_FE", "SELECT dbo.convertNumToTextFunction(@0, @1) AS cantidadLetra", "F:S:" + electronicDocument.Data.Total.Value.ToString() + ";F:I:" + idMoneda, hc); cel = new Cell(new Phrase("Importe con Letra:\n" + dtImporteLetra.Rows[0]["cantidadLetra"].ToString(), f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_LEFT; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = gris; cel.Colspan = 2; cel.Rowspan = 3; comentarios.AddCell(cel); cel = new Cell(new Phrase("Sub Total:", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.SubTotal.Value.ToString("C", _ci), f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase("Total Trasladados:", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.TotalTraslados.Value.ToString("C", _ci), f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase("Importe Total:", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 1; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Total.Value.ToString("C", _ci), f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 1; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BackgroundColor = grisOX; cel.BorderColor = grisOX; comentarios.AddCell(cel); #endregion #region "Construimos el Desglose de Impuestos" Table desgloseImpuestos = new Table(3); float[] headerwidthsDesgloce = { 15, 15, 70 }; desgloseImpuestos.Widths = headerwidthsDesgloce; desgloseImpuestos.WidthPercentage = 100; desgloseImpuestos.Padding = 1; desgloseImpuestos.Spacing = 1; desgloseImpuestos.BorderWidth = 0; desgloseImpuestos.DefaultCellBorder = 0; desgloseImpuestos.BorderColor = gris; cel = new Cell(new Phrase("Desgloce de Impuestos", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 1; cel.BorderColor = gris; cel.Colspan = 2; desgloseImpuestos.AddCell(cel); cel = new Cell(new Phrase("", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; desgloseImpuestos.AddCell(cel); for (int i = 0; i < electronicDocument.Data.Impuestos.Traslados.Count; i++) { cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.Traslados[i].Tipo.Value.ToString() + " " + electronicDocument.Data.Impuestos.Traslados[i].Tasa.Value.ToString() + "%", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; desgloseImpuestos.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.Traslados[i].Importe.Value.ToString("C", _ci), f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; desgloseImpuestos.AddCell(cel); cel = new Cell(new Phrase("", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; desgloseImpuestos.AddCell(cel); } for (int i = 0; i < electronicDocument.Data.Impuestos.Retenciones.Count; i++) { cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.Retenciones[i].Tipo.Value.ToString(), f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 1; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; desgloseImpuestos.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.Retenciones[i].Importe.Value.ToString("C", _ci), f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 1; cel.BorderWidthBottom = 0; cel.BorderColor = gris; desgloseImpuestos.AddCell(cel); cel = new Cell(new Phrase("", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; desgloseImpuestos.AddCell(cel); } #endregion #region "Construimos Tabla de Datos CFDI" DefaultSplitCharacter split = new DefaultSplitCharacter(); Table adicional = new Table(3); float[] headerwidthsAdicional = { 20, 25, 55 }; adicional.Widths = headerwidthsAdicional; adicional.WidthPercentage = 100; adicional.Padding = 1; adicional.Spacing = 1; adicional.BorderWidth = (float).5; adicional.DefaultCellBorder = 1; adicional.BorderColor = gris; if (timbrar) { #region "Generamos Quick Response Code" byte[] bytesQRCode = new byte[0]; if (timbrar) { // Generamos el Quick Response Code (QRCode) string re = electronicDocument.Data.Emisor.Rfc.Value; string rr = electronicDocument.Data.Receptor.Rfc.Value; string tt = String.Format("{0:F6}", electronicDocument.Data.Total.Value); string id = objTimbre.Uuid.Value; StringBuilder sbCadenaQRCode = new StringBuilder(); sbCadenaQRCode. Append("?"). Append("re=").Append(re). Append("&"). Append("rr=").Append(rr). Append("&"). Append("tt=").Append(tt). Append("&"). Append("id=").Append(id); BarcodeLib.Barcode.QRCode.QRCode barcode = new BarcodeLib.Barcode.QRCode.QRCode(); barcode.Data = sbCadenaQRCode.ToString(); barcode.ModuleSize = 3; barcode.LeftMargin = 0; barcode.RightMargin = 10; barcode.TopMargin = 0; barcode.BottomMargin = 0; barcode.Encoding = BarcodeLib.Barcode.QRCode.QRCodeEncoding.Auto; barcode.Version = BarcodeLib.Barcode.QRCode.QRCodeVersion.Auto; barcode.ECL = BarcodeLib.Barcode.QRCode.ErrorCorrectionLevel.L; bytesQRCode = barcode.drawBarcodeAsBytes(); } #endregion Image imageQRCode = Image.GetInstance(bytesQRCode); imageQRCode.Alignment = (Image.TEXTWRAP | Image.ALIGN_LEFT); imageQRCode.ScaleToFit(90f, 90f); imageQRCode.IndentationLeft = 9f; imageQRCode.SpacingAfter = 9f; imageQRCode.BorderColorTop = Color.WHITE; cel = new Cell(imageQRCode); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 6; adicional.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("SELLO DIGITAL DEL EMISOR\n", f5B)); par.Add(new Chunk(electronicDocument.Data.Sello.Value, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Colspan = 2; adicional.AddCell(cel); cel = new Cell(new Phrase("FOLIO FISCAL:", f5B)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase(objTimbre.Uuid.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("FECHA Y HORA DE CERTIFICACION:", f5B)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); string[] fechaTimbrado = Convert.ToDateTime(objTimbre.FechaTimbrado.Value).GetDateTimeFormats('s'); cel = new Cell(new Phrase(fechaTimbrado[0], f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL SAT:", f5B)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase(objTimbre.NumeroCertificadoSat.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL EMISOR:", f5B)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; adicional.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.NumeroCertificado.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = (float).5; adicional.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("TIPO DE COMPROBANTE: ", f5B)); par.Add(new Chunk(electronicDocument.Data.TipoComprobante.Value + " | ", f5)); par.Add(new Chunk("Moneda: ", f5B)); par.Add(new Chunk(electronicDocument.Data.Moneda.Value + " | ", f5)); par.Add(new Chunk("TASA DE CAMBIO: ", f5B)); string tasaCambio = electronicDocument.Data.TipoCambio.Value; string regimenes = string.Empty; if (tasaCambio.Length > 0) { par.Add(new Chunk(Convert.ToDouble(tasaCambio).ToString("C", _ci) + " | ", f5)); } else { par.Add(new Chunk(" | ", f5)); } par.Add(new Chunk("FORMA DE PAGO: ", f5B)); par.Add(new Chunk(electronicDocument.Data.FormaPago.Value + " | ", f5)); par.Add(new Chunk("MÉTODO DE PAGO: ", f5B)); par.Add(new Chunk(electronicDocument.Data.MetodoPago.Value, f5)); if (electronicDocument.Data.NumeroCuentaPago.Value.ToString().Length > 0) { par.Add(new Chunk(" | " + "No. CUENTA: ", f5B)); par.Add(new Chunk(electronicDocument.Data.NumeroCuentaPago.Value, f5)); } if (electronicDocument.Data.Emisor.Regimenes.Count > 0) { for (int u = 0; u < electronicDocument.Data.Emisor.Regimenes.Count; u++) regimenes += electronicDocument.Data.Emisor.Regimenes[u].Regimen.Value.ToString() + ","; par.Add(new Chunk(" | " + "RÉGIMEN FISCAL: ", f5B)); par.Add(new Chunk(regimenes.Substring(0, regimenes.Length - 1).ToString() + " | ", f5)); } if (electronicDocument.Data.FolioFiscalOriginal.Value.ToString().Length > 0) { par.Add(new Chunk("\nDATOS CFDI ORIGINAL - SERIE: ", f5B)); par.Add(new Chunk(electronicDocument.Data.SerieFolioFiscalOriginal.Value, f5)); par.Add(new Chunk(" FOLIO: ", f5B)); par.Add(new Chunk(electronicDocument.Data.FolioFiscalOriginal.Value, f5)); par.Add(new Chunk(" FECHA: ", f5B)); par.Add(new Chunk(electronicDocument.Data.FechaFolioFiscalOriginal.Value.ToString(), f5)); par.Add(new Chunk(" MONTO: ", f5B)); par.Add(new Chunk(electronicDocument.Data.MontoFolioFiscalOriginal.Value.ToString(), f5)); } cel.BorderColor = gris; cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; cel.BorderColor = gris; adicional.AddCell(cel); if (electronicDocument.Data.LugarExpedicion.Value.Length > 0) { par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("LUGAR EXPEDICIÓN: ", f5B)); par.Add(new Chunk(electronicDocument.Data.LugarExpedicion.Value, f5)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 3; adicional.AddCell(cel); } par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("CADENA ORIGINAL DEL COMPLEMENTO DE CERTIFICACIÓN DIGITAL DEL SAT\n", f5B)); par.Add(new Chunk(electronicDocument.FingerPrintPac, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Colspan = 3; adicional.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 0f); par.Add(new Chunk("SELLO DIGITAL DEL SAT\n", f5B)); par.Add(new Chunk(objTimbre.SelloSat.Value, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 3; adicional.AddCell(cel); } #endregion #region "Construimos Tabla del Footer" PdfPTable footer = new PdfPTable(1); footer.WidthPercentage = 100; footer.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; cell = new PdfPCell(new Phrase("", f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.BorderWidthBottom = 0; footer.AddCell(cell); cell = new PdfPCell(new Phrase("ESTE DOCUMENTO ES UNA REPRESENTACIÓN IMPRESA DE UN CFDI", f6B)); cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = grisOX; cell.BorderWidthTop = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.BorderWidthBottom = 0; footer.AddCell(cell); #endregion pageEventHandler.encabezado = encabezado; pageEventHandler.encReceptor = tReceptor; pageEventHandler.footer = footer; document.Open(); //document.Add(tReceptor); document.Add(tableConceptos); document.Add(comentarios); document.Add(desgloseImpuestos); document.Add(adicional); #endregion } catch (Exception ex) { string exe = ex.Message; } }
public void GeneratePDF(DataSet _ms) { String rpt_date = ""; String Daily_notes = ""; String Daily_comments = ""; String Change_order_notes = ""; DataTable dtPDFData = _ms.Tables[0]; foreach (DataRow dRow in dtPDFData.Rows) { rpt_date = dRow["rpt_date"] == DBNull.Value ? "" : dRow["rpt_date"].ToString(); Daily_notes = dRow["Daily_notes"] == DBNull.Value ? "" : dRow["Daily_notes"].ToString(); Daily_comments = dRow["Daily_comments"] == DBNull.Value ? "" : dRow["Daily_comments"].ToString(); Change_order_notes = dRow["Change_order_notes"] == DBNull.Value ? "" : dRow["Change_order_notes"].ToString(); } MemoryStream m = new MemoryStream(); //Document document = new Document(); Document document = new Document(PageSize.A4.Rotate(), 50, 50, 50, 50); try { Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition","attachment;filename=DailyProjectReport.pdf"); //PdfWriter.GetInstance(document, new FileStream("HarishTesting.pdf", FileMode.Create)); PdfWriter writer = PdfWriter.GetInstance(document, m); writer.CloseStream = false; document.AddAuthor("Whitfield Corporation"); document.AddSubject("Daily Production REPORT"); Phrase phrase4 = new Phrase(); phrase4.Add(BuildNewCellSpanRows("Whitfield Corporation Daily Production Report for ", rpt_date)); HeaderFooter headerFooter2 = new HeaderFooter(phrase4, false); headerFooter2.Border = 0; HeaderFooter headerFooter1 = new HeaderFooter(new Phrase("Page: ", FontFactory.GetFont("Times-Roman", 8.0F, 0, new iTextSharp.text.Color(0, 0, 0))), true); headerFooter1.Border = 0; document.Footer = headerFooter1; document.Header = headerFooter2; document.Open(); iTextSharp.text.Table table1 = new iTextSharp.text.Table(2); table1.Padding = 4.0F; table1.Spacing = 0.0F; float[] fArr2 = new float[] { 24.0F, 24.0F }; float[] fArr1 = fArr2; table1.WidthPercentage = 100.0F; Cell cell = new Cell(new Phrase("General Information", FontFactory.GetFont(FontFactory.HELVETICA, 18, iTextSharp.text.Font.BOLD))); cell.HorizontalAlignment = 1; cell.VerticalAlignment = 1; cell.Leading = 8.0F; cell.Colspan = 2; cell.Border = 0; cell.BackgroundColor = new iTextSharp.text.Color(190, 190, 190); table1.AddCell(cell); table1.DefaultCellBorderWidth = 1.0F; table1.DefaultRowspan = 1; table1.DefaultHorizontalAlignment = 0; //table1.AddCell(BuildNewCell("Report Date:", rpt_date.Trim())); //cell = new Cell(BuildNewCell("Daily Notes:", Daily_notes)); //cell.Colspan = 2; //table1.AddCell(cell); cell = new Cell(BuildNewCell("Daily Comments:", Daily_comments)); cell.Colspan = 2; table1.AddCell(cell); //cell = new Cell(BuildNewCell("Change Order Notes:", Change_order_notes)); //cell.Colspan = 2; //table1.AddCell(cell); //table1.AddCell(""); document.Add(table1); document.Add(GenerateCoreReport(rpt_date)); } catch (DocumentException) { throw; } document.Close(); Response.Buffer = true; Response.Clear(); //Write pdf byes to outputstream Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length); Response.OutputStream.Flush(); Response.End(); }
public static void formatoN(Document document, ElectronicDocument electronicDocument, Data objTimbre, pdfPageEventHandlerPfizer pageEventHandler, DataTable dtEncabezado, DataTable dtDetalle, Hashtable htCFDI, HttpContext hc) { try { DAL dal = new DAL(); #region "Construimos el Documento" #region "Construimos el Encabezado" Table encabezado = new Table(7); float[] headerwidthsEncabezado = { 9, 18, 28, 28, 5, 7, 5 }; encabezado.Widths = headerwidthsEncabezado; encabezado.WidthPercentage = 100; encabezado.Padding = 1; encabezado.Spacing = 1; encabezado.BorderWidth = 0; encabezado.DefaultCellBorder = 0; encabezado.BorderColor = gris; //Agregando Imagen de Logotipo Image imgLogo = Image.GetInstance(pathIMGLOGO); imgLogo.ScalePercent(47f); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(1f, 1f); par.Add(new Chunk(imgLogo, 0, 0)); par.Add(new Chunk("", f6)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 5; cel.Colspan = 2; encabezado.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(8f, 9f); par.Add(new Chunk(htCFDI["nombreEmisor"].ToString().ToUpper(), f6B)); par.Add(new Chunk("\nRFC " + htCFDI["rfcEmisor"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor1"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor2"].ToString().ToUpper(), f6)); par.Add(new Chunk("\n" + htCFDI["direccionEmisor3"].ToString().ToUpper(), f6)); par.Add(new Chunk("\nTel. (52) 55 5081-8500", f6)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 5; encabezado.AddCell(cel); StringBuilder expedido = new StringBuilder(); expedido. Append("Lugar de Expedición México DF\n"). Append(htCFDI["sucursal"]).Append("\n"). Append(htCFDI["direccionExpedido1"].ToString().ToUpper()).Append("\n"). Append(htCFDI["direccionExpedido2"].ToString().ToUpper()).Append("\n"). Append(htCFDI["direccionExpedido3"].ToString().ToUpper()).Append("\n"). Append(dtEncabezado.Rows[0]["corporateCode"]).Append("\n").//CE29 Append(dtEncabezado.Rows[0]["oldCorporateCode"].ToString()).Append("\n");//CE30; cel = new Cell(new Phrase(expedido.ToString(), f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.Rowspan = 5; encabezado.AddCell(cel); cel = new Cell(new Phrase(htCFDI["tipoDoc"].ToString(), titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase(htCFDI["serie"].ToString().ToUpper() + electronicDocument.Data.Folio.Value, f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase("Día", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("Mes", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase("Año", f6B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; encabezado.AddCell(cel); string[] fechaCFDI = Convert.ToDateTime(htCFDI["fechaCfdi"].ToString()).GetDateTimeFormats(); string HORAS = fechaCFDI[103]; string DIA = Convert.ToDateTime(htCFDI["fechaCfdi"]).Day.ToString(); string MES = Convert.ToDateTime(htCFDI["fechaCfdi"]).ToString("MMMM").ToUpper(); string ANIO = Convert.ToDateTime(htCFDI["fechaCfdi"]).Year.ToString(); cel = new Cell(new Phrase(DIA, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(MES, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(ANIO, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; encabezado.AddCell(cel); cel = new Cell(new Phrase(HORAS, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase("CLIENTE", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BackgroundColor = azul; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; encabezado.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Receptor.Nombre.Value, f6)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); cel = new Cell(new Phrase("Referencia Documento: " + dtEncabezado.Rows[0]["referencia"].ToString(), f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 1f); par.Add(new Chunk("R.F.C. " + electronicDocument.Data.Receptor.Rfc.Value + "\n", f5)); par.Add(new Chunk(htCFDI["direccionReceptor1"].ToString() + "\n", f5)); par.Add(new Chunk(htCFDI["direccionReceptor2"].ToString() + "\n", f5)); par.Add(new Chunk(htCFDI["direccionReceptor3"].ToString() + "\n", f5)); par.Add(new Chunk(dtEncabezado.Rows[0]["codigoCorporativo"] + "\n" + "\n", f5));//36 par.Add(new Chunk(dtEncabezado.Rows[0]["codigoCorporativoAnt"].ToString(), f5));//37 cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; cel.Rowspan = 5; cel.Colspan = 2; encabezado.AddCell(cel); #region "Consignado a" string nombreEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-NOMBRE"].ToString();//CE string calleEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-CALLE"].ToString();//CE 10, 11, 12 string coloniaEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-COLONIA"].ToString();//CE13 string cpEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-CP"].ToString();//CE18 string municEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-MUNIC"].ToString();//CE15 string estadoEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-ESTADO"].ToString();//CE16 string paisEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-PAIS"].ToString();//CE14 string intericom = dtEncabezado.Rows[0]["INTERICOM"].ToString().ToUpper();//CE32 string saltoEntregado = "\n"; string separador = ", "; string espacio = " "; if (nombreEntregado.Length > 0) nombreEntregado = nombreEntregado + saltoEntregado; else nombreEntregado = "" + saltoEntregado; if (calleEntregado.Length > 0) calleEntregado = calleEntregado + saltoEntregado; else calleEntregado = "" + saltoEntregado; if (coloniaEntregado.Length > 0) coloniaEntregado = coloniaEntregado + espacio; else coloniaEntregado = "" + espacio; if (cpEntregado.Length > 0) cpEntregado = cpEntregado + ", CP " + saltoEntregado; else cpEntregado = "" + separador + saltoEntregado; if (municEntregado.Length > 0) municEntregado = municEntregado + saltoEntregado; else municEntregado = ""; if (estadoEntregado.Length > 0) estadoEntregado = estadoEntregado + espacio; else estadoEntregado = "" + espacio; if (paisEntregado.Length > 0) paisEntregado = paisEntregado + ""; else paisEntregado = ""; if (intericom.Length > 0) intericom = intericom + espacio; else intericom = ""; #endregion par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 1f); par.Add(new Chunk("Consignado a:\n", f5B)); par.Add(new Chunk(calleEntregado, f5)); par.Add(new Chunk(coloniaEntregado, f5)); par.Add(new Chunk(cpEntregado, f5)); par.Add(new Chunk(municEntregado, f5)); par.Add(new Chunk(estadoEntregado, f5)); par.Add(new Chunk(paisEntregado, f5)); par.Add(new Chunk("INTERICOM:\n", f5)); par.Add(new Chunk(intericom, f5));//CE32 cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Rowspan = 5; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Contacto:\n", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["contacto"].ToString(), f5)); par.Add(new Chunk("\nTeléfono:\n", f5B)); par.Add(new Chunk("" + "\n", f5)); par.Add(new Chunk("Método de Pago:\n", f5B)); par.Add(new Chunk(electronicDocument.Data.FormaPago.Value, f5)); cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 5; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Fecha de Ref. Doc: ", f5B)); par.Add(new Chunk(dtEncabezado.Rows[0]["fechaRefDoc"].ToString(), f5));//CE34 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Moneda: ", f5B)); par.Add(new Chunk(electronicDocument.Data.Moneda.Value, f5)); cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Forma de Pago: ", f5B)); par.Add(new Chunk(electronicDocument.Data.FormaPago.Value.ToString(), f5)); cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Condiciones de Pago: ", f5B)); par.Add(new Chunk(electronicDocument.Data.CondicionesPago.Value.ToString(), f5));//CE19 cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 1f); par.Add(new Chunk("Proveedor: ", f5B)); par.Add(new Chunk("", f5)); cel = new Cell(par); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 3; encabezado.AddCell(cel); #endregion #region "Construimos Tablas de Partidas" #region "Construimos Encabezados de Partidas" Table encabezadoPartidas = new Table(9); float[] headerwidthsEncabesadoPartidas = { 10, 34, 7, 7, 7, 9, 8, 9, 9 }; encabezadoPartidas.Widths = headerwidthsEncabesadoPartidas; encabezadoPartidas.WidthPercentage = 100; encabezadoPartidas.Padding = 1; encabezadoPartidas.Spacing = 1; encabezadoPartidas.BorderWidth = (float).5; encabezadoPartidas.DefaultCellBorder = 1; encabezadoPartidas.BorderColor = gris; cel = new Cell(new Phrase("Codigo Producto.", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Descripción", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Cantidad", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Cantidad Real (Kg,Lt,Mt)", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Unidad Medida", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Precio Unitario", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Descuento", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Importe", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); cel = new Cell(new Phrase("Importe Neto", titulo)); cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BackgroundColor = azul; cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; encabezadoPartidas.AddCell(cel); #endregion #region "Construimos Contenido de las Partidas" Table partidas = new Table(9); float[] headerwidthsPartidas = { 10, 34, 7, 7, 7, 9, 8, 9, 9 }; partidas.Widths = headerwidthsPartidas; partidas.WidthPercentage = 100; partidas.Padding = 1; partidas.Spacing = 1; partidas.BorderWidth = (float).5; partidas.DefaultCellBorder = 1; partidas.BorderColor = gris; double sumDescuento = 0; if (dtEncabezado.Rows.Count > 0) { for (int i = 0; i < electronicDocument.Data.Conceptos.Count; i++) { cel = new Cell(new Phrase(dtDetalle.Rows[i]["codeLocal"].ToString(), f5));//CD1 cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; partidas.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Descripcion.Value, f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; partidas.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Cantidad.Value.ToString("N", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; partidas.AddCell(cel); cel = new Cell(new Phrase(dtDetalle.Rows[i]["cantidadReal"].ToString(), f5));//CD16 cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; partidas.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Unidad.Value, f5));//CD10 cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; partidas.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].ValorUnitario.Value.ToString("N", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; partidas.AddCell(cel); cel = new Cell(new Phrase(dtDetalle.Rows[i]["descuento"].ToString(), f5));//CD12 cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; partidas.AddCell(cel); if (double.TryParse(dtDetalle.Rows[i]["descuento"].ToString(), out sumDescuento)) sumDescuento += double.Parse(dtDetalle.Rows[i]["descuento"].ToString()); else sumDescuento += 0; cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Importe.Value.ToString("N", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; partidas.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Importe.Value.ToString("N", _ci), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; partidas.AddCell(cel); } } #endregion #endregion #region "Construimos el Comentarios" Table comentarios = new Table(7); float[] headerwidthsComentarios = { 9, 18, 28, 28, 7, 5, 5 }; comentarios.Widths = headerwidthsComentarios; comentarios.WidthPercentage = 100; comentarios.Padding = 1; comentarios.Spacing = 1; comentarios.BorderWidth = 0; comentarios.DefaultCellBorder = 0; comentarios.BorderColor = gris; cel = new Cell(new Phrase("Observaciones:", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Cantidad:", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Sub Total", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.SubTotal.Value.ToString(), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 4; comentarios.AddCell(cel); cel = new Cell(new Phrase("Descuento", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(sumDescuento.ToString(), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 4; comentarios.AddCell(cel); cel = new Cell(new Phrase("I.E.P.S.", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase("0", f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase(dtEncabezado.Rows[0]["observaciones"].ToString(), f5)); cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; cel.Rowspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase(dtEncabezado.Rows[0]["cantidadLetra"].ToString(), f5));//CE26 cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; cel.Rowspan = 2; comentarios.AddCell(cel); double importe = 0; double tasa = 0; for (int i = 0; i < electronicDocument.Data.Impuestos.Traslados.Count; i++) { if (electronicDocument.Data.Impuestos.Traslados[i].Tipo.Value == "IVA") { importe = electronicDocument.Data.Impuestos.Traslados[i].Importe.Value; tasa = electronicDocument.Data.Impuestos.Traslados[i].Tasa.Value; break; } } cel = new Cell(new Phrase("IVA " + tasa.ToString() + " %", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.TotalTraslados.Value.ToString(), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("Total", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Total.Value.ToString(), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Colspan = 4; comentarios.AddCell(cel); cel = new Cell(new Phrase("Total de Articulos", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; comentarios.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.Conceptos.Count.ToString(), f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; comentarios.AddCell(cel); #endregion #region "Construimos Tabla Especial" Table especial = new Table(5); float[] headerwidthsEspecial = { 20, 20, 20, 20, 20 }; especial.Widths = headerwidthsEspecial; especial.WidthPercentage = 100; especial.Padding = 1; especial.Spacing = 1; especial.BorderWidth = 0; especial.DefaultCellBorder = 0; especial.BorderColor = gris; cel = new Cell(new Phrase("", titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); cel = new Cell(new Phrase("", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); cel = new Cell(new Phrase("", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); cel = new Cell(new Phrase("", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); cel = new Cell(new Phrase("", f5B)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = (float).5; cel.BorderColor = gris; cel.Rowspan = 2; especial.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); cel = new Cell(new Phrase("", f5)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = (float).5; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = (float).5; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); cel = new Cell(new Phrase("", titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = 0; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; cel.Colspan = 2; especial.AddCell(cel); cel = new Cell(new Phrase("", titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); cel = new Cell(new Phrase("", titulo)); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_RIGHT; cel.BorderWidthTop = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthBottom = 0; cel.BorderColor = gris; especial.AddCell(cel); #endregion #region "Construimos Tabla de Datos CFDI" DefaultSplitCharacter split = new DefaultSplitCharacter(); Table adicional = new Table(3); float[] headerwidthsAdicional = { 20, 25, 55 }; adicional.Widths = headerwidthsAdicional; adicional.WidthPercentage = 100; adicional.Padding = 1; adicional.Spacing = 1; adicional.BorderWidth = (float).5; adicional.DefaultCellBorder = 1; adicional.BorderColor = gris; if (timbrar) { #region "Generamos Quick Response Code" byte[] bytesQRCode = new byte[0]; if (timbrar) { // Generamos el Quick Response Code (QRCode) string re = electronicDocument.Data.Emisor.Rfc.Value; string rr = electronicDocument.Data.Receptor.Rfc.Value; string tt = String.Format("{0:F6}", electronicDocument.Data.Total.Value); string id = objTimbre.Uuid.Value; StringBuilder sbCadenaQRCode = new StringBuilder(); sbCadenaQRCode. Append("?"). Append("re=").Append(re). Append("&"). Append("rr=").Append(rr). Append("&"). Append("tt=").Append(tt). Append("&"). Append("id=").Append(id); BarcodeLib.Barcode.QRCode.QRCode barcode = new BarcodeLib.Barcode.QRCode.QRCode(); barcode.Data = sbCadenaQRCode.ToString(); barcode.ModuleSize = 3; barcode.LeftMargin = 0; barcode.RightMargin = 10; barcode.TopMargin = 0; barcode.BottomMargin = 0; barcode.Encoding = BarcodeLib.Barcode.QRCode.QRCodeEncoding.Auto; barcode.Version = BarcodeLib.Barcode.QRCode.QRCodeVersion.Auto; barcode.ECL = BarcodeLib.Barcode.QRCode.ErrorCorrectionLevel.L; bytesQRCode = barcode.drawBarcodeAsBytes(); } #endregion Image imageQRCode = Image.GetInstance(bytesQRCode); imageQRCode.Alignment = (Image.TEXTWRAP | Image.ALIGN_LEFT); imageQRCode.ScaleToFit(90f, 90f); imageQRCode.IndentationLeft = 9f; imageQRCode.SpacingAfter = 9f; imageQRCode.BorderColorTop = Color.WHITE; cel = new Cell(imageQRCode); cel.VerticalAlignment = Element.ALIGN_MIDDLE; cel.HorizontalAlignment = Element.ALIGN_CENTER; cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = (float).5; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Rowspan = 6; adicional.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("SELLO DIGITAL DEL EMISOR\n", f5L)); par.Add(new Chunk(electronicDocument.Data.Sello.Value, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Colspan = 2; adicional.AddCell(cel); cel = new Cell(new Phrase("FOLIO FISCAL:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase(objTimbre.Uuid.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("FECHA Y HORA DE CERTIFICACION:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); string[] fechaTimbrado = Convert.ToDateTime(objTimbre.FechaTimbrado.Value).GetDateTimeFormats('s'); cel = new Cell(new Phrase(fechaTimbrado[0], f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL SAT:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase(objTimbre.NumeroCertificadoSat.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = 0; adicional.AddCell(cel); cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL EMISOR:", f5L)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; adicional.AddCell(cel); cel = new Cell(new Phrase(electronicDocument.Data.NumeroCertificado.Value, f5)); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = (float).5; cel.BorderWidthBottom = (float).5; adicional.AddCell(cel); string lbRegimen = "REGIMEN FISCAL APLICABLE: "; StringBuilder regimenes = new StringBuilder(); if (electronicDocument.Data.Emisor.Regimenes.IsAssigned) { for (int i = 0; i < electronicDocument.Data.Emisor.Regimenes.Count; i++) { regimenes.Append(electronicDocument.Data.Emisor.Regimenes[i].Regimen.Value).Append("\n"); } } else { regimenes.Append(""); lbRegimen = ""; } string cuenta = electronicDocument.Data.NumeroCuentaPago.IsAssigned ? electronicDocument.Data.NumeroCuentaPago.Value : ""; par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("TIPO DE COMPROBANTE: ", f5L)); par.Add(new Chunk(electronicDocument.Data.TipoComprobante.Value + " | ", f5)); par.Add(new Chunk("Moneda: ", f5L)); par.Add(new Chunk(electronicDocument.Data.Moneda.Value + " | ", f5)); par.Add(new Chunk("TASA DE CAMBIO: ", f5L)); string tasaCambio = electronicDocument.Data.TipoCambio.Value; if (tasaCambio.Length > 0) { par.Add(new Chunk(Convert.ToDouble(tasaCambio).ToString("C", _ci) + " | ", f5)); } else { par.Add(new Chunk(" | ", f5)); } par.Add(new Chunk("FORMA DE PAGO: ", f5L)); par.Add(new Chunk(electronicDocument.Data.FormaPago.Value + "\n", f5)); par.Add(new Chunk("MÉTODO DE PAGO: ", f5L)); par.Add(new Chunk(electronicDocument.Data.MetodoPago.Value + " | ", f5)); par.Add(new Chunk("NÚMERO DE CUENTA: ", f5L)); par.Add(new Chunk(cuenta + " | ", f5)); par.Add(new Chunk(lbRegimen, f5L)); par.Add(new Chunk(regimenes.ToString(), f5)); cel.BorderColor = gris; cel = new Cell(par); cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 2; cel.BorderColor = gris; adicional.AddCell(cel); par = new Paragraph(); par.SetLeading(7f, 0f); par.Add(new Chunk("CADENA ORIGINAL DEL COMPLEMENTO DE CERTIFICACIÓN DIGITAL DEL SAT\n", f5L)); par.Add(new Chunk(electronicDocument.FingerPrintPac, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = (float).5; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = (float).5; cel.Colspan = 3; adicional.AddCell(cel); par = new Paragraph(); par.KeepTogether = true; par.SetLeading(7f, 0f); par.Add(new Chunk("SELLO DIGITAL DEL SAT\n", f5L)); par.Add(new Chunk(objTimbre.SelloSat.Value, f5).SetSplitCharacter(split)); cel = new Cell(par); cel.BorderColor = gris; cel.BorderWidthTop = 0; cel.BorderWidthRight = 0; cel.BorderWidthLeft = 0; cel.BorderWidthBottom = 0; cel.Colspan = 3; adicional.AddCell(cel); } #endregion #region "Construimos Tabla del Footer" PdfPTable footer = new PdfPTable(1); footer.WidthPercentage = 100; footer.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; cell = new PdfPCell(new Phrase("", f5)); cell.BorderWidthTop = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.BorderWidthBottom = 0; footer.AddCell(cell); cell = new PdfPCell(new Phrase("ESTE DOCUMENTO ES UNA REPRESENTACIÓN IMPRESA DE UN CFDI", titulo)); cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = azul; cell.BorderWidthTop = 0; cell.BorderWidthLeft = 0; cell.BorderWidthRight = 0; cell.BorderWidthBottom = 0; footer.AddCell(cell); #endregion pageEventHandler.encabezado = encabezado; pageEventHandler.encPartidas = encabezadoPartidas; pageEventHandler.footer = footer; document.Open(); document.Add(partidas); document.Add(comentarios); document.Add(especial); document.Add(adicional); document.Close(); #endregion } catch (Exception ex) { string exe = ex.Message; } }
private void EscrevaProcessosNoDocumentoAnalitico() { var tabela = new Table(1); tabela.Widths = new Single[] { 218 }; tabela.Padding = 0; tabela.Spacing = 0; tabela.Width = 100; tabela.AutoFillEmptyCells = true; tabela.DefaultCell.Border = Rectangle.NO_BORDER; tabela.EndHeaders(); foreach (var revistaDePatente in _revistasPatentes) { var tabela1 = new Table(1); tabela1.Widths = new Single[] { 100 }; tabela1.Padding = 0; tabela1.Spacing = 0; tabela1.Width = 100; tabela1.AutoFillEmptyCells = true; tabela1.Border = 0; tabela1.EndHeaders(); tabela1.DefaultCell.Border = Rectangle.NO_BORDER; var tabelaProcesso = new Cell(ObtenhaTabelaCelulaProcesso(revistaDePatente)); tabela1.AddCell(tabelaProcesso); var tabelaRevistas = new Cell(ObtenhaTabelaInformacoesRevista(revistaDePatente)); tabela1.AddCell(tabelaRevistas); tabela.AddCell(new Cell(tabela1)); tabela.AddCell(ObtenhaCelulaVazia()); tabela.AddCell(ObtenhaCelulaVazia()); tabela.AddCell(ObtenhaCelulaVazia()); } _documento.Add(tabela); }
private void EscrevaProcessosNoDocumentoSintetico() { var tabela = new Table(4); tabela.Widths = new Single[] { 60, 100, 60, 100 }; tabela.Padding = 1; tabela.Spacing = 0; tabela.Width = 100; tabela.AutoFillEmptyCells = true; var corBackgroudHeader = new Color(211, 211, 211); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Número do processo", _Fonte2, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true)); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Marca", _Fonte2, Cell.ALIGN_LEFT, 0, corBackgroudHeader, true)); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Despacho", _Fonte2, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true)); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Cliente", _Fonte2, Cell.ALIGN_LEFT, 0, corBackgroudHeader, true)); tabela.EndHeaders(); foreach (var processo in _processos) { tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Processo.ToString(), _Fonte1, Cell.ALIGN_CENTER, 0, false)); if (processo.Marca != null && !string.IsNullOrEmpty(processo.Marca.DescricaoDaMarca)) tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Marca.DescricaoDaMarca, _Fonte1, Cell.ALIGN_LEFT, 0, false)); else tabela.AddCell(iTextSharpUtilidades.CrieCelula(string.Empty, _Fonte1, Cell.ALIGN_LEFT, 0, false)); tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Despacho != null ? processo.Despacho.CodigoDespacho : "", _Fonte1, Cell.ALIGN_CENTER, 0, false)); tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Marca.Cliente.Pessoa.Nome, _Fonte1, Cell.ALIGN_LEFT, 0, false)); } _documento.Add(tabela); }
/// <summary> /// 输出到PDF /// </summary> /// <param name="list"></param> /// <param name="sysFont"></param> /// <param name="multiRow"></param> /// <param name="export">算高度的情况最后输出时使用</param> /// <returns></returns> public Table WriteFields(List<List<PdfDesc>> list, System.Drawing.Font sysFont, int multiRow, bool export) { #region Variable Definition Cell cell = null; int maxColumnCount = -1; int maxRowCount = -1; LineSeparator lineSeparator = null; int tempCount = 0; int previousFieldCells = 0; Table tb = null; #endregion //try //{ Font pdfFont = this.GetPdfFont(sysFont); //Hashtable allStartIndex = new Hashtable(); Dictionary<int, int> allStartIndex = new Dictionary<int, int>(); if (export) { foreach (List<PdfDesc> row in list) { if (!allStartIndex.ContainsKey(row[0].FieldNum)) { allStartIndex.Add(row[0].FieldNum, list.IndexOf(row)); } } } else { allStartIndex.Add(0, 0); } List<int> startIndex = new List<int>(); foreach (int index in allStartIndex.Values) { startIndex.Add(index); } for (int l = 0; l < startIndex.Count; l++) { //計算最大Column和最大Row maxColumnCount = 0; if (startIndex.Count == 1) { maxRowCount = list.Count; } else if (l != startIndex.Count - 1) { maxRowCount = startIndex[l + 1] - startIndex[l]; } else { maxRowCount = list.Count - startIndex[l]; } for (int s = startIndex[l]; s < list.Count; s++) //foreach (List<PdfDesc> row in list) { if (startIndex.Count != 1) { if (l != startIndex.Count - 1 && s == startIndex[l + 1]) { break; } } List<PdfDesc> row = list[s]; foreach (PdfDesc pdfDesc in row) { tempCount += pdfDesc.Cells; } if (tempCount > maxColumnCount) { maxColumnCount = tempCount; } tempCount = 0; } tb = new Table(maxColumnCount, maxRowCount); #region 計算欄位寬度 if (multiRow == 1) { int[] widths = new int[maxColumnCount]; previousFieldCells = 0; List<PdfDesc> firstRow = list[startIndex[l]]; for (int i = 0; i < firstRow.Count; i++) { int widthPercent = Convert.ToInt32(Math.Truncate((UnitConversion.GetPdfLetterWidth(firstRow[i].Width, sysFont) / Convert.ToDouble((this.pdfDoc.PageSize.Width - this.pdfDoc.LeftMargin - this.pdfDoc.RightMargin))) * 100)); //算出百分比 if (i == 0) { widths[i] = widthPercent; if (firstRow[i].Cells > 1) { for (int j = 0; j < firstRow[i].Cells - 1; j++) { widths[i + j + 1] = widthPercent; } } } else { widths[previousFieldCells] = widthPercent; if (firstRow[i].Cells > 1) { for (int j = 0; j < firstRow[i].Cells - 1; j++) { widths[previousFieldCells + j + 1] = widthPercent; } } } previousFieldCells += firstRow[i].Cells; } tb.SetWidths(widths); previousFieldCells = 0; } #endregion if (!this.report.Format.ColumnGridLine) { tb.Border = Rectangle.NO_BORDER; } tb.Cellpadding = PdfSizeConfig.Cellpadding; //tb.Width = ((this.pdfDoc.PageSize.Width - this.pdfDoc.LeftMargin - this.pdfDoc.RightMargin) / this.pdfDoc.PageSize.Width) * 100; //此處為百分比 tb.Width = 100; tb.Alignment = Element.ALIGN_LEFT; for (int j = startIndex[l]; j < list.Count; j++) { if (startIndex.Count != 1) { if (l != startIndex.Count - 1 && j == startIndex[l + 1]) { break; } } List<PdfDesc> row = list[j]; previousFieldCells = 0; for (int i = 0; i < row.Count; i++) { PdfDesc pdfDesc = row[i]; switch (pdfDesc.GroupGap) { case DataSourceItem.GroupGapType.None: cell = new Cell(new Chunk(pdfDesc.Value, pdfFont)); cell.Colspan = pdfDesc.Cells; cell.HorizontalAlignment = this.GetPdfHAlignByStr(pdfDesc.HAlign); break; case DataSourceItem.GroupGapType.EmptyRow: if (i == 0) { cell = new Cell(new Chunk(String.Empty, pdfFont)); cell.Colspan = maxColumnCount; } break; case DataSourceItem.GroupGapType.SingleLine: if (i == 0) { cell = new Cell(); lineSeparator = new LineSeparator(); lineSeparator.LineWidth = cell.Width; lineSeparator.Offset = PdfSizeConfig.LineSeparatorOffsetU; cell.AddElement(lineSeparator); cell.Colspan = tb.Columns; } break; case DataSourceItem.GroupGapType.DoubleLine: if (i == 0) { cell = new Cell(); lineSeparator = new LineSeparator(); lineSeparator.LineWidth = cell.Width; lineSeparator.Offset = PdfSizeConfig.LineSeparatorOffsetU; cell.AddElement(lineSeparator); lineSeparator = new LineSeparator(); lineSeparator.LineWidth = cell.Width; lineSeparator.Offset = PdfSizeConfig.LineSeparatorOffsetD; cell.AddElement(lineSeparator); cell.Colspan = tb.Columns; } break; } cell.BorderWidthLeft = pdfDesc.LeftLine == true ? PdfSizeConfig.BorderWidth : PdfSizeConfig.BorderWidthZero; cell.BorderWidthRight = pdfDesc.RightLine == true ? PdfSizeConfig.BorderWidth : PdfSizeConfig.BorderWidthZero; cell.BorderWidthTop = pdfDesc.TopLine == true ? PdfSizeConfig.BorderWidth : PdfSizeConfig.BorderWidthZero; cell.BorderWidthBottom = pdfDesc.BottomLine == true ? PdfSizeConfig.BorderWidth : PdfSizeConfig.BorderWidthZero; if (j == list.Count - 1) { cell.BorderWidthBottom = report.Format.RowGridLine == true ? PdfSizeConfig.BorderWidth : PdfSizeConfig.BorderWidthZero; } cell.UseAscender = true; //此屬性設置為True的時候VerticalAlignment才會起作用 cell.VerticalAlignment = Cell.ALIGN_MIDDLE; switch (pdfDesc.GroupGap) { case DataSourceItem.GroupGapType.None: if (i == 0) { tb.AddCell(cell, j, i); } else { tb.AddCell(cell, j, previousFieldCells); } break; case DataSourceItem.GroupGapType.EmptyRow: case DataSourceItem.GroupGapType.SingleLine: case DataSourceItem.GroupGapType.DoubleLine: if (i == 0) { tb.AddCell(cell, j, i); } break; } previousFieldCells += pdfDesc.Cells; } } if (!ExportByHeight || export) { this.pdfDoc.Add(tb); } } //} //catch (Exception ex) //{ // log.WriteExceptionInfo(ex); // throw ex; //} return tb; }
private void EscrevaProcessosNoDocumentoAnalitico() { var tabela = new Table(6); tabela.Widths = new Single[] { 60, 100, 50, 100, 60, 100 }; tabela.Padding = 0; tabela.Spacing = 0; tabela.Width = 100; tabela.AutoFillEmptyCells = true; tabela.EndHeaders(); foreach (var processo in _processos) { var labelNumeroProcesso = new Cell(new Phrase("Número do processo: ", _Fonte2)); labelNumeroProcesso.DisableBorderSide(0); tabela.AddCell(labelNumeroProcesso); var valorNumeroProcesso = new Cell(new Phrase(processo.Processo.ToString(), _Fonte1)); valorNumeroProcesso.DisableBorderSide(0); tabela.AddCell(valorNumeroProcesso); var labelDataDoCadastro = new Cell(new Phrase("Data do cadastro: ", _Fonte2)); labelDataDoCadastro.DisableBorderSide(0); tabela.AddCell(labelDataDoCadastro); var valorDataDoCadastro = new Cell(new Phrase(processo.DataDoCadastro.ToString("dd/MM/yyyy"), _Fonte1)); valorDataDoCadastro.DisableBorderSide(0); tabela.AddCell(valorDataDoCadastro); var labelDespacho = new Cell(new Phrase("Despacho: ", _Fonte2)); labelDespacho.DisableBorderSide(0); tabela.AddCell(labelDespacho); var valorDespacho = processo.Despacho != null ? new Cell(new Phrase(processo.Despacho.CodigoDespacho, _Fonte1)) : new Cell(new Phrase(string.Empty, _Fonte1)); valorDespacho.DisableBorderSide(0); tabela.AddCell(valorDespacho); var labelApresentacao = new Cell(new Phrase("Apresentação: ", _Fonte2)); labelApresentacao.DisableBorderSide(0); tabela.AddCell(labelApresentacao); Cell valorApresentacao; if(processo.Marca != null && processo.Marca.Apresentacao != null) valorApresentacao = new Cell(new Phrase(processo.Marca.Apresentacao.Nome, _Fonte1)); else valorApresentacao = new Cell(new Phrase(string.Empty, _Fonte1)); valorApresentacao.DisableBorderSide(0); tabela.AddCell(valorApresentacao); var labelNatureza = new Cell(new Phrase("Natureza: ", _Fonte2)); labelNatureza.DisableBorderSide(0); tabela.AddCell(labelNatureza); Cell valorNatureza; if (processo.Marca != null && processo.Marca.Natureza != null) valorNatureza = new Cell(new Phrase(processo.Marca.Natureza.Nome, _Fonte1)); else valorNatureza = new Cell(new Phrase(string.Empty, _Fonte1)); valorNatureza.DisableBorderSide(0); tabela.AddCell(valorNatureza); var labelNCL = new Cell(new Phrase("NCL: ", _Fonte2)); labelNCL.DisableBorderSide(0); tabela.AddCell(labelNCL); Cell valorNCL; if (processo.Marca != null && processo.Marca.NCL != null) valorNCL = new Cell(new Phrase(processo.Marca.NCL.Codigo, _Fonte1)); else valorNCL = new Cell(new Phrase(string.Empty, _Fonte1)); valorNCL.DisableBorderSide(0); tabela.AddCell(valorNCL); var labelCliente = new Cell(new Phrase("Cliente: ", _Fonte2)); labelCliente.DisableBorderSide(0); tabela.AddCell(labelCliente); var valorCliente = new Cell(new Phrase(processo.Marca.Cliente.Pessoa.Nome, _Fonte1)) { Colspan = 5 }; valorCliente.DisableBorderSide(0); tabela.AddCell(valorCliente); var labelMarca = new Cell(new Phrase("Marca: ", _Fonte2)); labelMarca.DisableBorderSide(0); tabela.AddCell(labelMarca); Cell valorMarca; if (processo.Marca != null && !string.IsNullOrEmpty(processo.Marca.DescricaoDaMarca)) valorMarca = new Cell(new Phrase(processo.Marca.DescricaoDaMarca, _Fonte1)); else valorMarca = new Cell(new Phrase(string.Empty, _Fonte1)); valorMarca.Colspan = 5; valorMarca.DisableBorderSide(0); tabela.AddCell(valorMarca); var labelApostila = new Cell(new Phrase("Apostila: ", _Fonte2)); labelApostila.DisableBorderSide(0); tabela.AddCell(labelApostila); Cell valorApostila; if (!string.IsNullOrEmpty(processo.Apostila)) valorApostila = new Cell(new Phrase(processo.Apostila, _Fonte1)); else valorApostila = new Cell(new Phrase(string.Empty, _Fonte1)); valorApostila.Colspan = 5; valorApostila.DisableBorderSide(0); tabela.AddCell(valorApostila); var labelTextoDespacho = new Cell(new Phrase("Texto do Despacho: ", _Fonte2)); labelTextoDespacho.DisableBorderSide(0); tabela.AddCell(labelTextoDespacho); Cell valorTextoDespacho; if (!string.IsNullOrEmpty(processo.TextoComplementarDoDespacho)) valorTextoDespacho = new Cell(new Phrase(processo.Apostila, _Fonte1)); else valorTextoDespacho = new Cell(new Phrase(string.Empty, _Fonte1)); valorTextoDespacho.Colspan = 5; valorTextoDespacho.DisableBorderSide(0); tabela.AddCell(valorTextoDespacho); var labelProcurador = new Cell(new Phrase("Procurador: ", _Fonte2)); labelProcurador.DisableBorderSide(0); tabela.AddCell(labelProcurador); Cell valorProcurador; if (processo.Procurador != null && processo.Procurador.Pessoa != null && !string.IsNullOrEmpty(processo.Procurador.Pessoa.Nome)) valorProcurador = new Cell(new Phrase(processo.Procurador.Pessoa.Nome, _Fonte1)); else valorProcurador = new Cell(new Phrase(string.Empty, _Fonte1)); valorProcurador.Colspan = 5; valorProcurador.DisableBorderSide(0); tabela.AddCell(valorProcurador); var linhaVazia = new Cell(new Phrase("\n", _Fonte1)); linhaVazia.Colspan = 6; linhaVazia.DisableBorderSide(1); tabela.AddCell(linhaVazia); } _documento.Add(tabela); }
public Table WriteItem(List<List<object>> lists, System.Drawing.Font sysFont) { #region Variable Definition //int tempCount = 0; int cellCount = 0; int maxColumnCount = -1; Font pdfFont = null; Table tb = null; Image image = null; string imagePath = String.Empty; float imageWidth = float.Epsilon; Cell cell = null; double height = 0.0; #endregion //try //{ pdfFont = this.GetPdfFont(sysFont); //计算Table中最大的Column数。 #region Old Function //foreach (List<object> list in lists) //{ // foreach (ReportItem item in list) // { // tempCount += item.Cells; // } // if (tempCount > maxColumnCount) // { // maxColumnCount = tempCount; // } // tempCount = 0; //} #endregion maxColumnCount = mPageWidth; if (lists.Count == 0) { return tb; } tb = new Table(maxColumnCount, lists.Count); tb.Border = Rectangle.NO_BORDER; tb.Cellpadding = PdfSizeConfig.Cellpadding; //tb.Width = ((this.pdfDoc.PageSize.Width - this.pdfDoc.LeftMargin - this.pdfDoc.RightMargin) / this.pdfDoc.PageSize.Width) * 100; //此處為百分比 tb.Width = 100; tb.Alignment = Element.ALIGN_LEFT; foreach (List<object> list in lists) { cellCount = 0; height += GetHeight(list, sysFont); for (int i = 0; i < list.Count; i++) { if (list[i].GetType().Name != "ReportImageItem") { if (((ReportItem)list[i]).Font == null) { pdfFont = this.GetPdfFont(sysFont); } else { pdfFont = this.GetPdfFont(((ReportItem)list[i]).Font); } string value = ""; string format = ""; if (string.IsNullOrEmpty(((ReportItem)list[i]).Format)) { if (list[i] is ReportDataSourceItem) { DDProvider ddProvider = new DDProvider(report.HeaderDataSource, mDesignTime); string ddValue = ddProvider.GetDDValue(((ReportDataSourceItem)list[i]).ColumnName, DDInfo.FieldCaption).ToString(); if (ddValue == "") { ddValue = ddProvider.GetDDValue(((ReportDataSourceItem)list[i]).ColumnName, DDInfo.FieldName).ToString(); } format = ddValue + ":{0}"; } else { format = "{0}"; } } else { format = ((ReportItem)list[i]).Format; } value = string.IsNullOrEmpty(((ReportItem)list[i]).Format) ? string.Format(format, ((ReportItem)list[i]).Value) : String.Format(format, ((ReportItem)list[i]).Value); cell = new Cell(new Chunk(value, pdfFont)); } else { #region Image Item image = Image.GetInstance((System.Drawing.Image)((ReportItem)list[i]).Value, System.Drawing.Imaging.ImageFormat.Jpeg); image.Alignment = this.GetPdfImageHAlign(((ReportItem)list[i]).ContentAlignment); if (list.Count > 1) { imageWidth = (this.pdfDoc.PageSize.Width - this.pdfDoc.LeftMargin - this.pdfDoc.RightMargin) / (float)list.Count; //imageWidth -= (float)16; //image.ScaleAbsoluteWidth(imageWidth); } Chunk chuck = new Chunk(image, 0, 0, true); cell = new Cell(chuck); #endregion } cell.UseAscender = true; //此屬性設置為True的時候VerticalAlignment才會起作用 cell.VerticalAlignment = Cell.ALIGN_MIDDLE; cell.HorizontalAlignment = this.GetPdfHAlign(((ReportItem)list[i]).ContentAlignment); if (((ReportItem)list[i]).Cells == 0) { if (tb.Columns - cellCount != 0) { cell.Colspan = tb.Columns - cellCount; } } else { cell.Colspan = ((ReportItem)list[i]).Cells; } cell.Border = Rectangle.NO_BORDER; if (((ReportItem)list[i]).Position == ReportItem.PositionAlign.Right && ((ReportItem)list[i]).Cells != 0) { if (maxColumnCount - cellCount - ((ReportItem)list[i]).Cells != 0) { Cell tempCell = new Cell(); tempCell.Colspan = maxColumnCount - cellCount - ((ReportItem)list[i]).Cells; tempCell.Border = Rectangle.NO_BORDER; tb.AddCell(tempCell); cellCount = maxColumnCount - ((ReportItem)list[i]).Cells; } } if (i == 0 && ((ReportItem)list[i]).Position != ReportItem.PositionAlign.Right) { tb.AddCell(cell, lists.IndexOf(list), i); } else { tb.AddCell(cell, lists.IndexOf(list), cellCount); } cellCount += ((ReportItem)list[i]).Cells; } } if (ExportByHeight) { if (HeaderTable == null && object.ReferenceEquals(sysFont, report.HeaderFont)) { HeaderTable = tb; if (HeaderHeight == 0.0) { HeaderHeight = height; } } else if (FooterTable == null && object.ReferenceEquals(sysFont, report.FooterFont)) { FooterTable = tb; if (FooterHeight == 0.0) { FooterHeight = height; } } } else { this.pdfDoc.Add(tb); } //} //catch (Exception ex) //{ // log.WriteExceptionInfo(ex); // throw ex; //} return tb; }
protected void btnpdf_Click(object sender, ImageClickEventArgs e) { HttpContext.Current.Response.ContentType = "Application/PDF"; HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename= MIS_Teacher.pdf"); StringWriter sw = new StringWriter(); HtmlTextWriter tw = new HtmlTextWriter(sw); if (ddltch.Text == "-All-") { string qry1 = "Select sms_teacher.Teacher_Name, sms_teacher.Teacher_ID, sms_teacher.Subject_Code, sms_subject_master.Subject_Name, sms_teacher.School_Code, sms_school_master.School_Name, sms_school_master.Dist_Code, Dist_List.Dist_Name from (((sms_teacher inner join sms_school_master on sms_teacher.School_Code = sms_school_master.School_Code) inner join Dist_List on sms_school_master.Dist_Code = Dist_List.Dist_Code) inner join sms_subject_master on sms_teacher.Subject_Code = sms_subject_master.Subject_ID) order by sms_teacher.Teacher_Name"; SqlCommand cmd = new SqlCommand(qry1, con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); iTextSharp.text.Table tb = new iTextSharp.text.Table(4); tb.BorderWidth = 0.6f; tb.BorderColor = new Color(0, 0, 0); tb.CellsFitPage = true; tb.Padding = 2; tb.Width = 90; //Single widths = new Single() [ 5, 5]; //tb.Widths = widths; if (ds.Tables[0].Rows.Count > 0) { DataTable dt; dt = ds.Tables[0]; Paragraph p31 = new Paragraph("Teacher", new Font(Font.TIMES_ROMAN, 11, Font.BOLD)); iTextSharp.text.Cell tcell_1 = new iTextSharp.text.Cell(p31); tcell_1.Header = true; tcell_1.HorizontalAlignment = Element.ALIGN_CENTER; tcell_1.BackgroundColor = Color.LIGHT_GRAY; tb.AddCell(tcell_1); tb.EndHeaders(); Paragraph p32 = new Paragraph("Subject", new Font(Font.TIMES_ROMAN, 11, Font.BOLD)); iTextSharp.text.Cell tcell_2 = new iTextSharp.text.Cell(p32); tcell_2.Header = true; tcell_2.HorizontalAlignment = Element.ALIGN_CENTER; tcell_2.BackgroundColor = Color.LIGHT_GRAY; tb.AddCell(tcell_2); tb.EndHeaders(); Paragraph p33 = new Paragraph("School", new Font(Font.TIMES_ROMAN, 11, Font.BOLD)); iTextSharp.text.Cell tcell_3 = new iTextSharp.text.Cell(p33); tcell_3.Header = true; tcell_3.HorizontalAlignment = Element.ALIGN_CENTER; tcell_3.BackgroundColor = Color.LIGHT_GRAY; tb.AddCell(tcell_3); tb.EndHeaders(); Paragraph p34 = new Paragraph("District", new Font(Font.TIMES_ROMAN, 11, Font.BOLD)); iTextSharp.text.Cell tcell_4 = new iTextSharp.text.Cell(p34); tcell_4.Header = true; tcell_4.HorizontalAlignment = Element.ALIGN_CENTER; tcell_4.BackgroundColor = Color.LIGHT_GRAY; tb.AddCell(tcell_4); tb.EndHeaders(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { Paragraph p11; Paragraph p12; Paragraph p13; Paragraph p14; p11 = new Paragraph(ds.Tables[0].Rows[i]["Teacher_Name"].ToString(), new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); p12 = new Paragraph(ds.Tables[0].Rows[i]["Subject_Name"].ToString(), new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); p13 = new Paragraph(ds.Tables[0].Rows[i]["School_Name"].ToString(), new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); p14 = new Paragraph(ds.Tables[0].Rows[i]["Dist_Name"].ToString(), new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); iTextSharp.text.Cell tcell_p111 = new iTextSharp.text.Cell(p11); tcell_p111.HorizontalAlignment = Element.ALIGN_CENTER; tb.AddCell(tcell_p111); iTextSharp.text.Cell tcell_p112 = new iTextSharp.text.Cell(p12); tcell_p112.HorizontalAlignment = Element.ALIGN_CENTER; tb.AddCell(tcell_p112); iTextSharp.text.Cell tcell_p113 = new iTextSharp.text.Cell(p13); tcell_p113.HorizontalAlignment = Element.ALIGN_CENTER; tb.AddCell(tcell_p113); iTextSharp.text.Cell tcell_p114 = new iTextSharp.text.Cell(p14); tcell_p114.HorizontalAlignment = Element.ALIGN_CENTER; tb.AddCell(tcell_p114); } } StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A4, 2, 2, 2, 1); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, HttpContext.Current.Response.OutputStream); PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream); String pcnt; pcnt = (writer.CurrentPageNumber - 1).ToString(); pcnt = pcnt.Substring(1); pdfDoc.Open(); pdfDoc.Add(new Paragraph(" MIS Teachers")); pdfDoc.Add(tb); pdfDoc.Close(); HttpContext.Current.Response.Write(pdfDoc); HttpContext.Current.Response.End(); } else { string qry1 = "Select sms_teacher.Teacher_Name, sms_teacher.Teacher_ID, sms_teacher.Subject_Code, sms_subject_master.Subject_Name, sms_teacher.School_Code, sms_school_master.School_Name, sms_school_master.Dist_Code, Dist_List.Dist_Name from ((sms_teacher inner join sms_school_master on sms_teacher.School_Code = sms_school_master.School_Code) inner join Dist_List on sms_school_master.Dist_Code = Dist_List.Dist_Code) inner join sms_subject_master on sms_teacher.Subject_Code=sms_subject_master.Subject_ID) order by sms_teacher.Teacher_Name where sms_teacher.Teacher_ID='" + ddltch.SelectedItem.Value + "' "; SqlCommand cmd = new SqlCommand(qry1, con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); iTextSharp.text.Table tb = new iTextSharp.text.Table(4); tb.BorderWidth = 0.6f; tb.BorderColor = new Color(0, 0, 0); tb.CellsFitPage = true; tb.Padding = 2; tb.Width = 90; //Single widths = new Single() [ 5, 5]; //tb.Widths = widths; if (ds.Tables[0].Rows.Count > 0) { DataTable dt; dt = ds.Tables[0]; Paragraph p31 = new Paragraph("Teacher", new Font(Font.TIMES_ROMAN, 11, Font.BOLD)); iTextSharp.text.Cell tcell_1 = new iTextSharp.text.Cell(p31); tcell_1.Header = true; tcell_1.HorizontalAlignment = Element.ALIGN_CENTER; tcell_1.BackgroundColor = Color.LIGHT_GRAY; tb.AddCell(tcell_1); tb.EndHeaders(); Paragraph p32 = new Paragraph("Subject", new Font(Font.TIMES_ROMAN, 11, Font.BOLD)); iTextSharp.text.Cell tcell_2 = new iTextSharp.text.Cell(p32); tcell_2.Header = true; tcell_2.HorizontalAlignment = Element.ALIGN_CENTER; tcell_2.BackgroundColor = Color.LIGHT_GRAY; tb.AddCell(tcell_2); tb.EndHeaders(); Paragraph p33 = new Paragraph("School", new Font(Font.TIMES_ROMAN, 11, Font.BOLD)); iTextSharp.text.Cell tcell_3 = new iTextSharp.text.Cell(p33); tcell_3.Header = true; tcell_3.HorizontalAlignment = Element.ALIGN_CENTER; tcell_3.BackgroundColor = Color.LIGHT_GRAY; tb.AddCell(tcell_3); tb.EndHeaders(); Paragraph p34 = new Paragraph("District", new Font(Font.TIMES_ROMAN, 11, Font.BOLD)); iTextSharp.text.Cell tcell_4 = new iTextSharp.text.Cell(p34); tcell_4.Header = true; tcell_4.HorizontalAlignment = Element.ALIGN_CENTER; tcell_4.BackgroundColor = Color.LIGHT_GRAY; tb.AddCell(tcell_4); tb.EndHeaders(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { Paragraph p11; Paragraph p12; Paragraph p13; Paragraph p14; p11 = new Paragraph(ds.Tables[0].Rows[i]["Teacher_Name"].ToString(), new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); p12 = new Paragraph(ds.Tables[0].Rows[i]["Subject_Name"].ToString(), new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); p13 = new Paragraph(ds.Tables[0].Rows[i]["School_Name"].ToString(), new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); p14 = new Paragraph(ds.Tables[0].Rows[i]["Dist_Name"].ToString(), new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); iTextSharp.text.Cell tcell_p111 = new iTextSharp.text.Cell(p11); tcell_p111.HorizontalAlignment = Element.ALIGN_CENTER; tb.AddCell(tcell_p111); iTextSharp.text.Cell tcell_p112 = new iTextSharp.text.Cell(p12); tcell_p112.HorizontalAlignment = Element.ALIGN_CENTER; tb.AddCell(tcell_p112); iTextSharp.text.Cell tcell_p113 = new iTextSharp.text.Cell(p13); tcell_p113.HorizontalAlignment = Element.ALIGN_CENTER; tb.AddCell(tcell_p113); iTextSharp.text.Cell tcell_p114 = new iTextSharp.text.Cell(p14); tcell_p114.HorizontalAlignment = Element.ALIGN_CENTER; tb.AddCell(tcell_p114); } } StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A4, 2, 2, 2, 1); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, HttpContext.Current.Response.OutputStream); PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream); String pcnt; pcnt = (writer.CurrentPageNumber - 1).ToString(); pcnt = pcnt.Substring(1); pdfDoc.Open(); pdfDoc.Add(new Paragraph(" MIS Teachers")); pdfDoc.Add(tb); pdfDoc.Close(); HttpContext.Current.Response.Write(pdfDoc); HttpContext.Current.Response.End(); } }
// methods to set the membervariables /** * Adds an element to this Cell. * <P> * Remark: you can't add ListItems, Rows, Cells, * JPEGs, GIFs or PNGs to a Cell. * * @param element The Element to add * @throws BadElementException if the method was called with a ListItem, Row or Cell */ /// <summary> /// Adds an element to this Cell. /// </summary> /// <remarks> /// You can't add ListItems, Rows, Cells, /// JPEGs, GIFs or PNGs to a Cell. /// </remarks> /// <param name="element">the Element to add</param> public void AddElement(IElement element) { if (IsTable()) { Table table = (Table) arrayList[0]; Cell tmp = new Cell(element); tmp.Border = NO_BORDER; tmp.Colspan = table.Columns; table.AddCell(tmp); return; } switch (element.Type) { case Element.LISTITEM: case Element.ROW: case Element.CELL: throw new BadElementException("You can't add listitems, rows or cells to a cell."); case Element.JPEG: case Element.IMGRAW: case Element.IMGTEMPLATE: arrayList.Add(element); break; case Element.LIST: if (float.IsNaN(this.Leading)) { leading = ((List) element).Leading; } if (((List) element).Size == 0) return; arrayList.Add(element); return; case Element.ANCHOR: case Element.PARAGRAPH: case Element.PHRASE: if (float.IsNaN(leading)) { leading = ((Phrase) element).Leading; } if (((Phrase) element).IsEmpty()) return; arrayList.Add(element); return; case Element.CHUNK: if (((Chunk) element).IsEmpty()) return; arrayList.Add(element); return; case Element.TABLE: Table table = new Table(3); float[] widths = new float[3]; widths[1] = ((Table)element).WidthPercentage; switch (((Table)element).Alignment) { case Element.ALIGN_LEFT: widths[0] = 0f; widths[2] = 100f - widths[1]; break; case Element.ALIGN_CENTER: widths[0] = (100f - widths[1]) / 2f; widths[2] = widths[0]; break; case Element.ALIGN_RIGHT: widths[0] = 100f - widths[1]; widths[2] = 0f; break; } table.Widths = widths; Cell tmp; if (arrayList.Count == 0) { table.AddCell(Cell.DummyCell); } else { tmp = new Cell(); tmp.Border = NO_BORDER; tmp.Colspan = 3; foreach (IElement ele in arrayList) { tmp.Add(ele); } table.AddCell(tmp); } tmp = new Cell(); tmp.Border = NO_BORDER; table.AddCell(tmp); table.InsertTable((Table)element); tmp = new Cell(); tmp.Border = NO_BORDER; table.AddCell(tmp); table.AddCell(Cell.DummyCell); Clear(); arrayList.Add(table); return; default: arrayList.Add(element); break; } }