private void addLargeFooter(Document doc) { iTextSharp.text.Font text = FontFactory.GetFont("Verdana", 12, iTextSharp.text.Font.NORMAL, BaseColor.Black); Paragraph p = new Paragraph(); p.Alignment = Element.ALIGN_LEFT; DottedLineSeparator dottedline = new DottedLineSeparator(); dottedline.Offset = 0; dottedline.Gap = 2f; //p.Add(dottedline); Chunk chunk1 = new Chunk("\n\nFind det detaljerede program og andre oplysninger på http://www.bffis.dk", text); Chunk chunk2 = new Chunk("\n\nTilmelding foretages på http://www.bffis.dk/Tilmelding.aspx", text); p.Add(chunk1); p.Add(chunk2); doc.Add(p); }
private void addFooter(Document doc) { iTextSharp.text.Font text = FontFactory.GetFont("Verdana", 12, iTextSharp.text.Font.NORMAL, BaseColor.Black); iTextSharp.text.Font textLink = FontFactory.GetFont("Verdana", 14, iTextSharp.text.Font.UNDERLINE, BaseColor.Blue); Paragraph p = new Paragraph(); p.Alignment = Element.ALIGN_LEFT; DottedLineSeparator dottedline = new DottedLineSeparator(); dottedline.Offset = 0; dottedline.Gap = 2f; //p.Add(dottedline); Chunk chunk1 = new Chunk("\n\nDet detaljerede program og andre oplysninger på foreningens hjemmeside ", text); Chunk chunk2 = new Chunk("http://www.bffis.dk", textLink); p.Add(chunk1); p.Add(chunk2); doc.Add(p); }
public void MakePdf() { string str1 = DateTime.Today.ToString("u"); string str2 = str1.Replace(':', 's'); string str3 = str2.Replace(',', 'd'); // string filname = DateTime.Today.ToString(""); string fileNamePrifix = customerNameBox.Text.Trim(); string final_fileName = fileNamePrifix + str3; string dirctory = Path.GetDirectoryName(@"C:\Users\Public\"); DirectoryInfo df = new DirectoryInfo(dirctory + @"\voucher\"); if (df.Exists == false) { Directory.CreateDirectory(dirctory + @"\voucher\"); } string filePath = df + final_fileName; Document document = new Document(PageSize.A4, 75, 75, 75, 75); PdfWriter create = PdfWriter.GetInstance(document, new FileStream(filePath + ".pdf", FileMode.Create)); document.Open(); // Font Entry BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); iTextSharp.text.Font hedingfont = new iTextSharp.text.Font(bf, 30, iTextSharp.text.Font.BOLD, BaseColor.BLUE); iTextSharp.text.Font smfont = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD, BaseColor.BLACK); iTextSharp.text.Font thfont = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD, BaseColor.BLACK); iTextSharp.text.Font tdfont = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.NORMAL, BaseColor.BLACK); iTextSharp.text.Font signfont = new iTextSharp.text.Font(bf, 11, iTextSharp.text.Font.BOLD, BaseColor.BLACK); signfont.SetColor(23, 45, 12); byte[] image = introduce.loadLogo(); if (image != null) { Image logo = Image.GetInstance(image); logo.SetAbsolutePosition(40, 700); logo.ScaleAbsoluteWidth(70); logo.ScaleAbsoluteHeight(70); document.Add(logo); } // Customer Data Paragraph Header = new Paragraph(); Header.Alignment = Element.ALIGN_CENTER; IntroduceModel introduction = introduce.GetInformation(); if (introduction != null) { string instituteBox = introduction.InstituteName; string emailBox = introduction.Email; string addresss = introduction.Address; string web = introduction.WebSite; string mobiles = introduction.Mobile; string ownerName = introduction.OwnerName; Header.Add(new Chunk(instituteBox, hedingfont)); Header.Add(new Chunk("\n" + addresss, smfont)); Header.Add(new Chunk("\nCell :" + mobiles + ", \n " + web + " , " + emailBox, smfont)); document.Add(Header); } else { Header.Add(new Chunk("It is Your Institute Name", hedingfont)); Header.Add(new Chunk("\nSomething Address text will visible here", smfont)); Header.Add(new Chunk("\nCell : -9087948059830, \n Web: N/A, Email: N/A ", smfont)); document.Add(Header); } DottedLineSeparator separator = new DottedLineSeparator(); separator.LineWidth = 1f; Chunk linebreak = new Chunk(separator); document.Add(linebreak); string customerName = customerNameBox.Text.Trim(); string address = addressTextBox.Text.Trim(); string mobile = mnumberBox.Text.Trim(); Paragraph csdata = new Paragraph(); csdata.Alignment = Element.ALIGN_LEFT; csdata.Add(new Chunk("Customer Name : " + customerName + "\nAddress : " + address + "\nMabile Number : " + mobile + "\n Date : " + DateTime.Now.ToString("dd/MM/yyyy"), smfont)); document.Add(csdata); DottedLineSeparator separator2 = new DottedLineSeparator(); separator2.LineWidth = 1f; Chunk linebreak2 = new Chunk(separator2); document.Add(linebreak2); //Write the table float[] columnWidths = { 1.5f, 7f, 2.2f, 4f }; PdfPTable ItemsRecord = new PdfPTable(columnWidths); ItemsRecord.DefaultCell.Column.Alignment = Element.ALIGN_CENTER; ItemsRecord.WidthPercentage = 100; ItemsRecord.DefaultCell.PaddingBottom = 4f; ItemsRecord.AddCell(new Phrase("Sl", thfont)); ItemsRecord.AddCell(new Phrase("Product Description", thfont)); ItemsRecord.AddCell(new Phrase("Quantity", thfont)); ItemsRecord.AddCell(new Phrase("Net Price", thfont)); //table Data var totalQuantity = listofStockOut.Sum(x => x.Quantity); var totalamount = listofStockOut.Sum(x => x.Price).ToString(CultureInfo.CreateSpecificCulture("bn-BD")); int ci = 0; int lc = listofStockOut.Count; foreach (var items in listofStockOut) { if (ci <= lc) { ci++; } ItemsRecord.AddCell(new Phrase(ci.ToString(), tdfont)); ItemsRecord.AddCell(new Phrase(items.CatagoryName + " : " + items.ItemName + " Sl/Mo:" + items.Model, tdfont)); ItemsRecord.AddCell(new Phrase(items.Quantity.ToString(), tdfont)); ItemsRecord.AddCell(new Phrase(items.Price.ToString(), tdfont)); } PdfPCell cell = new PdfPCell(new Phrase("Total : ", tdfont)); cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.Colspan = 2; ItemsRecord.AddCell(cell); ItemsRecord.AddCell(new Phrase(totalQuantity.ToString(), tdfont)); ItemsRecord.AddCell(new Phrase(totalamount, tdfont)); document.Add(ItemsRecord); document.Add(new Chunk("\n\n\n")); //Author Paragraph prgAuthor = new Paragraph(); prgAuthor.Alignment = Element.ALIGN_CENTER; prgAuthor.IndentationLeft = 250f; prgAuthor.Add(new Chunk("Received by", signfont)); prgAuthor.Add(new Chunk("\n" + DateTime.Now.ToString("dd/MM/yyyy"), signfont)); document.Add(prgAuthor); document.Add(new Chunk("\n\n\n")); DottedLineSeparator separator4 = new DottedLineSeparator(); separator4.LineWidth = 1f; Chunk linebreak4 = new Chunk(separator4); document.Add(linebreak4); document.Add(new Chunk("\nN:B: \n")); DottedLineSeparator separator5 = new DottedLineSeparator(); separator5.LineWidth = 1f; Chunk linebreak5 = new Chunk(separator5); document.Add(linebreak5); document.Add(new Chunk("\n")); document.Close(); create.Close(); System.Diagnostics.Process.Start(filePath + ".pdf"); }
public MemoryStream DownloadDeliveryPackage(ReportFilter reportFilter) { var pdfData = new MemoryStream(); var document = new Document(PageSize.A4, 35, 35, 25, 50); var pdfWriter = PdfWriter.GetInstance(document, pdfData); pdfWriter.ViewerPreferences = PdfWriter.PageLayoutOneColumn; // Our custom Header and Footer is done using Event Handler var pageEventHandler = new TwoColumnHeaderFooter(); pdfWriter.PageEvent = pageEventHandler; // Define the page header //pageEventHandler.Title = title; //pageEventHandler.HeaderFont = FontFactory.GetFont(BaseFont.COURIER_BOLD, 10, Font.BOLD); //pageEventHandler.HeaderLeft = "Group"; //pageEventHandler.HeaderRight = "1"; var filePath = System.IO.Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "Content\\Fonts", "times.ttf"); BaseFont baseFont = BaseFont.CreateFont("C:\\Windows\\Fonts\\times.ttf", BaseFont.IDENTITY_H, true); var fontBold = new Font(baseFont, 11, Font.BOLD, BaseColor.BLACK); Font defaultFont = new Font(baseFont, 14, Font.NORMAL, BaseColor.BLACK); document.Open(); //Add header //var myCompany = new Chunk("VPDD CTY TNHH TM VC TRUNG THÀNH", defaultFont); //document.Add(myCompany); //document.Add(new Phrase("\n")); //var myCompanyAddress = new Chunk("Đ/C: SỐ 17 NGÁCH 43 NGÕ 64 NG.LƯƠNG BẰNG - ĐỐNG ĐA - HN", defaultFont); //document.Add(myCompanyAddress); //document.Add(new Phrase("\n")); //var myCompanyContact = new Chunk("SĐT: 04.3514.9969 FAX: 04.3573.9119", defaultFont); //document.Add(myCompanyContact); //document.Add(new Paragraph("\r\n")); //var myTitle = new Paragraph("DANH SÁCH ĐƠN HÀNG CẦN GIAO", new Font(baseFont, 22, Font.BOLD, BaseColor.BLACK)); //myTitle.Alignment = Element.ALIGN_CENTER; //document.Add(myTitle); //document.Add(new Paragraph("\r\n")); //From - To Rectangle pageSize = document.PageSize; //Report date //var dateReport = new Chunk(" NGÀY: " + DateTime.Now.ToString("dd/MM/yyyy HH:mm"), defaultFont); //document.Add(dateReport); //document.Add(new Paragraph("\r\n")); //Add rows var no = 1; var model = GetDeliveryPackage(reportFilter); foreach (var item in model) { var line1 = new Chunk(string.Format("KHÁCH HÀNG: {0} ĐT: {1}", item.CustomerName, item.CustomerPhone), defaultFont); document.Add(line1); document.Add(new Phrase("\n")); var line2 = new Chunk(string.Format("NƠI ĐẾN: {0}", item.CustomerAddress), defaultFont); document.Add(line2); document.Add(new Phrase("\n")); var products = ""; foreach (var product in item.ProductReportModels) { products += string.Format("Mẫu {0}, SL {1}; ", product.CategoryName, product.Amount); } var line3 = new Chunk(products, defaultFont); document.Add(line3); document.Add(new Phrase("\n")); var line4 = new Chunk(string.Format("Số tiền thu hộ: {0} (Bằng chữ: {1})", String.Format("{0:0,0}", item.Total), NumberToWords.ChangeCurrencyToWords(item.Total)), defaultFont); document.Add(line4); document.Add(new Phrase("\n")); var line5 = new Chunk(string.Format("Khách hàng đến lấy: {0} Chuyển hàng: {1}", item.PaymentType == (int)PaymentTypes.InOffice ? "X" : "", item.PaymentType == (int)PaymentTypes.InShippingPlace ? "X" : ""), defaultFont); document.Add(line5); document.Add(new Phrase("\n")); var line6 = new Chunk(string.Format("Nhà xe: {0} ĐT: {1}", item.ShippingServiceName, item.ShippingServicePhone), defaultFont); document.Add(line6); document.Add(new Phrase("\n")); var line7 = new Chunk(string.Format("Đ/c nhà xe: {0} Giờ xe chạy: {1}", item.ShippingAddress, (item.StartAt.HasValue ? item.StartAt.Value.ToString("dd/MM/yyyy HH:mm") : "")), defaultFont); document.Add(line7); document.Add(new Phrase("\n")); DottedLineSeparator separator = new DottedLineSeparator(); //separator.s(59500f / 523f); Chunk linebreak = new Chunk(separator); document.Add(linebreak); document.Add(new Paragraph("\r\n")); no++; } document.Close(); return(pdfData); }
public override void MontaCorpoDados() { base.MontaCorpoDados(); #region Cabeçalho do Relatório PdfPTable table = new PdfPTable(8); BaseColor preto = new BaseColor(0, 0, 0); BaseColor fundo = new BaseColor(200, 200, 200); Font font = FontFactory.GetFont("Verdana", 8, Font.NORMAL, preto); Font titulo = FontFactory.GetFont("Verdana", 8, Font.BOLD, preto); float[] colsW = { 14, 10, 7, 7, 7, 7, 5, 6 }; table.SetWidths(colsW); //table.HeaderRows = 1; repetir cabeçalho em todas paginas table.WidthPercentage = 100f; table.DefaultCell.Border = PdfPCell.BOTTOM_BORDER; table.DefaultCell.BorderColor = preto; table.DefaultCell.BorderColorBottom = new BaseColor(255, 255, 255); table.DefaultCell.Padding = 10; table.AddCell(GetNovaCelula("Cliente", titulo, Element.ALIGN_LEFT, 2, PdfPCell.BOTTOM_BORDER, preto, fundo)); table.AddCell(GetNovaCelula("Centro Custo", titulo, Element.ALIGN_LEFT, 2, PdfPCell.BOTTOM_BORDER, preto, fundo)); table.AddCell(GetNovaCelula("Emissão", titulo, Element.ALIGN_CENTER, 2, PdfPCell.BOTTOM_BORDER, preto, fundo)); table.AddCell(GetNovaCelula("Recebimento", titulo, Element.ALIGN_CENTER, 2, PdfPCell.BOTTOM_BORDER, preto, fundo)); table.AddCell(GetNovaCelula("Vencimento", titulo, Element.ALIGN_CENTER, 2, PdfPCell.BOTTOM_BORDER, preto, fundo)); table.AddCell(GetNovaCelula("Situação", titulo, Element.ALIGN_CENTER, 2, PdfPCell.BOTTOM_BORDER, preto, fundo)); table.AddCell(GetNovaCelula("Vlr Total", titulo, Element.ALIGN_CENTER, 2, PdfPCell.BOTTOM_BORDER, preto, fundo)); table.AddCell(GetNovaCelula("Vlr Pago", titulo, Element.ALIGN_CENTER, 2, PdfPCell.BOTTOM_BORDER, preto, fundo)); #endregion var parcelas = new FinanceiroContasReceberParcelasRepository().GetContasReceberReport(DataInicial, DataFinal, Status, PesquisaTexto); decimal totalPago = 0; decimal totalAberto = 0; decimal totalVencidos = 0; var dataAtual = DateTime.Now; foreach (var parcela in parcelas) { table.AddCell(GetNovaCelula(parcela.ClienteNome, font, Element.ALIGN_LEFT, 2, PdfPCell.BOTTOM_BORDER)); table.AddCell(GetNovaCelula(parcela.CentroCustoDescricao, font, Element.ALIGN_LEFT, 5, PdfPCell.BOTTOM_BORDER)); table.AddCell(GetNovaCelula(parcela.DataEmissao.IsValidDate(), font, Element.ALIGN_CENTER, 5, PdfPCell.BOTTOM_BORDER)); table.AddCell(GetNovaCelula(parcela.DataRecebimento.IsValidDate(), font, Element.ALIGN_CENTER, 5, PdfPCell.BOTTOM_BORDER)); table.AddCell(GetNovaCelula(parcela.DataVencimento.IsValidDate(), font, Element.ALIGN_CENTER, 5, PdfPCell.BOTTOM_BORDER)); table.AddCell(GetNovaCelula(parcela.SituacaoParcelaFinanceira.ToString(), font, Element.ALIGN_CENTER, 5, PdfPCell.BOTTOM_BORDER)); table.AddCell(GetNovaCelula(parcela.ValorTotalLiquido.ToString("N"), font, Element.ALIGN_CENTER, 5, PdfPCell.BOTTOM_BORDER)); table.AddCell(GetNovaCelula(parcela.ValorLiquidado.ToString("N"), font, Element.ALIGN_CENTER, 5, PdfPCell.BOTTOM_BORDER)); totalPago += parcela.ValorLiquidado; if (parcela.SituacaoParcelaFinanceira == SituacaoParcelaFinanceira.Aberto) { totalAberto += parcela.ValorTotalLiquido; } if (parcela.DataVencimento < dataAtual && parcela.SituacaoParcelaFinanceira == SituacaoParcelaFinanceira.Aberto) { totalVencidos += parcela.ValorTotalLiquido; } } doc.Add(table); DottedLineSeparator dottedline = new DottedLineSeparator(); dottedline.Offset = -2; dottedline.Gap = 2f; var paragraph = new Paragraph(); paragraph.Add(dottedline); doc.Add(paragraph); Font fontTotais = FontFactory.GetFont("Arial", 8, Font.NORMAL, preto); Phrase phrase; doc.Add(new Chunk("\n\n")); var totalVencidoParagraph = new Paragraph(); totalVencidoParagraph.Alignment = Element.ALIGN_RIGHT; phrase = new Phrase(string.Format("Total Vencidas: {0}", totalVencidos.ToString("N")), fontTotais); totalVencidoParagraph.Add(phrase); doc.Add(totalVencidoParagraph); var totalAbertoParagraph = new Paragraph(); totalAbertoParagraph.Alignment = Element.ALIGN_RIGHT; phrase = new Phrase(string.Format("Total Aberto: {0}", totalAberto.ToString("N")), fontTotais); totalAbertoParagraph.Add(phrase); doc.Add(totalAbertoParagraph); var totalPagoParagraph = new Paragraph(); totalPagoParagraph.Alignment = Element.ALIGN_RIGHT; phrase = new Phrase(string.Format("Total Liquidado: {0}", totalPago.ToString("N")), fontTotais); totalPagoParagraph.Add(phrase); doc.Add(totalPagoParagraph); }
private void AddHeader(string year, Document doc, bool simple = false) { iTextSharp.text.Font header = FontFactory.GetFont("Arial", 22, iTextSharp.text.Font.BOLD, BaseColor.Black); iTextSharp.text.Font subHeader = FontFactory.GetFont("Arial", 14, iTextSharp.text.Font.BOLD, BaseColor.Black); iTextSharp.text.Font subHeader2 = FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.NORMAL, BaseColor.Black); Paragraph p = new Paragraph(); p.Alignment = Element.ALIGN_CENTER; Chunk hdrChunk = new Chunk("Børnefritidsforeningen i Sydhavnen\n\n", header); Chunk subChunk = new Chunk("Program " + year + "\n\n", subHeader); Chunk subChunk2 = new Chunk("Alle aktiviteter foregår på skolen i Sydhavnen, Støberigade 1, 2450 København SV\n\n", subHeader2); iTextSharp.text.Image img = null; string imgPath = Path.Combine(Directory.GetCurrentDirectory(), "images/" + "play1.png"); if (File.Exists(imgPath)) { img = iTextSharp.text.Image.GetInstance(imgPath); img.ScaleToFit(50, 50f); img.Alignment = iTextSharp.text.Image.TEXTWRAP | iTextSharp.text.Image.ALIGN_LEFT; img.IndentationLeft = 1f; img.SpacingAfter = 1f; img.BorderWidthTop = 1f; img.BorderColorTop = iTextSharp.text.BaseColor.White; doc.Add(img); } else { Console.WriteLine("Kan ikke finde billedet banner.png"); } p.Add(hdrChunk); p.Add(subChunk); p.Add(subChunk2); iTextSharp.text.Image img1 = null; string img1Path = Path.Combine(Directory.GetCurrentDirectory(), "images/" + "play2.png"); if (File.Exists(img1Path)) { img1 = iTextSharp.text.Image.GetInstance(img1Path); img1.ScaleToFit(50, 50f); img1.Alignment = iTextSharp.text.Image.TEXTWRAP | iTextSharp.text.Image.ALIGN_RIGHT; img1.IndentationLeft = 1f; img1.SpacingAfter = 1f; img1.BorderWidthTop = 1f; img1.BorderColorTop = iTextSharp.text.BaseColor.White; doc.Add(img1); } else { Console.WriteLine("Kan ikke finde billedet banner.png"); } DottedLineSeparator dottedline = new DottedLineSeparator(); dottedline.Offset = 0; dottedline.Gap = 2f; p.Add(dottedline); p.Add(new Chunk("\n\n\n")); doc.Add(p); }
private void AddTeam(Hold team, Document doc, bool addSeparator) { iTextSharp.text.Font header = FontFactory.GetFont("Arial", 16, iTextSharp.text.Font.BOLD, BaseColor.Black); iTextSharp.text.Font boldText = FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.BOLD, BaseColor.Black); iTextSharp.text.Font descFont = FontFactory.GetFont("Verdana", 12, iTextSharp.text.Font.NORMAL, BaseColor.DarkGray); iTextSharp.text.Font text = FontFactory.GetFont("Verdana", 12, iTextSharp.text.Font.NORMAL, BaseColor.Black); iTextSharp.text.Font textRed = FontFactory.GetFont("Verdana", 12, iTextSharp.text.Font.NORMAL, BaseColor.Red); iTextSharp.text.Image img = null; if (string.IsNullOrEmpty(team.Image) == false) { string imgPath = Path.Combine(Directory.GetCurrentDirectory(), "images/" + team.Image); if (File.Exists(imgPath)) { img = iTextSharp.text.Image.GetInstance(imgPath); img.ScaleToFit(120f, 120f); img.Alignment = iTextSharp.text.Image.TEXTWRAP | iTextSharp.text.Image.ALIGN_RIGHT; img.IndentationLeft = 9f; img.SpacingAfter = 9f; img.BorderWidthTop = 16f; img.BorderColorTop = iTextSharp.text.BaseColor.White; } else { Console.WriteLine("Kan ikke finde billedet " + team.Image); } } Paragraph p = new Paragraph(); p.Alignment = Element.ALIGN_JUSTIFIED; Chunk nameChunk = new Chunk(team.Name, header); Chunk ageChunk = new Chunk(" for " + team.Age + "\n\n", text); p.Add(nameChunk); p.Add(ageChunk); iTextSharp.text.List list = new iTextSharp.text.List(iTextSharp.text.List.UNORDERED, 10f); list.SetListSymbol("\u2022"); list.IndentationLeft = 20f; list.Add("Ansvarlig Instruktør : " + team.Responsible); list.Add("Yderligere Instruktør(er) : " + team.Assistent); list.Add("Tidspunkt : " + team.WeekDay + " " + team.Time + " i " + team.Place); list.Add("Deltagere : " + team.Min + " til " + team.Max); list.Add("Pris : " + team.Price); list.Add("Opstart : " + team.StartDate); p.Add(list); Paragraph p1 = new Paragraph(); Chunk descChunk = new Chunk("\n\n" + team.Description + "\n\n", descFont); p1.Add(descChunk); if (string.IsNullOrWhiteSpace(team.HalfSeason) == false && team.HalfSeason.ToLowerInvariant() != "nej") { Chunk halfSeason = new Chunk("Bemærk", boldText); Chunk halfSeason2 = new Chunk(" Dette hold udbydes kun for en halv sæson og løber indtil " + team.HalfSeason, text); p1.Add(halfSeason); p1.Add(halfSeason2); } if (string.IsNullOrWhiteSpace(team.Status)) { Chunk extraInfo = new Chunk("\nHoldet er endnu ikke helt på plads ( " + team.Comments + ")", textRed); p1.Add(extraInfo); } if (addSeparator) { p1.Add(new Chunk("\n\n")); DottedLineSeparator dottedline = new DottedLineSeparator(); dottedline.Offset = 0; dottedline.Gap = 2f; p1.Add(dottedline); p1.Add(new Chunk("\n\n")); } if (img != null) { doc.Add(img); } doc.Add(p); doc.Add(p1); }
/// <summary> /// Output printable file to the path of tmpFile. /// </summary> /// <param name="title"></param> /// <param name="printRows"></param> /// <param name="tmpFile"></param> public static void StartPrint(string title, List <PrintRow> printRows, string tmpFile) { iTextSharp.text.io.StreamUtil.AddToResourceSearch(System.Reflection.Assembly.Load("iTextAsian")); BaseFont baseFont = BaseFont.CreateFont("MHei-Medium", "UniCNS-UCS2-H", BaseFont.NOT_EMBEDDED); Font headFont = new Font(baseFont, 14); Font contentFont = new Font(baseFont, 9); Document doc = new Document(PageSize.A4); if (!Directory.Exists(Path.GetTempPath() + @"PrintFileTemp\")) { Directory.CreateDirectory(Path.GetTempPath() + @"PrintFileTemp\"); } var output = new FileStream(Path.Combine(Path.GetTempPath() + @"PrintFileTemp\", tmpFile), FileMode.Create); var writer = PdfWriter.GetInstance(doc, output); PrintHeaderFooter pageEventHandler = new PrintHeaderFooter(); pageEventHandler.Title = !String.IsNullOrEmpty(title) ? title : " "; pageEventHandler.ProgramCode = "Dinp02401"; pageEventHandler.ReportCode = "Dinp02401r"; writer.PageEvent = pageEventHandler; doc.SetMargins(36, 36, 36 + 14 * 4, 36); doc.Open(); PdfPTable contentTable = new PdfPTable(pageEventHandler.FieldList1.Length); contentTable.WidthPercentage = 100; contentTable.SetWidths(pageEventHandler.FieldList1.Select(o => (float)o.Length).ToArray()); for (int i = 0; i < printRows.Count; i++) { var printRow = printRows[i]; PdfPCell pcodeCell = new PdfPCell(new Phrase(printRow.inf29a05_pcode, contentFont)); pcodeCell.Border = Rectangle.NO_BORDER; contentTable.AddCell(pcodeCell); PdfPCell productNameCell = new PdfPCell(new Phrase(printRow.inf29a33_product_name, contentFont)); productNameCell.Border = Rectangle.NO_BORDER; contentTable.AddCell(productNameCell); PdfPCell unitCell = new PdfPCell(new Phrase(printRow.inf29a17_runit, contentFont)); unitCell.Border = Rectangle.NO_BORDER; contentTable.AddCell(unitCell); PdfPCell customCodeNameCell = new PdfPCell(new Phrase(printRow.Inf2903CustomerCodeName, contentFont)); customCodeNameCell.Border = Rectangle.NO_BORDER; contentTable.AddCell(customCodeNameCell); PdfPCell inReasonCell = new PdfPCell(new Phrase(printRow.Inf2910InReasonName, contentFont)); inReasonCell.Border = Rectangle.NO_BORDER; contentTable.AddCell(inReasonCell); PdfPCell proDateCell = new PdfPCell(new Phrase(printRow.inf2904_pro_date.ToString("yyyy/MM/dd"), contentFont)); proDateCell.Border = Rectangle.NO_BORDER; contentTable.AddCell(proDateCell); PdfPCell priceCell = new PdfPCell(new Phrase(printRow.inf29a39_price, contentFont)); priceCell.Border = Rectangle.NO_BORDER; priceCell.HorizontalAlignment = Element.ALIGN_RIGHT; contentTable.AddCell(priceCell); PdfPCell costCell = new PdfPCell(new Phrase(printRow.inf29a10_ocost_one.ToString("0.00"), contentFont)); costCell.Border = Rectangle.NO_BORDER; costCell.HorizontalAlignment = Element.ALIGN_RIGHT; contentTable.AddCell(costCell); PdfPCell retailCell = new PdfPCell(new Phrase(printRow.inf29a09_oretail_one.ToString("0"), contentFont)); retailCell.Border = Rectangle.NO_BORDER; retailCell.HorizontalAlignment = Element.ALIGN_RIGHT; contentTable.AddCell(retailCell); PdfPCell qtyCell = new PdfPCell(new Phrase(printRow.inf29a13_sold_qty.ToString("0"), contentFont)); qtyCell.Border = Rectangle.NO_BORDER; qtyCell.HorizontalAlignment = Element.ALIGN_RIGHT; contentTable.AddCell(qtyCell); PdfPCell totalPriceCell = new PdfPCell(new Phrase(printRow.TotalPrice.ToString("0"), contentFont)); totalPriceCell.Border = Rectangle.NO_BORDER; totalPriceCell.HorizontalAlignment = Element.ALIGN_RIGHT; contentTable.AddCell(totalPriceCell); } doc.Add(contentTable); DottedLineSeparator separator = new DottedLineSeparator(); separator.Gap = 2f; doc.Add(separator); PdfPTable summaryTable = new PdfPTable(8); summaryTable.WidthPercentage = 100; PdfPCell costSumTitleCell = new PdfPCell(new Phrase("進價總額:", contentFont)); costSumTitleCell.Border = Rectangle.NO_BORDER; costSumTitleCell.HorizontalAlignment = Element.ALIGN_LEFT; summaryTable.AddCell(costSumTitleCell); PdfPCell costSumCell = new PdfPCell(new Phrase(printRows.Sum(o => o.inf29a10_ocost_one).ToString("0"), contentFont)); costSumCell.Border = Rectangle.NO_BORDER; costSumCell.HorizontalAlignment = Element.ALIGN_CENTER; summaryTable.AddCell(costSumCell); PdfPCell retailSumTitleCell = new PdfPCell(new Phrase("售價總額:", contentFont)); retailSumTitleCell.Border = Rectangle.NO_BORDER; retailSumTitleCell.HorizontalAlignment = Element.ALIGN_CENTER; summaryTable.AddCell(retailSumTitleCell); PdfPCell retailSumCell = new PdfPCell(new Phrase(printRows.Sum(o => o.inf29a09_oretail_one).ToString("0"), contentFont)); retailSumCell.Border = Rectangle.NO_BORDER; retailSumCell.HorizontalAlignment = Element.ALIGN_CENTER; summaryTable.AddCell(retailSumCell); PdfPCell priceSumTitleCell = new PdfPCell(new Phrase("單價總額:", contentFont)); priceSumTitleCell.Border = Rectangle.NO_BORDER; priceSumTitleCell.HorizontalAlignment = Element.ALIGN_CENTER; summaryTable.AddCell(priceSumTitleCell); PdfPCell priceSumCell = new PdfPCell( new Phrase( printRows.Sum(o => Convert.ToDouble(o.inf29a39_price == "" ? "0" : o.inf29a39_price)) .ToString("0"), contentFont)); priceSumCell.Border = Rectangle.NO_BORDER; priceSumCell.HorizontalAlignment = Element.ALIGN_CENTER; summaryTable.AddCell(priceSumCell); PdfPCell qtySumTitleCell = new PdfPCell(new Phrase("筆數:", contentFont)); qtySumTitleCell.Border = Rectangle.NO_BORDER; qtySumTitleCell.HorizontalAlignment = Element.ALIGN_CENTER; summaryTable.AddCell(qtySumTitleCell); PdfPCell qtySumCell = new PdfPCell(new Phrase(Convert.ToString(printRows.Sum(o => (int)o.inf29a13_sold_qty)), contentFont)); qtySumCell.Border = Rectangle.NO_BORDER; qtySumCell.HorizontalAlignment = Element.ALIGN_CENTER; summaryTable.AddCell(qtySumCell); doc.Add(summaryTable); doc.Close(); }
public override void MontaCorpoDados() { base.MontaCorpoDados(); #region Cabeçalho do Relatório PdfPTable table = new PdfPTable(4); BaseColor preto = new BaseColor(0, 0, 0); BaseColor vermelho = new BaseColor(255, 0, 0); BaseColor verde = new BaseColor(0, 210, 0); BaseColor fundo = new BaseColor(200, 200, 200); Font font = FontFactory.GetFont("Verdana", 8, Font.NORMAL, preto); Font fontCredito = FontFactory.GetFont("Verdana", 8, Font.NORMAL, verde); Font fontDebito = FontFactory.GetFont("Verdana", 8, Font.NORMAL, vermelho); Font titulo = FontFactory.GetFont("Verdana", 8, Font.BOLD, preto); float[] colsW = { 14, 7, 12, 10 }; table.SetWidths(colsW); //table.HeaderRows = 1; repetir cabeçalho em todas paginas table.WidthPercentage = 100f; table.DefaultCell.Border = PdfPCell.BOTTOM_BORDER; table.DefaultCell.BorderColor = preto; table.DefaultCell.BorderColorBottom = new BaseColor(255, 255, 255); table.DefaultCell.Padding = 10; table.AddCell(GetNovaCelula("Centro Custo", titulo, Element.ALIGN_LEFT, 2, PdfPCell.BOTTOM_BORDER, preto, fundo)); table.AddCell(GetNovaCelula("Tipo", titulo, Element.ALIGN_CENTER, 2, PdfPCell.BOTTOM_BORDER, preto, fundo)); table.AddCell(GetNovaCelula("Data", titulo, Element.ALIGN_CENTER, 2, PdfPCell.BOTTOM_BORDER, preto, fundo)); table.AddCell(GetNovaCelula("Crédito/Débito", titulo, Element.ALIGN_CENTER, 2, PdfPCell.BOTTOM_BORDER, preto, fundo)); #endregion var movimentacoes = new FinanceiroMovimentacoesRepository().GetMovimentacoesReport(DataInicial, DataFinal, Tipo, PesquisaTexto); decimal totalCredito = 0; decimal totalDebito = 0; decimal saldo = 0; foreach (var movimentacao in movimentacoes) { var fontCreditoDebito = movimentacao.TipoMovimentacao == TipoMovimentacao.Debito ? fontDebito : fontCredito; table.AddCell(GetNovaCelula(movimentacao.CentroCustoDescricao, font, Element.ALIGN_LEFT, 2, PdfPCell.BOTTOM_BORDER)); table.AddCell(GetNovaCelula(movimentacao.TipoMovimentacaoDescricao, fontCreditoDebito, Element.ALIGN_CENTER, 5, PdfPCell.BOTTOM_BORDER)); table.AddCell(GetNovaCelula(movimentacao.DataHora.ToString("G"), font, Element.ALIGN_CENTER, 5, PdfPCell.BOTTOM_BORDER)); table.AddCell(GetNovaCelula(movimentacao.CreditoDebito.ToString("N"), font, Element.ALIGN_CENTER, 5, PdfPCell.BOTTOM_BORDER)); if (movimentacao.TipoMovimentacao == TipoMovimentacao.Credito) { totalCredito += movimentacao.CreditoDebito; } if (movimentacao.TipoMovimentacao == TipoMovimentacao.Debito) { totalDebito += movimentacao.CreditoDebito; } } doc.Add(table); DottedLineSeparator dottedline = new DottedLineSeparator(); dottedline.Offset = -2; dottedline.Gap = 2f; var paragraph = new Paragraph(); paragraph.Add(dottedline); doc.Add(paragraph); Font fontTotais = FontFactory.GetFont("Arial", 8, Font.NORMAL, preto); Font fontSaldo = FontFactory.GetFont("Arial", 8, Font.BOLD, preto); Phrase phrase; doc.Add(new Chunk("\n\n")); var totalVencidoParagraph = new Paragraph(); totalVencidoParagraph.Alignment = Element.ALIGN_RIGHT; fontTotais.Color = verde; phrase = new Phrase(string.Format("Total Crédito: {0}", totalCredito.ToString("N")), fontTotais); totalVencidoParagraph.Add(phrase); doc.Add(totalVencidoParagraph); var totalAbertoParagraph = new Paragraph(); totalAbertoParagraph.Alignment = Element.ALIGN_RIGHT; fontTotais.Color = vermelho; phrase = new Phrase(string.Format("Total Débito: {0}", totalDebito.ToString("N")), fontTotais); totalAbertoParagraph.Add(phrase); doc.Add(totalAbertoParagraph); var totalPagoParagraph = new Paragraph(); totalPagoParagraph.Alignment = Element.ALIGN_RIGHT; phrase = new Phrase(string.Format("Saldo: {0}", (totalCredito - totalDebito).ToString("N")), fontSaldo); totalPagoParagraph.Add(phrase); doc.Add(totalPagoParagraph); }