public MemoryStream GeneratePdfTemplate(VBRealizationDocumentNonPOViewModel viewModel, int timeoffsset) { const int MARGIN = 20; const int MARGIN_VERTICAL = 10; Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 18); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11); Font normal_font_8 = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11); Font bold_font_8 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font note_font = FontFactory.GetFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font bold_italic_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12); Font Title_bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 13); Document document = new Document(PageSize.A4, MARGIN_VERTICAL, MARGIN_VERTICAL, MARGIN, MARGIN); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); #region Header PdfPTable headerTable_A = new PdfPTable(2); PdfPTable headerTable_B = new PdfPTable(1); PdfPTable headerTable_C = new PdfPTable(1); PdfPTable headerTable1 = new PdfPTable(1); PdfPTable headerTable2 = new PdfPTable(1); PdfPTable headerTable3 = new PdfPTable(7); PdfPTable headerTable3a = new PdfPTable(5); PdfPTable headerTable3b = new PdfPTable(5); PdfPTable headerTable4 = new PdfPTable(2); headerTable_A.SetWidths(new float[] { 10f, 10f }); headerTable_A.WidthPercentage = 100; headerTable3.SetWidths(new float[] { 5f, 15f, 15f, 15f, 20f, 15f, 20f }); headerTable3.WidthPercentage = 110; headerTable3a.SetWidths(new float[] { 3f, 15f, 5f, 15f, 62f }); headerTable3a.WidthPercentage = 110; headerTable3b.SetWidths(new float[] { 3f, 15f, 5f, 15f, 62f }); headerTable3b.WidthPercentage = 110; headerTable4.SetWidths(new float[] { 10f, 40f }); headerTable4.WidthPercentage = 100; PdfPCell cellHeader1 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader3 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader4 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader3a = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody1 = new PdfPCell() { }; PdfPCell cellHeaderBody1a = new PdfPCell() { BorderWidthTop = 2 }; PdfPCell cellHeaderBody1a1 = new PdfPCell() { }; PdfPCell cellHeaderBody1a2 = new PdfPCell() { }; PdfPCell cellHeaderBody1b = new PdfPCell() { BorderWidthTop = 2 }; PdfPCell cellHeaderBody1b1 = new PdfPCell() { }; PdfPCell cellHeaderBody1b2 = new PdfPCell() { }; PdfPCell cellHeaderBody1c = new PdfPCell() { }; PdfPCell cellHeaderBody2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody3 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody4 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody4a = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody4b = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody5 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody5a = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody6 = new PdfPCell() { }; cellHeader1.AddElement(headerTable1); headerTable_A.AddCell(cellHeader1); cellHeader2.AddElement(headerTable2); headerTable_A.AddCell(cellHeader2); document.Add(headerTable_A); cellHeaderBody.HorizontalAlignment = Element.ALIGN_LEFT; cellHeaderBody1.HorizontalAlignment = Element.ALIGN_CENTER; cellHeaderBody1a.HorizontalAlignment = Element.ALIGN_RIGHT; cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_RIGHT; cellHeaderBody1a2.HorizontalAlignment = Element.ALIGN_RIGHT; cellHeaderBody1b.HorizontalAlignment = Element.ALIGN_CENTER; cellHeaderBody1b1.HorizontalAlignment = Element.ALIGN_CENTER; cellHeaderBody1b2.HorizontalAlignment = Element.ALIGN_CENTER; cellHeaderBody1c.HorizontalAlignment = Element.ALIGN_CENTER; cellHeaderBody2.HorizontalAlignment = Element.ALIGN_CENTER; cellHeaderBody3.HorizontalAlignment = Element.ALIGN_RIGHT; cellHeaderBody4.HorizontalAlignment = Element.ALIGN_CENTER; cellHeaderBody4a.HorizontalAlignment = Element.ALIGN_CENTER; cellHeaderBody4b.HorizontalAlignment = Element.ALIGN_LEFT; cellHeaderBody5.HorizontalAlignment = Element.ALIGN_RIGHT; cellHeaderBody5a.HorizontalAlignment = Element.ALIGN_CENTER; cellHeaderBody6.HorizontalAlignment = Element.ALIGN_LEFT; // Document title cellHeaderBody2.Colspan = 7; cellHeaderBody2.Phrase = new Phrase("REALISASI VB INKLARING TANPA PO", bold_font); headerTable3.AddCell(cellHeaderBody2); // Document number cellHeaderBody3.Colspan = 7; cellHeaderBody3.Phrase = new Phrase($"{viewModel.DocumentNo}", bold_font); headerTable3.AddCell(cellHeaderBody3); // Realisasi VB Bagian cellHeaderBody3.Colspan = 7; cellHeaderBody3.HorizontalAlignment = Element.ALIGN_LEFT; // Override default to right cellHeaderBody3.Phrase = new Phrase($"Realisasi VB Bagian: {viewModel.Unit.Name}", bold_font); headerTable3.AddCell(cellHeaderBody3); // Tanggal cellHeaderBody3.Colspan = 7; cellHeaderBody3.HorizontalAlignment = Element.ALIGN_LEFT; // Override default to right cellHeaderBody3.Phrase = new Phrase($"Tanggal: {viewModel.Date?.AddHours(timeoffsset).ToString("dd MMMM yyyy", new CultureInfo("id-ID"))}", bold_font); headerTable3.AddCell(cellHeaderBody3); // New line cellHeaderBody3.Phrase = new Phrase(" ", normal_font); headerTable3.AddCell(cellHeaderBody3); // Table header cellHeaderBody1.Phrase = new Phrase("No", normal_font); headerTable3.AddCell(cellHeaderBody1); cellHeaderBody1.Phrase = new Phrase("Tanggal", normal_font); headerTable3.AddCell(cellHeaderBody1); cellHeaderBody1.Colspan = 2; cellHeaderBody1.Phrase = new Phrase("Keterangan", normal_font); headerTable3.AddCell(cellHeaderBody1); cellHeaderBody1.Colspan = 1; cellHeaderBody1.Phrase = new Phrase("No. BL / AWB", normal_font); headerTable3.AddCell(cellHeaderBody1); cellHeaderBody1.Phrase = new Phrase("Mata Uang", normal_font); headerTable3.AddCell(cellHeaderBody1); cellHeaderBody1.Phrase = new Phrase("Jumlah", normal_font); headerTable3.AddCell(cellHeaderBody1); int index = 1; /*decimal count_price = 0;*/ /*decimal total_all = 0;*/ decimal total_realization = 0; decimal ppn_manually = 0; decimal pph_supplier = 0; decimal pph_danliris = 0; var currencyCode = viewModel.Currency.Code; var currencydescription = viewModel.Currency.Description; foreach (var itm in viewModel.Items) { // No cellHeaderBody1.Phrase = new Phrase(index.ToString(), normal_font); cellHeaderBody1.HorizontalAlignment = Element.ALIGN_CENTER; headerTable3.AddCell(cellHeaderBody1); index++; // Tanggal cellHeaderBody1.Phrase = new Phrase(itm.DateDetail?.AddHours(timeoffsset).ToString("dd/MM/yyyy"), normal_font); headerTable3.AddCell(cellHeaderBody1); // Keterangan cellHeaderBody1.Colspan = 2; cellHeaderBody1.Phrase = new Phrase(itm.Remark, normal_font); cellHeaderBody1.HorizontalAlignment = Element.ALIGN_LEFT; headerTable3.AddCell(cellHeaderBody1); // No. BL / AWB cellHeaderBody1.Colspan = 1; cellHeaderBody1.Phrase = new Phrase(itm.BLAWBNumber, normal_font); cellHeaderBody1.HorizontalAlignment = Element.ALIGN_LEFT; headerTable3.AddCell(cellHeaderBody1); if (itm.IsGetPPn) { /*var temp = itm.Amount * 0.1m; * total_all = itm.Amount + temp;*/ ppn_manually += itm.PPnAmount; } /*else * { * total_all = itm.Amount; * }*/ if (itm.IsGetPPh) { if (itm.IncomeTaxBy == "Supplier") { pph_supplier += itm.PPhAmount; } else { pph_danliris += itm.PPhAmount; } } // Mata Uang cellHeaderBody1.Colspan = 1; cellHeaderBody1.Phrase = new Phrase(currencyCode, normal_font); cellHeaderBody1.HorizontalAlignment = Element.ALIGN_CENTER; headerTable3.AddCell(cellHeaderBody1); // Jumlah cellHeaderBody1.Phrase = new Phrase(itm.Amount.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font); cellHeaderBody1.HorizontalAlignment = Element.ALIGN_RIGHT; // Override default to center headerTable3.AddCell(cellHeaderBody1); /*count_price += total_all;*/ total_realization += itm.Amount; } // Jumlah Realisasi cellHeaderBody1a.Colspan = 5; cellHeaderBody1a.HorizontalAlignment = Element.ALIGN_LEFT; cellHeaderBody1a.Phrase = new Phrase("Jumlah Realisasi", normal_font); headerTable3.AddCell(cellHeaderBody1a); // Mata Uang cellHeaderBody1b.Phrase = new Phrase(currencyCode, normal_font); headerTable3.AddCell(cellHeaderBody1b); // Jumlah cellHeaderBody1a.Phrase = new Phrase(total_realization.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font); cellHeaderBody1a.HorizontalAlignment = Element.ALIGN_RIGHT; headerTable3.AddCell(cellHeaderBody1a); // PPn cellHeaderBody1a1.Colspan = 5; cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_LEFT; cellHeaderBody1a1.Phrase = new Phrase("PPN", normal_font); headerTable3.AddCell(cellHeaderBody1a1); // Mata Uang cellHeaderBody1b1.Phrase = new Phrase(currencyCode, normal_font); headerTable3.AddCell(cellHeaderBody1b1); // Jumlah cellHeaderBody1a1.Phrase = new Phrase(ppn_manually.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font); cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_RIGHT; headerTable3.AddCell(cellHeaderBody1a1); // PPh ditanggung Dan Liris cellHeaderBody1a1.Colspan = 5; cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_LEFT; cellHeaderBody1a1.Phrase = new Phrase("PPh ditanggung Dan Liris", normal_font); headerTable3.AddCell(cellHeaderBody1a1); // Mata Uang cellHeaderBody1b1.Phrase = new Phrase(currencyCode, normal_font); headerTable3.AddCell(cellHeaderBody1b1); // Jumlah cellHeaderBody1a1.Phrase = new Phrase(pph_danliris.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font); cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_RIGHT; headerTable3.AddCell(cellHeaderBody1a1); // PPh ditanggung Supplier cellHeaderBody1a1.Colspan = 5; cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_LEFT; cellHeaderBody1a1.Phrase = new Phrase("PPh ditanggung Supplier", normal_font); headerTable3.AddCell(cellHeaderBody1a1); // Mata Uang cellHeaderBody1b1.Phrase = new Phrase(currencyCode, normal_font); headerTable3.AddCell(cellHeaderBody1b1); // Jumlah cellHeaderBody1a1.Phrase = new Phrase(pph_supplier.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font); cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_RIGHT; headerTable3.AddCell(cellHeaderBody1a1); // Total Keseluruhan cellHeaderBody1a2.Colspan = 5; cellHeaderBody1a2.HorizontalAlignment = Element.ALIGN_LEFT; cellHeaderBody1a2.Phrase = new Phrase("Total", normal_font); headerTable3.AddCell(cellHeaderBody1a2); // Mata Uang cellHeaderBody1b2.Phrase = new Phrase(currencyCode, normal_font); headerTable3.AddCell(cellHeaderBody1b2); // Jumlah var grandTotal = total_realization + ppn_manually - pph_supplier; cellHeaderBody1a2.Phrase = new Phrase(grandTotal.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font); cellHeaderBody1a2.HorizontalAlignment = Element.ALIGN_RIGHT; headerTable3.AddCell(cellHeaderBody1a2); var vbDate = viewModel.VBDocument?.Date?.AddHours(timeoffsset).ToString("dd-MMMM-yy", new CultureInfo("id-ID")); if (viewModel.VBNonPOType == "Tanpa Nomor VB") { if (viewModel.VBDocument != null && !string.IsNullOrWhiteSpace(viewModel.VBDocument?.DocumentNo)) { vbDate = viewModel.VBDocument?.Date?.AddHours(timeoffsset).ToString("dd-MMMM-yy", new CultureInfo("id-ID")); } else { vbDate = ""; } } // Tanggal VB cellHeaderBody6.Colspan = 3; cellHeaderBody6.Phrase = new Phrase($"Tanggal VB: {vbDate}", normal_font); headerTable3.AddCell(cellHeaderBody6); // No VB cellHeaderBody1.Colspan = 2; cellHeaderBody1.Phrase = new Phrase($"No.VB: {viewModel.VBDocument?.DocumentNo}", normal_font); cellHeaderBody1.HorizontalAlignment = Element.ALIGN_LEFT; headerTable3.AddCell(cellHeaderBody1); if (viewModel.VBDocument == null) { // Mata Uang cellHeaderBody1.Colspan = 1; cellHeaderBody1.Phrase = new Phrase(currencyCode, normal_font); cellHeaderBody1.HorizontalAlignment = Element.ALIGN_CENTER; headerTable3.AddCell(cellHeaderBody1); // Jumlah cellHeaderBody1.Phrase = new Phrase(0.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font); cellHeaderBody1.HorizontalAlignment = Element.ALIGN_RIGHT; // Override default to center headerTable3.AddCell(cellHeaderBody1); } else { // Mata Uang cellHeaderBody1.Colspan = 1; cellHeaderBody1.Phrase = new Phrase(currencyCode, normal_font); cellHeaderBody1.HorizontalAlignment = Element.ALIGN_CENTER; headerTable3.AddCell(cellHeaderBody1); // Jumlah cellHeaderBody1.Phrase = new Phrase(viewModel.VBDocument?.Amount.GetValueOrDefault().ToString("#,##0.00", new CultureInfo("id-ID")), normal_font); cellHeaderBody1.HorizontalAlignment = Element.ALIGN_RIGHT; // Override default to center headerTable3.AddCell(cellHeaderBody1); } var priceterbilang = grandTotal; var res = grandTotal - (viewModel.VBDocument == null ? 0 : viewModel.VBDocument.Amount.GetValueOrDefault()); if (res > 0) { // Kurang cellHeaderBody5.Colspan = 5; cellHeaderBody5.Phrase = new Phrase("Kurang", bold_font); headerTable3.AddCell(cellHeaderBody5); // Mata Uang cellHeaderBody5a.Phrase = new Phrase(currencyCode, normal_font); headerTable3.AddCell(cellHeaderBody5a); // Jumlah cellHeaderBody5a.Phrase = new Phrase("(" + res.ToString("#,##0.00", new CultureInfo("id-ID")) + ")", normal_font); cellHeaderBody5a.HorizontalAlignment = Element.ALIGN_RIGHT; // Override default to center headerTable3.AddCell(cellHeaderBody5a); } else { // Sisa cellHeaderBody5.Colspan = 5; cellHeaderBody5.Phrase = new Phrase("Sisa", bold_font); headerTable3.AddCell(cellHeaderBody5); // Mata Uang cellHeaderBody5a.Phrase = new Phrase(currencyCode, normal_font); headerTable3.AddCell(cellHeaderBody5a); // Jumlah cellHeaderBody5a.Phrase = new Phrase((res * -1).ToString("#,##0.00", new CultureInfo("id-ID")), normal_font); cellHeaderBody5a.HorizontalAlignment = Element.ALIGN_RIGHT; // Override default to center headerTable3.AddCell(cellHeaderBody5a); } string total = grandTotal.ToString("#,##0.00", new CultureInfo("id-ID")); // New Line cellHeaderBody4a.Colspan = 7; cellHeaderBody4a.Phrase = new Phrase(" ", normal_font); headerTable3.AddCell(cellHeaderBody4a); // Terbilang cellHeaderBody4a.Colspan = 7; cellHeaderBody4a.HorizontalAlignment = Element.ALIGN_LEFT; cellHeaderBody4a.Phrase = new Phrase("Terbilang: " + Nom(grandTotal, currencyCode, currencydescription), normal_font); headerTable3.AddCell(cellHeaderBody4a); // New Line cellHeaderBody4a.Colspan = 7; cellHeaderBody4a.Phrase = new Phrase(" ", normal_font); headerTable3.AddCell(cellHeaderBody4a); // Beban Unit cellHeaderBody4.Colspan = 7; cellHeaderBody4.HorizontalAlignment = Element.ALIGN_LEFT; cellHeaderBody4.Phrase = new Phrase("Beban Unit:", bold_font); headerTable3.AddCell(cellHeaderBody4); cellHeader3.AddElement(headerTable3); headerTable_B.AddCell(cellHeader3); cellHeader4.AddElement(headerTable4); headerTable_B.AddCell(cellHeader4); document.Add(headerTable_B); #endregion Header #region NewCheckbox var layoutOrderOther = viewModel.UnitCosts.ToList().FirstOrDefault(s => s.Unit.VBDocumentLayoutOrder == 10); var unitCost12 = viewModel.UnitCosts.ToList().FirstOrDefault(s => s.Unit.VBDocumentLayoutOrder == 12); if (unitCost12 != null) { unitCost12.Unit.VBDocumentLayoutOrder = 10; } if (layoutOrderOther != null) { layoutOrderOther.Unit.VBDocumentLayoutOrder = 12; } var items = viewModel.UnitCosts.Where(element => element.IsSelected).OrderBy(s => s.Unit.VBDocumentLayoutOrder).ToList(); List <PdfFormField> annotations = new List <PdfFormField>(); foreach (var item in items) { PdfPCell cellform = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellform.FixedHeight = 5f; // Initiate form checkbox PdfFormField _checkGroup = PdfFormField.CreateEmpty(writer); RadioCheckField _radioG; PdfFormField _radioField1; Rectangle kotak = new Rectangle(100, 100); _radioG = new RadioCheckField(writer, kotak, "abc", "Yes"); _radioG.CheckType = RadioCheckField.TYPE_CHECK; _radioG.BorderStyle = PdfBorderDictionary.STYLE_SOLID; _radioG.BorderColor = BaseColor.Black; _radioG.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM; _radioG.Checked = item.IsSelected; bool flag = item.IsSelected; _radioG.Rotation = 0; _radioG.Options = TextField.READ_ONLY; _radioField1 = _radioG.CheckField; cellform.CellEvent = new BebanUnitEvent(_checkGroup, _radioField1, 1); headerTable3a.AddCell(cellform); // Beban Unit Item if (string.IsNullOrEmpty(item.Unit.Name)) { cellHeaderBody.Phrase = new Phrase("......", normal_font_8); } else { cellHeaderBody.Phrase = new Phrase(item.Unit.Name, normal_font_8); } cellHeaderBody.HorizontalAlignment = Element.ALIGN_LEFT; headerTable3a.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font_8); if (!flag) { cellHeaderBody.Phrase = new Phrase($"...........", normal_font_8); headerTable3a.AddCell(cellHeaderBody); } else { var nom = item.Amount.ToString("#,##0.00", new CultureInfo("id-ID")); // Beban Unit Item Mata Uang cellHeaderBody.Phrase = new Phrase(currencyCode, normal_font_8); cellHeaderBody.HorizontalAlignment = Element.ALIGN_RIGHT; headerTable3a.AddCell(cellHeaderBody); // Beban Unit Item Nominal cellHeaderBody.Phrase = new Phrase(nom, normal_font_8); cellHeaderBody.HorizontalAlignment = Element.ALIGN_RIGHT; headerTable3a.AddCell(cellHeaderBody); } // Empty space cellHeaderBody.Phrase = new Phrase(" ", normal_font_8); headerTable3a.AddCell(cellHeaderBody); annotations.Add(_checkGroup); } for (var i = 0; i < 9 - (3 * (items.Count() % 3)); i++) { cellHeaderBody.Phrase = new Phrase(" ", normal_font); headerTable3a.AddCell(cellHeaderBody); } cellHeader3a.AddElement(headerTable3a); headerTable_C.AddCell(cellHeader3a); var cellLeft = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, }; var emptyBorder = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellLeft.Colspan = 5; cellLeft.Phrase = new Phrase("\n\nKeterangan: ", normal_font); headerTable3b.AddCell(cellLeft); cellLeft.Colspan = 1; cellLeft.Phrase = new Phrase("", normal_font); headerTable3b.AddCell(cellLeft); cellLeft.Colspan = 4; cellLeft.Phrase = new Phrase(viewModel.Remark, normal_font); headerTable3b.AddCell(cellLeft); emptyBorder.AddElement(headerTable3b); headerTable_C.AddCell(emptyBorder); document.Add(headerTable_C); foreach (var annotation in annotations) { writer.AddAnnotation(annotation); } #endregion #region Footer PdfPTable table = new PdfPTable(5) { WidthPercentage = 97 }; float[] widths = new float[] { 1f, 1f, 1f, 1f, 1f }; table.SetWidths(widths); PdfPCell cell = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, }; cell.Phrase = new Phrase("\n\n", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("\n\n", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("\n\n", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("\n\n", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("\n\n", normal_font); table.AddCell(cell); // Menyetujui cell.Phrase = new Phrase("Menyetujui,", normal_font); table.AddCell(cell); // Diperiksa cell.Phrase = new Phrase("Diperiksa,", normal_font); table.AddCell(cell); // Mengetahui cell.Colspan = 2; cell.Phrase = new Phrase("Mengetahui,", normal_font); table.AddCell(cell); // Pembuat laporan cell.Colspan = 1; cell.Phrase = new Phrase("Pembuat laporan,", normal_font); table.AddCell(cell); for (var i = 0; i < 11; i++) { cell.Phrase = new Phrase("", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("", normal_font); table.AddCell(cell); } cell.Phrase = new Phrase("(..................)", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("(..................)", normal_font); table.AddCell(cell); cell.Phrase = new Phrase("(..................)", normal_font); table.AddCell(cell); cell.Phrase = new Phrase($"(..................)", normal_font); table.AddCell(cell); cell.Phrase = new Phrase($"({viewModel.CreatedBy})", normal_font); table.AddCell(cell); document.Add(table); #endregion Footer document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(RO_GarmentViewModel viewModel, int offset) { //set pdf stream MemoryStream stream = new MemoryStream(); Document document = new Document(PageSize.A4, 10, 10, 10, 10); PdfWriter writer = PdfWriter.GetInstance(document, stream); writer.PageEvent = new ROGarmentPdfTemplatePageEvent(); document.Open(); //set content configuration Font company_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); Font title_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7); #region Header document.Add(new Paragraph("PT.DANLIRIS", company_font) { Alignment = Element.ALIGN_LEFT, Leading = 0, MultipliedLeading = 1 }); document.Add(new Paragraph("RO EKSPOR GARMENT", title_font) { Alignment = Element.ALIGN_LEFT, Leading = 0, MultipliedLeading = 1 }); #endregion #region Top PdfPTable table_top_with_images = new PdfPTable(2); table_top_with_images.SetWidths(new float[] { 5f, 0.7f }); PdfPTable table_top = new PdfPTable(9); float[] top_widths = new float[] { 1f, 0.1f, 2f, 1f, 0.1f, 2f, 1.2f, 0.1f, 2f }; table_top.TotalWidth = 500f; table_top.SetWidths(top_widths); PdfPCell cell_top = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_TOP, PaddingRight = 1, PaddingBottom = 2, PaddingTop = 2 }; PdfPCell cell_colon = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_TOP }; PdfPCell cell_top_keterangan = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_TOP, PaddingRight = 1, PaddingBottom = 2, PaddingTop = 2, Colspan = 7 }; cell_colon.Phrase = new Phrase(":", normal_font); cell_top.Phrase = new Phrase("NO RO", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.CostCalculationGarment.RO_Number}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("SECTION", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.CostCalculationGarment.Section}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("DATE", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.CostCalculationGarment.ConfirmDate.AddHours(offset).ToString("dd MMMM yyyy")}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("Artikel", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.CostCalculationGarment.Article}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("BUYER", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.CostCalculationGarment.BuyerBrand.Name}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("DELIVERY DATE", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.CostCalculationGarment.DeliveryDate.ToOffset(new TimeSpan(offset, 0, 0)).ToString("dd MMMM yyyy")}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("Konveksi", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.CostCalculationGarment.Unit.Code}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("QUANTITY", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.Total.ToString()} {viewModel.CostCalculationGarment.UOM.Unit}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("SIZE RANGE", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.CostCalculationGarment.SizeRange}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("DESC", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.CostCalculationGarment.CommodityDescription}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_top); table_top.AddCell(cell_top); table_top.AddCell(cell_top); table_top.AddCell(cell_top); table_top.AddCell(cell_top); table_top.LockedWidth = true; table_top.HorizontalAlignment = Element.ALIGN_LEFT; table_top.ExtendLastRow = false; table_top_with_images.AddCell(new PdfPCell(table_top) { Border = Rectangle.NO_BORDER }); byte[] imageByte; try { imageByte = Convert.FromBase64String(Base64.GetBase64File(viewModel.CostCalculationGarment.ImageFile)); } catch (Exception) { //var webClient = new WebClient(); //imageByte = webClient.DownloadData("https://bellamozzarella.files.wordpress.com/2013/07/blank-canvas1.jpg"); imageByte = Convert.FromBase64String("/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAA0NDQ0ODQ4QEA4UFhMWFB4bGRkbHi0gIiAiIC1EKjIqKjIqRDxJOzc7STxsVUtLVWx9aWNpfZeHh5e+tb75+f8BDQ0NDQ4NDhAQDhQWExYUHhsZGRseLSAiICIgLUQqMioqMipEPEk7NztJPGxVS0tVbH1pY2l9l4eHl761vvn5///CABEIAAoACgMBIgACEQEDEQH/xAAVAAEBAAAAAAAAAAAAAAAAAAAAB//aAAgBAQAAAACnD//EABQBAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIQAAAAf//EABQBAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMQAAAAf//EABQQAQAAAAAAAAAAAAAAAAAAACD/2gAIAQEAAT8AH//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Af//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Af//Z"); } Image image = Image.GetInstance(imgb: imageByte); if (image.Width > 60) { float percentage = 0.0f; percentage = 60 / image.Width; image.ScalePercent(percentage * 100); } float row1Y = 800; float imageY = 800 - image.ScaledHeight; table_top_with_images.AddCell(new PdfPCell(image) { Border = Rectangle.NO_BORDER }); PdfPCell cell_table_top_with_images = new PdfPCell(table_top_with_images); table_top_with_images.SpacingBefore = 5f; table_top_with_images.ExtendLastRow = false; document.Add(table_top_with_images); #endregion #region Table Fabric //Fabric title PdfPTable table_fabric_top = new PdfPTable(1); table_fabric_top.TotalWidth = 570f; float[] fabric_widths_top = new float[] { 5f }; table_fabric_top.SetWidths(fabric_widths_top); PdfPCell cell_top_fabric = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 1, PaddingBottom = 2, PaddingTop = 2 }; cell_top_fabric.Phrase = new Phrase("FABRIC", bold_font); table_fabric_top.AddCell(cell_top_fabric); table_fabric_top.LockedWidth = true; table_fabric_top.HorizontalAlignment = Element.ALIGN_LEFT; table_fabric_top.SpacingBefore = 5f; table_fabric_top.ExtendLastRow = false; document.Add(table_fabric_top); //Main fabric table PdfPTable table_fabric = new PdfPTable(8); table_fabric.TotalWidth = 570f; float[] fabric_widths = new float[] { 5f, 5f, 5f, 5f, 5f, 5f, 5f, 5f }; table_fabric.SetWidths(fabric_widths); PdfPCell cell_fabric_center = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2 }; PdfPCell cell_fabric_left = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2 }; //cell_fabric_center.Phrase = new Phrase("FABRIC", bold_font); //table_fabric.AddCell(cell_fabric_center); cell_fabric_center.Phrase = new Phrase("PRODUCT CODE", bold_font); table_fabric.AddCell(cell_fabric_center); cell_fabric_center.Phrase = new Phrase("COMPOSITION", bold_font); table_fabric.AddCell(cell_fabric_center); cell_fabric_center.Phrase = new Phrase("CONSTRUCTION", bold_font); table_fabric.AddCell(cell_fabric_center); cell_fabric_center.Phrase = new Phrase("YARN", bold_font); table_fabric.AddCell(cell_fabric_center); cell_fabric_center.Phrase = new Phrase("WIDTH", bold_font); table_fabric.AddCell(cell_fabric_center); cell_fabric_center.Phrase = new Phrase("DESCRIPTION", bold_font); table_fabric.AddCell(cell_fabric_center); cell_fabric_center.Phrase = new Phrase("QUANTITY", bold_font); table_fabric.AddCell(cell_fabric_center); cell_fabric_center.Phrase = new Phrase("REMARK", bold_font); table_fabric.AddCell(cell_fabric_center); foreach (var materialModel in viewModel.CostCalculationGarment.CostCalculationGarment_Materials) { if (materialModel.Category.name == "FABRIC") { //cell_fabric_left.Phrase = new Phrase(materialModel.Category.SubCategory != null ? materialModel.Category.SubCategory : "", normal_font); //table_fabric.AddCell(cell_fabric_left); cell_fabric_left.Phrase = new Phrase(materialModel.Product.Code, normal_font); table_fabric.AddCell(cell_fabric_left); cell_fabric_left.Phrase = new Phrase(materialModel.Product.Composition, normal_font); table_fabric.AddCell(cell_fabric_left); cell_fabric_left.Phrase = new Phrase(materialModel.Product.Const, normal_font); table_fabric.AddCell(cell_fabric_left); cell_fabric_left.Phrase = new Phrase(materialModel.Product.Yarn, normal_font); table_fabric.AddCell(cell_fabric_left); cell_fabric_left.Phrase = new Phrase(materialModel.Product.Width, normal_font); table_fabric.AddCell(cell_fabric_left); cell_fabric_left.Phrase = new Phrase(materialModel.Description != null ? materialModel.Description : "", normal_font); table_fabric.AddCell(cell_fabric_left); cell_fabric_left.Phrase = new Phrase(materialModel.Quantity.ToString() != null ? String.Format("{0} " + materialModel.UOMQuantity.Unit, materialModel.Quantity.ToString()) : "0", normal_font); table_fabric.AddCell(cell_fabric_left); cell_fabric_left.Phrase = new Phrase(materialModel.Information != null ? materialModel.Information : "", normal_font); table_fabric.AddCell(cell_fabric_left); } } table_fabric.LockedWidth = true; table_fabric.HorizontalAlignment = Element.ALIGN_LEFT; table_fabric.SpacingBefore = 5f; table_fabric.ExtendLastRow = false; document.Add(table_fabric); #endregion #region Table Accessories //Accessories Title PdfPTable table_acc_top = new PdfPTable(1); table_acc_top.TotalWidth = 570f; float[] acc_width_top = new float[] { 5f }; table_acc_top.SetWidths(acc_width_top); PdfPCell cell_top_acc = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 1, PaddingBottom = 2, PaddingTop = 2 }; cell_top_acc.Phrase = new Phrase("ACCESSORIES", bold_font); table_acc_top.AddCell(cell_top_acc); table_acc_top.LockedWidth = true; table_acc_top.HorizontalAlignment = Element.ALIGN_LEFT; table_acc_top.SpacingBefore = 5f; table_acc_top.ExtendLastRow = false; document.Add(table_acc_top); //Main Accessories Table PdfPTable table_accessories = new PdfPTable(4); table_accessories.TotalWidth = 570f; float[] accessories_widths = new float[] { 3f, 5f, 2.5f, 7.5f }; table_accessories.SetWidths(accessories_widths); PdfPCell cell_acc_center = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2 }; PdfPCell cell_acc_left = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2 }; //cell_acc_center.Phrase = new Phrase("ACCESSORIES", bold_font); //table_accessories.AddCell(cell_acc_center); cell_fabric_center.Phrase = new Phrase("PRODUCT CODE", bold_font); table_accessories.AddCell(cell_fabric_center); cell_acc_center.Phrase = new Phrase("DESCRIPTION", bold_font); table_accessories.AddCell(cell_acc_center); cell_acc_center.Phrase = new Phrase("QUANTITY", bold_font); table_accessories.AddCell(cell_acc_center); cell_acc_center.Phrase = new Phrase("REMARK", bold_font); table_accessories.AddCell(cell_acc_center); foreach (var materialModel in viewModel.CostCalculationGarment.CostCalculationGarment_Materials) { if (materialModel.Category.name != "FABRIC") { cell_acc_left.Phrase = new Phrase(materialModel.Product.Code, normal_font); table_accessories.AddCell(cell_acc_left); cell_acc_left.Phrase = new Phrase(materialModel.Description != null ? materialModel.Description : "", normal_font); table_accessories.AddCell(cell_acc_left); cell_acc_left.Phrase = new Phrase(materialModel.Quantity != null ? String.Format("{0} " + materialModel.UOMQuantity.Unit, materialModel.Quantity.ToString()) : "0", normal_font); table_accessories.AddCell(cell_acc_left); cell_acc_left.Phrase = new Phrase(materialModel.Information != null ? materialModel.Information : "", normal_font); table_accessories.AddCell(cell_acc_left); } } table_accessories.LockedWidth = true; table_accessories.HorizontalAlignment = Element.ALIGN_LEFT; table_accessories.SpacingBefore = 5f; table_accessories.ExtendLastRow = false; document.Add(table_accessories); #endregion #region Table Size Breakdown //Title PdfPTable table_breakdown_top = new PdfPTable(1); table_breakdown_top.TotalWidth = 570f; float[] breakdown_width_top = new float[] { 5f }; table_breakdown_top.SetWidths(breakdown_width_top); PdfPCell cell_top_breakdown = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 1, PaddingBottom = 2, PaddingTop = 2 }; cell_top_breakdown.Phrase = new Phrase("SIZE BREAKDOWN", bold_font); table_breakdown_top.AddCell(cell_top_breakdown); table_breakdown_top.LockedWidth = true; table_breakdown_top.HorizontalAlignment = Element.ALIGN_LEFT; table_breakdown_top.SpacingBefore = 5f; table_breakdown_top.ExtendLastRow = false; document.Add(table_breakdown_top); //Main Table Size Breakdown PdfPTable table_breakDown = new PdfPTable(2); table_breakDown.TotalWidth = 570f; float[] breakDown_widths = new float[] { 3f, 12f }; table_breakDown.SetWidths(breakDown_widths); PdfPCell cell_breakDown_center = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2 }; PdfPCell cell_breakDown_left = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2 }; PdfPCell cell_breakDown_total = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2 }; PdfPCell cell_breakDown_total_2 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2 }; cell_breakDown_center.Phrase = new Phrase("WARNA", bold_font); table_breakDown.AddCell(cell_breakDown_center); cell_breakDown_center.Phrase = new Phrase("SIZE RANGE", bold_font); table_breakDown.AddCell(cell_breakDown_center); foreach (var productRetail in viewModel.RO_Garment_SizeBreakdowns) { if (productRetail.Total != 0) { cell_breakDown_left.Phrase = new Phrase(productRetail.Color.Name != null ? productRetail.Color.Name : "", normal_font); table_breakDown.AddCell(cell_breakDown_left); PdfPTable table_breakDown_child = new PdfPTable(3); table_breakDown_child.TotalWidth = 300f; float[] breakDown_child_widths = new float[] { 9f, 3f, 3f }; table_breakDown_child.SetWidths(breakDown_child_widths); PdfPCell cell_breakDown_child_center = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2 }; PdfPCell cell_breakDown_child_left = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2 }; cell_breakDown_child_center.Phrase = new Phrase("KETERANGAN", bold_font); table_breakDown_child.AddCell(cell_breakDown_child_center); cell_breakDown_child_center.Phrase = new Phrase("SIZE", bold_font); table_breakDown_child.AddCell(cell_breakDown_child_center); cell_breakDown_child_center.Phrase = new Phrase("QUANTITY", bold_font); table_breakDown_child.AddCell(cell_breakDown_child_center); foreach (var size in productRetail.RO_Garment_SizeBreakdown_Details) { cell_breakDown_child_left.Phrase = new Phrase(size.Information != null ? size.Information : "", normal_font); table_breakDown_child.AddCell(cell_breakDown_child_left); cell_breakDown_child_left.Phrase = new Phrase(size.Size != null ? size.Size : "", normal_font); table_breakDown_child.AddCell(cell_breakDown_child_left); cell_breakDown_child_left.Phrase = new Phrase(size.Quantity.ToString() != null ? size.Quantity.ToString() : "0", normal_font); table_breakDown_child.AddCell(cell_breakDown_child_left); } cell_breakDown_child_left.Phrase = new Phrase(" ", bold_font); table_breakDown_child.AddCell(cell_breakDown_child_left); cell_breakDown_child_left.Phrase = new Phrase("TOTAL", bold_font); table_breakDown_child.AddCell(cell_breakDown_child_left); cell_breakDown_child_left.Phrase = new Phrase(productRetail.Total.ToString() != null ? productRetail.Total.ToString() : "0", normal_font); table_breakDown_child.AddCell(cell_breakDown_child_left); table_breakDown.AddCell(table_breakDown_child); } } cell_breakDown_total_2.Phrase = new Phrase("TOTAL", bold_font); table_breakDown.AddCell(cell_breakDown_total_2); cell_breakDown_total_2.Phrase = new Phrase(viewModel.Total.ToString(), bold_font); table_breakDown.AddCell(cell_breakDown_total_2); table_breakDown.LockedWidth = true; table_breakDown.HorizontalAlignment = Element.ALIGN_LEFT; table_breakDown.SpacingBefore = 5f; table_breakDown.ExtendLastRow = false; document.Add(table_breakDown); #endregion #region Table Instruksi //Title PdfPTable table_instruction = new PdfPTable(1); float[] instruction_widths = new float[] { 5f }; table_instruction.TotalWidth = 500f; table_instruction.SetWidths(instruction_widths); PdfPCell cell_top_instruction = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 1, PaddingBottom = 2, PaddingTop = 2 }; PdfPCell cell_colon_instruction = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE }; PdfPCell cell_top_keterangan_instruction = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 1, PaddingBottom = 2, PaddingTop = 2, Colspan = 7 }; cell_top_instruction.Phrase = new Phrase("INSTRUCTION", normal_font); table_instruction.AddCell(cell_top_instruction); table_instruction.AddCell(cell_colon_instruction); cell_top_keterangan_instruction.Phrase = new Phrase($"{viewModel.Instruction}", normal_font); table_instruction.AddCell(cell_top_keterangan_instruction); table_instruction.LockedWidth = true; table_instruction.HorizontalAlignment = Element.ALIGN_LEFT; table_instruction.SpacingBefore = 5f; table_instruction.ExtendLastRow = false; document.Add(table_instruction); #endregion #region RO Image var countImageRo = 0; byte[] roImage; foreach (var index in viewModel.ImagesFile) { countImageRo++; } if (countImageRo != 0) { if (countImageRo > 5) { countImageRo = 5; } PdfPTable table_ro_image = new PdfPTable(countImageRo); float[] ro_widths = new float[countImageRo]; for (var i = 0; i < countImageRo; i++) { ro_widths.SetValue(5f, i); } if (countImageRo != 0) { table_ro_image.SetWidths(ro_widths); } table_ro_image.TotalWidth = 570f; foreach (var imageFromRo in viewModel.ImagesFile) { try { roImage = Convert.FromBase64String(Base64.GetBase64File(imageFromRo)); } catch (Exception) { //var webClient = new WebClient(); //roImage = webClient.DownloadData("https://bateeqstorage.blob.core.windows.net/other/no-image.jpg"); roImage = Convert.FromBase64String("/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAA0NDQ0ODQ4QEA4UFhMWFB4bGRkbHi0gIiAiIC1EKjIqKjIqRDxJOzc7STxsVUtLVWx9aWNpfZeHh5e+tb75+f8BDQ0NDQ4NDhAQDhQWExYUHhsZGRseLSAiICIgLUQqMioqMipEPEk7NztJPGxVS0tVbH1pY2l9l4eHl761vvn5///CABEIAAoACgMBIgACEQEDEQH/xAAVAAEBAAAAAAAAAAAAAAAAAAAAB//aAAgBAQAAAACnD//EABQBAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIQAAAAf//EABQBAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMQAAAAf//EABQQAQAAAAAAAAAAAAAAAAAAACD/2gAIAQEAAT8AH//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Af//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Af//Z"); } Image images = Image.GetInstance(imgb: roImage); if (images.Width > 60) { float percentage = 0.0f; percentage = 60 / images.Width; images.ScalePercent(percentage * 100); } PdfPCell imageCell = new PdfPCell(images); imageCell.Border = 0; table_ro_image.AddCell(imageCell); } PdfPCell cell_image = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2, }; foreach (var name in viewModel.ImagesName) { cell_image.Phrase = new Phrase(name, normal_font); table_ro_image.AddCell(cell_image); } table_ro_image.LockedWidth = true; table_ro_image.HorizontalAlignment = Element.ALIGN_LEFT; table_ro_image.SpacingBefore = 5f; table_ro_image.ExtendLastRow = false; document.Add(table_ro_image); } #endregion #region Signature PdfPTable table_signature = new PdfPTable(2); table_signature.TotalWidth = 570f; float[] signature_widths = new float[] { 1f, 1f }; table_signature.SetWidths(signature_widths); PdfPCell cell_signature = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2, }; PdfPCell cell_signature_noted = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2, PaddingTop = 50 }; cell_signature.Phrase = new Phrase("Bagian Penjualan", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Kasie/Kabag Penjualan", normal_font); table_signature.AddCell(cell_signature); cell_signature_noted.Phrase = new Phrase("( )", normal_font); table_signature.AddCell(cell_signature_noted); cell_signature_noted.Phrase = new Phrase("( )", normal_font); table_signature.AddCell(cell_signature_noted); table_signature.LockedWidth = true; table_signature.HorizontalAlignment = Element.ALIGN_LEFT; table_signature.SpacingBefore = 5f; table_signature.ExtendLastRow = false; document.Add(table_signature); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
private static void SetCategory(Document document, List <ReportCategoryDto> categories, bool isForeignCurrency, bool isImportSupplier) { var cellCenter = new PdfPCell() { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_CENTER }; var cellLeft = new PdfPCell() { HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER }; var cellRight = new PdfPCell() { HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_CENTER }; if (isForeignCurrency || isImportSupplier) { var table = new PdfPTable(4) { WidthPercentage = 30, HorizontalAlignment = Element.ALIGN_LEFT, }; cellCenter.Phrase = new Phrase("Kategori", _subHeaderFont); table.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Mata Uang", _subHeaderFont); table.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Total Valas", _subHeaderFont); table.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Total (IDR)", _subHeaderFont); table.AddCell(cellCenter); foreach (var category in categories) { cellLeft.Phrase = new Phrase(category.CategoryName, _normalFont); table.AddCell(cellLeft); cellLeft.Phrase = new Phrase(category.CurrencyCode, _normalFont); table.AddCell(cellLeft); cellRight.Phrase = new Phrase(category.CurrencyAmount.ToString("0,0.00", CultureInfo.InvariantCulture), _normalFont); table.AddCell(cellRight); cellRight.Phrase = new Phrase(category.Amount.ToString("0,0.00", CultureInfo.InvariantCulture), _normalFont); table.AddCell(cellRight); } document.Add(table); } else { var table = new PdfPTable(2) { WidthPercentage = 30, HorizontalAlignment = Element.ALIGN_LEFT }; cellCenter.Phrase = new Phrase("Kategori", _subHeaderFont); table.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Total (IDR)", _subHeaderFont); table.AddCell(cellCenter); foreach (var category in categories) { cellLeft.Phrase = new Phrase(category.CategoryName, _normalFont); table.AddCell(cellLeft); cellRight.Phrase = new Phrase(category.Amount.ToString("0,0.00", CultureInfo.InvariantCulture), _normalFont); table.AddCell(cellRight); } document.Add(table); } document.Add(new Paragraph("\n")); }
//======================== Method For report File Format================================================////// public void ExportToPdf(DataTable myDataTable, params string[] headerList) { if (myDataTable.Rows.Count == 0) { return; } Document pdfDoc = new Document(PageSize.A4, 10, 10, 8, 8); try { PdfWriter.GetInstance(pdfDoc, System.Web.HttpContext.Current.Response.OutputStream); pdfDoc.Open(); //Chunk c = new Chunk( "HSBC", FontFactory.GetFont("Verdana", 11)); //Paragraph p = new Paragraph(); //p.Alignment = Element.ALIGN_CENTER; //p.Add(c); //pdfDoc.Add(p); string imageFilePath = Server.MapPath("~/Images") + "\\" + "hsbc.jpg"; iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageFilePath); //Resize image depend upon your need //jpg.ScaleToFit(80f, 60f); //Give space before image jpg.SpacingBefore = 0f; //Give some space after the image jpg.SpacingAfter = 1f; jpg.Alignment = Element.ALIGN_CENTER; pdfDoc.Add(jpg); Font font8 = FontFactory.GetFont("ARIAL", 7); DataTable dt = myDataTable; if (dt != null) { //Craete instance of the pdf table and set the number of column in that table PdfPTable PdfTable = new PdfPTable(dt.Columns.Count); PdfPCell PdfPCell = null; Font fnt = new Font(Font.HELVETICA, 8); foreach (string columheader in headerList) { PdfTable.AddCell(new iTextSharp.text.Phrase(columheader, fnt)); } for (int rows = 0; rows < dt.Rows.Count; rows++) { for (int column = 0; column < dt.Columns.Count; column++) { PdfPCell = new PdfPCell(new Phrase(new Chunk(dt.Rows[rows][column].ToString(), font8))); PdfTable.AddCell(PdfPCell); } } //PdfTable.SpacingBefore = 15f; // Give some space after the text or it may overlap the table pdfDoc.Add(PdfTable); // add pdf table to the document } pdfDoc.Close(); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment; filename= SampleExport.pdf"); System.Web.HttpContext.Current.Response.Write(pdfDoc); Response.Flush(); Response.End(); //HttpContext.Current.ApplicationInstance.CompleteRequest(); } catch (DocumentException de) { System.Web.HttpContext.Current.Response.Write(de.Message); } catch (IOException ioEx) { System.Web.HttpContext.Current.Response.Write(ioEx.Message); } catch (Exception ex) { System.Web.HttpContext.Current.Response.Write(ex.Message); } }
public ActionResult AccountLedger(String StartDate, String EndDate, Int32 CompanyId, Int32 BranchId, Int32 AccountId) { // ============ // PDF Settings // ============ MemoryStream workStream = new MemoryStream(); Rectangle rectangle = new Rectangle(PageSize.A3); Document document = new Document(rectangle, 72, 72, 72, 72); document.SetMargins(30f, 30f, 30f, 30f); PdfWriter.GetInstance(document, workStream).CloseStream = false; document.Open(); // =================== // Fonts Customization // =================== Font fontArial17Bold = FontFactory.GetFont("Arial", 17, Font.BOLD); Font fontArial11 = FontFactory.GetFont("Arial", 11); Font fontArial10Bold = FontFactory.GetFont("Arial", 10, Font.BOLD); Font fontArial10 = FontFactory.GetFont("Arial", 10); Font fontArial11Bold = FontFactory.GetFont("Arial", 11, Font.BOLD); Font fontArial12Bold = FontFactory.GetFont("Arial", 12, Font.BOLD); Paragraph line = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, BaseColor.BLACK, Element.ALIGN_LEFT, 4.5F))); // ============== // Company Detail // ============== var companyName = (from d in db.MstBranches where d.Id == Convert.ToInt32(BranchId) select d.MstCompany.Company).FirstOrDefault(); var address = (from d in db.MstBranches where d.Id == Convert.ToInt32(BranchId) select d.MstCompany.Address).FirstOrDefault(); var contactNo = (from d in db.MstBranches where d.Id == Convert.ToInt32(BranchId) select d.MstCompany.ContactNumber).FirstOrDefault(); var branch = (from d in db.MstBranches where d.Id == Convert.ToInt32(BranchId) select d.Branch).FirstOrDefault(); // =========== // Header Page // =========== PdfPTable headerPage = new PdfPTable(2); float[] widthsCellsHeaderPage = new float[] { 100f, 75f }; headerPage.SetWidths(widthsCellsHeaderPage); headerPage.WidthPercentage = 100; headerPage.AddCell(new PdfPCell(new Phrase(companyName, fontArial17Bold)) { Border = 0 }); headerPage.AddCell(new PdfPCell(new Phrase("Account Ledger", fontArial17Bold)) { Border = 0, HorizontalAlignment = 2 }); headerPage.AddCell(new PdfPCell(new Phrase(address, fontArial11)) { Border = 0, PaddingTop = 5f }); headerPage.AddCell(new PdfPCell(new Phrase("Date From " + Convert.ToDateTime(StartDate).ToString("MM-dd-yyyy", CultureInfo.InvariantCulture) + " to " + Convert.ToDateTime(EndDate).ToString("MM-dd-yyyy", CultureInfo.InvariantCulture), fontArial11)) { Border = 0, PaddingTop = 5f, HorizontalAlignment = 2 }); headerPage.AddCell(new PdfPCell(new Phrase(contactNo, fontArial11)) { Border = 0, PaddingTop = 5f }); headerPage.AddCell(new PdfPCell(new Phrase("Printed " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToString("hh:mm:ss tt"), fontArial11)) { Border = 0, PaddingTop = 5f, HorizontalAlignment = 2 }); document.Add(headerPage); document.Add(line); // ======== // Get Data // ======== var accounts = from d in db.MstAccounts where d.Id == AccountId select d; if (accounts.Any()) { // ============ // Branch Title // ============ PdfPTable branchTitle = new PdfPTable(1); float[] widthCellsBranchTitle = new float[] { 100f }; branchTitle.SetWidths(widthCellsBranchTitle); branchTitle.WidthPercentage = 100; PdfPCell branchHeaderColspan = (new PdfPCell(new Phrase(branch, fontArial12Bold)) { Border = 0, HorizontalAlignment = 0, PaddingTop = 10f }); branchTitle.AddCell(branchHeaderColspan); document.Add(branchTitle); // ============= // Account Title // ============= PdfPTable itemTitle = new PdfPTable(1); float[] widthCellsItemTitle = new float[] { 100f }; itemTitle.SetWidths(widthCellsItemTitle); itemTitle.WidthPercentage = 100; itemTitle.AddCell(new PdfPCell(new Phrase(accounts.FirstOrDefault().AccountCode + " - " + accounts.FirstOrDefault().Account, fontArial12Bold)) { Border = 0, HorizontalAlignment = 0, PaddingBottom = 14f }); document.Add(itemTitle); var journals = from d in db.TrnJournals where d.JournalDate >= Convert.ToDateTime(StartDate) && d.JournalDate <= Convert.ToDateTime(EndDate) && d.MstBranch.CompanyId == CompanyId && d.BranchId == Convert.ToInt32(BranchId) && d.AccountId == AccountId select new { JournalDate = d.JournalDate.ToString("MM-dd-yyyy", CultureInfo.InvariantCulture), ManualNo = d.ORId != null ? d.TrnCollection.ManualORNumber : d.CVId != null ? d.TrnDisbursement.ManualCVNumber : d.JVId != null ? d.TrnJournalVoucher.ManualJVNumber : d.RRId != null ? d.TrnReceivingReceipt.ManualRRNumber : d.SIId != null ? d.TrnSalesInvoice.ManualSINumber : d.INId != null ? d.TrnStockIn.ManualINNumber : d.OTId != null ? d.TrnStockOut.ManualOTNumber : d.STId != null ? d.TrnStockTransfer.ManualSTNumber : " ", DocumentReference = d.DocumentReference, Article = d.MstArticle.Article, Particulars = d.Particulars, DebitAmount = d.DebitAmount, CreditAmount = d.CreditAmount }; if (journals.Any()) { // ==== // Data // ==== PdfPTable tableData = new PdfPTable(8); PdfPCell Cell = new PdfPCell(); float[] widthCellsTableData = new float[] { 65f, 125f, 125f, 130f, 150f, 100f, 100f, 100f }; tableData.SetWidths(widthCellsTableData); tableData.WidthPercentage = 100; tableData.AddCell(new PdfPCell(new Phrase("Date", fontArial11Bold)) { HorizontalAlignment = 1, Rowspan = 2, PaddingTop = 3f, PaddingBottom = 5f, BackgroundColor = BaseColor.LIGHT_GRAY }); tableData.AddCell(new PdfPCell(new Phrase("Manual No", fontArial11Bold)) { HorizontalAlignment = 1, Rowspan = 2, PaddingTop = 3f, PaddingBottom = 5f, BackgroundColor = BaseColor.LIGHT_GRAY }); tableData.AddCell(new PdfPCell(new Phrase("Doc. Reference", fontArial11Bold)) { HorizontalAlignment = 1, Rowspan = 2, PaddingTop = 3f, PaddingBottom = 5f, BackgroundColor = BaseColor.LIGHT_GRAY }); tableData.AddCell(new PdfPCell(new Phrase("Article", fontArial11Bold)) { HorizontalAlignment = 1, Rowspan = 2, PaddingTop = 3f, PaddingBottom = 5f, BackgroundColor = BaseColor.LIGHT_GRAY }); tableData.AddCell(new PdfPCell(new Phrase("Particulars", fontArial11Bold)) { HorizontalAlignment = 1, Rowspan = 2, PaddingTop = 3f, PaddingBottom = 5f, BackgroundColor = BaseColor.LIGHT_GRAY }); tableData.AddCell(new PdfPCell(new Phrase("Debit", fontArial11Bold)) { HorizontalAlignment = 1, Rowspan = 2, PaddingTop = 3f, PaddingBottom = 5f, BackgroundColor = BaseColor.LIGHT_GRAY }); tableData.AddCell(new PdfPCell(new Phrase("Credit", fontArial11Bold)) { HorizontalAlignment = 1, Rowspan = 2, PaddingTop = 3f, PaddingBottom = 5f, BackgroundColor = BaseColor.LIGHT_GRAY }); tableData.AddCell(new PdfPCell(new Phrase("Balance", fontArial11Bold)) { HorizontalAlignment = 1, Rowspan = 2, PaddingTop = 3f, PaddingBottom = 5f, BackgroundColor = BaseColor.LIGHT_GRAY }); Decimal totalDebitAmount = 0; Decimal totalCreditAmount = 0; Decimal totalBalance = 0; foreach (var journal in journals) { Decimal balance = journal.DebitAmount - journal.CreditAmount; tableData.AddCell(new PdfPCell(new Phrase(journal.JournalDate, fontArial10)) { HorizontalAlignment = 0, PaddingBottom = 5f, PaddingLeft = 5f, PaddingRight = 5f }); tableData.AddCell(new PdfPCell(new Phrase(journal.ManualNo, fontArial10)) { HorizontalAlignment = 0, PaddingBottom = 5f, PaddingLeft = 5f, PaddingRight = 5f }); tableData.AddCell(new PdfPCell(new Phrase(journal.DocumentReference, fontArial10)) { HorizontalAlignment = 0, PaddingBottom = 5f, PaddingLeft = 5f, PaddingRight = 5f }); tableData.AddCell(new PdfPCell(new Phrase(journal.Article, fontArial10)) { HorizontalAlignment = 0, PaddingBottom = 5f, PaddingLeft = 5f, PaddingRight = 5f }); tableData.AddCell(new PdfPCell(new Phrase(journal.Particulars, fontArial10)) { HorizontalAlignment = 0, PaddingBottom = 5f, PaddingLeft = 5f, PaddingRight = 5f }); tableData.AddCell(new PdfPCell(new Phrase(journal.DebitAmount.ToString("#,##0.00"), fontArial10)) { HorizontalAlignment = 2, PaddingBottom = 5f, PaddingLeft = 5f, PaddingRight = 5f }); tableData.AddCell(new PdfPCell(new Phrase(journal.CreditAmount.ToString("#,##0.00"), fontArial10)) { HorizontalAlignment = 2, PaddingBottom = 5f, PaddingLeft = 5f, PaddingRight = 5f }); tableData.AddCell(new PdfPCell(new Phrase(balance.ToString("#,##0.00"), fontArial10)) { HorizontalAlignment = 2, PaddingBottom = 5f, PaddingLeft = 5f, PaddingRight = 5f }); totalDebitAmount += journal.DebitAmount; totalCreditAmount += journal.CreditAmount; totalBalance += journal.DebitAmount - journal.CreditAmount; } tableData.AddCell(new PdfPCell(new Phrase("Total", fontArial10Bold)) { Colspan = 5, HorizontalAlignment = 2, PaddingBottom = 5f, PaddingLeft = 5f, PaddingRight = 5f }); tableData.AddCell(new PdfPCell(new Phrase(totalDebitAmount.ToString("#,##0.00"), fontArial10Bold)) { HorizontalAlignment = 2, PaddingBottom = 5f, PaddingLeft = 5f, PaddingRight = 5f }); tableData.AddCell(new PdfPCell(new Phrase(totalCreditAmount.ToString("#,##0.00"), fontArial10Bold)) { HorizontalAlignment = 2, PaddingBottom = 5f, PaddingLeft = 5f, PaddingRight = 5f }); tableData.AddCell(new PdfPCell(new Phrase(totalBalance.ToString("#,##0.00"), fontArial10Bold)) { HorizontalAlignment = 2, PaddingBottom = 5f, PaddingLeft = 5f, PaddingRight = 5f }); document.Add(tableData); } } document.Close(); byte[] byteInfo = workStream.ToArray(); workStream.Write(byteInfo, 0, byteInfo.Length); workStream.Position = 0; return new FileStreamResult(workStream, "application/pdf"); }
public void AddCol(PdfPCell cell) { if (cols == null) cols = new ArrayList(); cols.Add(cell); }
public void GenerarDocumento(Document document) { int i, j; int contRows = 0; System.Drawing.Color back; bool bandMas40 = false; iTextSharp.text.Font tipoheader = FontFactory.GetFont("arial", 10, 3, BaseColor.BLACK); iTextSharp.text.Font tipoFontCell = FontFactory.GetFont("arial", 9, BaseColor.BLUE); iTextSharp.text.Font tipoTotal = FontFactory.GetFont("arial", 9, BaseColor.BLUE); var colorBorde = System.Drawing.Color.Gray; PdfPTable datatable = new PdfPTable(FP.dgvBottC.ColumnCount); datatable.DefaultCell.Padding = 3; float[] headerwidths = GetTamañoColumnas(FP.dgvBottC); datatable.SetWidths(headerwidths); datatable.WidthPercentage = 100; //datatable.DefaultCell.BorderWidth = 1; datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; PdfPTable table2 = new PdfPTable(FP.dgvBottC.ColumnCount); table2.DefaultCell.Padding = 3; table2.SetWidths(headerwidths); table2.WidthPercentage = 100; table2.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; for (int z = 0; z < FP.dgvBC.ColumnCount; z++) { PdfPCell BC = new PdfPCell(new Phrase(FP.dgvBC.Columns[z].HeaderText, tipoheader)); BC.BorderColor = new BaseColor(colorBorde); BC.BackgroundColor = new BaseColor(System.Drawing.Color.FromName("LightBlue")); if (z == 0) { BC.Colspan = 3; } datatable.AddCell(BC); table2.AddCell(BC); } for (int y = 0; y < FP.dgvBD.ColumnCount; y++) { PdfPCell BD = new PdfPCell(new Phrase(FP.dgvBD.Columns[y].HeaderText, tipoheader)); BD.BorderColor = new BaseColor(colorBorde); BD.BackgroundColor = new BaseColor(System.Drawing.Color.LightPink); if (y == 0) { BD.Colspan = 3; } datatable.AddCell(BD); table2.AddCell(BD); } for (int e = 0; e < FP.dgvTops.ColumnCount; e++) { PdfPCell tops = new PdfPCell(new Phrase(FP.dgvTops.Columns[e].HeaderText, tipoheader)); tops.BorderColor = new BaseColor(colorBorde); tops.BackgroundColor = new BaseColor(System.Drawing.Color.WhiteSmoke); if (e == 0) { tops.Colspan = 3; } datatable.AddCell(tops); table2.AddCell(tops); } for (int x = 0; x < FP.dgvUni.ColumnCount; x++) { PdfPCell uni = new PdfPCell(new Phrase(FP.dgvUni.Columns[x].HeaderText, tipoheader)); uni.BorderColor = new BaseColor(colorBorde); uni.BackgroundColor = new BaseColor(System.Drawing.Color.Yellow); if (x == 0) { uni.Colspan = 3; } datatable.AddCell(uni); table2.AddCell(uni); } for (i = 0; i < FP.dgvBottC.ColumnCount; i++) { PdfPCell column = new PdfPCell(new Phrase(FP.dgvBottC.Columns[i].HeaderText, tipoheader)); column.BorderColor = new BaseColor(colorBorde); datatable.AddCell(column); table2.AddCell(column); } datatable.HeaderRows = 1; table2.HeaderRows = 1; //datatable.DefaultCell.BorderWidth = 1; string frase = ""; for (i = 0; i < FP.dgvBottC.Rows.Count; i++) { contRows++; for (j = 0; j < FP.dgvBottC.Columns.Count; j++) { if (FP.dgvBottC[j, i].Value == null) { frase = ""; } else { frase = FP.dgvBottC[j, i].Value.ToString(); } PdfPCell cell = new PdfPCell(new Phrase(frase, tipoFontCell)); var color = FP.dgvBottC[j, i].Style.BackColor; if (color.Name == "LightBlue") { cell.BackgroundColor = new BaseColor(System.Drawing.Color.LightBlue); } else if (color.Name == "LightPink") { cell.BackgroundColor = new BaseColor(System.Drawing.Color.LightPink); } else if (color.Name == "Yellow") { cell.BackgroundColor = new BaseColor(System.Drawing.Color.Yellow); } else if (color.Name == "WhiteSmoke") { cell.BackgroundColor = new BaseColor(System.Drawing.Color.WhiteSmoke); } else { if (i % 2 == 0) { cell.BackgroundColor = new BaseColor(System.Drawing.Color.LightGray); } } cell.Border = Rectangle.BOX; cell.BorderColor = new BaseColor(colorBorde); if (contRows < 40) { datatable.AddCell(cell);//En esta parte, se esta agregando un renglon por cada registro en el datagrid } if (contRows >= 40 && contRows < 80) { table2.AddCell(cell); bandMas40 = true; } //else if( i >= 80 && i < 120) //{ //} //else if( i >= 120 && i < 160) //{ //} } } PdfPCell total = new PdfPCell(new Phrase("TOTAL ARTICULOS:", tipoFontCell)); total.Colspan = 18; total.BorderColor = new BaseColor(colorBorde); total.BorderWidthBottom = 0; total.BorderWidthLeft = 0; total.BorderWidthTop = 0; total.HorizontalAlignment = 2; PdfPCell Ntotal = new PdfPCell(new Phrase(FP.txtTotal.Text, tipoFontCell)); Ntotal.BorderColor = new BaseColor(colorBorde); if (!bandMas40) { datatable.AddCell(total); datatable.AddCell(Ntotal); } datatable.CompleteRow(); document.Add(datatable); if (bandMas40) { document.NewPage(); table2.AddCell(total); table2.AddCell(Ntotal); table2.CompleteRow(); document.Add(table2); } }
private void Crear_Archivo(int intTotalPaginas) { Font ftProductos = new Font(FontFactory.GetFont(FontFactory.HELVETICA, 7, Font.NORMAL)); int intMaxWidth = 190, intMaxHeight = 50, intLogoWidth, intLogoHeight; HttpCookie ckSIAN = Request.Cookies["userCng"]; int intNombreLogo = ckSIAN["ck_logo"].LastIndexOf("/") + 1; string[] strSize = ckSIAN["ck_logo_size"].Split('x'); intLogoWidth = int.Parse(strSize[0]); intLogoHeight = int.Parse(strSize[1]); float flRelacion = CRutinas.Calcular_Relacion(intMaxWidth, intMaxHeight, intLogoWidth, intLogoHeight); MyPageEvents events = new MyPageEvents(); events.strMapPath = Server.MapPath("../imagenes") + "/"; events.strLogoEmpresa = ckSIAN["ck_logo"].Substring(intNombreLogo); events.flEscala = flRelacion * 100; events.strCotizacion = this.strCotizacion; events.strRazonSocial = this.strRazonSocial; events.strRFC = this.strRFC; events.strTelefono = this.strTelefono; events.strEmail = this.strEmail; events.objDirEmisor = this.objDirEmisor; events.strNumeroCliente = this.strNumeroCliente; events.strCliente = this.strCliente; events.strClienteRFC = this.strClienteRFC; events.strDiasCredito = this.strDiasCredito; events.objDirReceptor = this.objDirReceptor; events.objEnvio = this.objEnvio; events.strEjecutivoVentas = this.strEjecutivoVentas; events.dtFecha = this.dtFecha; events.strNota = this.strNota; events.strOrdenCompra = this.strOrdenCompra; events.strContacto = this.strContacto; events.dcmSubtotal = this.dcmSubtotal; events.dcmDescuento = this.dcmDescuento; events.dcmIVA = this.dcmIVA; events.dcmTotal = this.dcmTotal; events.strMoneda = this.strMoneda; events.intTotalPaginas = intTotalPaginas; string strArchivoFormato = Server.MapPath("remision_ipisa.pdf"); PdfReader pdfEntrada = new PdfReader(strArchivoFormato); MemoryStream m = new MemoryStream(); Document document = new Document( new Rectangle(PageSize.LETTER.Width, PageSize.LETTER.Height)); // 1 in = 25.4 mm = 72 points document.SetMargins(32.0f, 32.0f, 290.0f, 135.0f); Response.ContentType = "application/pdf"; PdfWriter writer; string strArchivo = "remision_" + Request.QueryString["notID"] + ".pdf"; if (Request.QueryString["m"] == null) { writer = PdfWriter.GetInstance(document, m); writer.CloseStream = false; } else { FileStream flArchivo = new FileStream(Server.MapPath("../xml_facturas" + HttpContext.Current.Request.ApplicationPath + "/" + strArchivo), FileMode.Create); writer = PdfWriter.GetInstance(document, flArchivo); } writer.PageEvent = events; events.pdfPage1 = writer.GetImportedPage(pdfEntrada, 1); document.Open(); float[] ancho_columnas = new float[6]; ancho_columnas[0] = 50; ancho_columnas[1] = 75; ancho_columnas[2] = 242; ancho_columnas[3] = 63; ancho_columnas[4] = 62; ancho_columnas[5] = 74; char tab = '\u0009'; foreach (CProducto objProducto in this.lstProductos) { PdfPTable tblLinea = new PdfPTable(ancho_columnas); tblLinea.TotalWidth = 532; tblLinea.DefaultCell.Border = Rectangle.NO_BORDER; tblLinea.HorizontalAlignment = Element.ALIGN_LEFT; tblLinea.LockedWidth = true; Paragraph texto = new Paragraph(string.Empty, ftProductos); PdfPCell celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.Border = Rectangle.NO_BORDER; tblLinea.AddCell(celda); texto = new Paragraph(objProducto.StrCodigo, ftProductos); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_LEFT; celda.Border = Rectangle.NO_BORDER; tblLinea.AddCell(celda); if (!string.IsNullOrEmpty(objProducto.StrDetalle)) texto = new Paragraph(objProducto.StrDescripcion + "\n" + objProducto.StrDetalle.Replace(tab.ToString(), " "), ftProductos); else texto = new Paragraph(objProducto.StrDescripcion, ftProductos); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_LEFT; celda.Border = Rectangle.NO_BORDER; if (objProducto.IntGrupoID == 0) celda.PaddingLeft = 0; else celda.PaddingLeft = 10; tblLinea.AddCell(celda); texto = new Paragraph((objProducto.SwKit ? string.Empty : objProducto.AmtCantidad.ToString("0.##")), ftProductos); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.Border = Rectangle.NO_BORDER; tblLinea.AddCell(celda); texto = new Paragraph((objProducto.SwKit ? string.Empty : objProducto.AmtValorUnitario.ToString("c")), ftProductos); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.Border = Rectangle.NO_BORDER; tblLinea.AddCell(celda); texto = new Paragraph((objProducto.SwKit ? string.Empty : objProducto.AmtImporte.ToString("c")), ftProductos); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.Border = Rectangle.NO_BORDER; tblLinea.AddCell(celda); document.Add(tblLinea); } document.Close(); if (Request.QueryString["m"] == null) { Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length); Response.OutputStream.Flush(); Response.OutputStream.Close(); Response.End(); m.Close(); } else Response.Redirect("cotizacion_correo.aspx?t=c&c=" + Request.QueryString["notID"] + "&f=" + strArchivo); }
public override void writePdf(bool bBlackAndWhite = false) { initFile(); { PdfPTable table; int cellHeight = ((int)m_doc.PageSize.Height - 200) / m_iCount; if (m_strType.Equals("numberstowords")) { if (m_iMax < 100) { float[] width = { 2, 10 }; table = new PdfPTable(width); m_fNorm.Size = 50; } else if (m_iMax < 1000) { float[] width = { 2, 10 }; table = new PdfPTable(width); m_fNorm.Size = 20; } else { float[] width = { 2, 10 }; table = new PdfPTable(width); m_fNorm.Size = 20; } } else { float[] width = { 10, 2 }; table = new PdfPTable(width); if (m_iMax > 1000) { m_fNorm.Size = 15; } if (m_iMax < 100) { m_fNorm.Size = 30; } } for (int i = 0; i < m_iCount; i++) { int val = s_random.Next(1, m_iMax); PdfPCell cell = new PdfPCell(); if (i == 0 || m_strType.Equals("numberstowords")) { cell.Phrase = new Phrase(val.ToString(), m_fNorm); } else { cell.Phrase = new Phrase(" "); } cell.HorizontalAlignment = Element.ALIGN_RIGHT; PdfPCell cellWords = new PdfPCell(); if (i == 0 || m_strType.Equals("wordstonumbers")) { cellWords.Phrase = new Phrase(NumberTranslator.ToWords(val), m_fNorm); } else { cellWords.Phrase = new Phrase(" "); } cell.MinimumHeight = cellHeight; cellWords.MinimumHeight = cellHeight; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cellWords.VerticalAlignment = Element.ALIGN_MIDDLE; if (m_strType.Equals("numberstowords")) { table.AddCell(cell); table.AddCell(cellWords); } else { table.AddCell(cellWords); table.AddCell(cell); } } m_doc.Add(table); } printSiteName(); m_doc.Close(); }
public override void OnEndPage(PdfWriter writer, Document document) { base.OnEndPage(writer, document); if (_Documento.IsOpen()) { BaseColor Grey = new BaseColor(128, 128, 128); PdfPTable footerTbl = new PdfPTable(3); PdfPTable footerTbl2 = new PdfPTable(1); PdfPCell Cell; string DocName = string.Empty; string Footerstring = string.Empty; Image Imagen = Image.GetInstance(_ImagenApliredPath); Imagen.Alignment = Element.ALIGN_CENTER; Imagen.ScalePercent(10); footerTbl.SetWidths(new float[] { 20, 60, 20 }); footerTbl.TotalWidth = document.PageSize.Width; footerTbl.WidthPercentage = 70; footerTbl.SpacingBefore = 10.0F; footerTbl.SpacingAfter = 5.0F; footerTbl.HorizontalAlignment = Element.ALIGN_CENTER; footerTbl.DefaultCell.Border = 0; Footerstring = Resources.PDFResource.FooterStringLinea1 + System.Environment.NewLine + Resources.PDFResource.FooterStringLinea2; DocName = _FileName; /* ************************************ ***** Armando el pie de página ***** ************************************ */ if (writer.PageNumber != 1) { footerTbl2.DefaultCell.Border = Rectangle.NO_BORDER; _Phrase = new Phrase(DocName, _Font8Normal); Cell = new PdfPCell(_Phrase) { HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Border = Rectangle.NO_BORDER, Padding = 10 }; footerTbl.AddCell(Cell); Cell = new PdfPCell(Imagen) { HorizontalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER }; footerTbl2.AddCell(Cell); _Phrase = new Phrase(Footerstring, _FontPieNormal); Cell = new PdfPCell(_Phrase) { HorizontalAlignment = Element.ALIGN_CENTER, Border = Rectangle.NO_BORDER }; footerTbl2.AddCell(Cell); if (_FileName.ToUpper().Substring(0, 3) != "PAD") { _Phrase = new Phrase(string.Format("Pág. {0}", writer.PageNumber.ToString("#0")), _FontPieNormal); } else { _Phrase = new Phrase("", _FontPieNormal); } Cell = new PdfPCell(_Phrase) { HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Border = Rectangle.NO_BORDER, Padding = 10 }; footerTbl.AddCell(footerTbl2); footerTbl.AddCell(Cell); footerTbl.WriteSelectedRows(0, -1, 0, (document.BottomMargin), writer.DirectContent); } } }
private int Crear_Archivo_Temporal() { Font ftProductos = new Font(FontFactory.GetFont(FontFactory.HELVETICA, 7, Font.NORMAL)); Document document = new Document( new Rectangle(PageSize.LETTER.Width, PageSize.LETTER.Height)); // 1 in = 25.4 mm = 72 points document.SetMargins(32.0f, 32.0f, 290.0f, 135.0f); MemoryStream m = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, m); document.Open(); float[] ancho_columnas = new float[6]; ancho_columnas[0] = 50; ancho_columnas[1] = 75; ancho_columnas[2] = 242; ancho_columnas[3] = 63; ancho_columnas[4] = 62; ancho_columnas[5] = 74; char tab = '\u0009'; foreach (CProducto objProducto in this.lstProductos) { PdfPTable tblLinea = new PdfPTable(ancho_columnas); tblLinea.TotalWidth = 532; tblLinea.DefaultCell.Border = Rectangle.NO_BORDER; tblLinea.HorizontalAlignment = Element.ALIGN_LEFT; tblLinea.LockedWidth = true; Paragraph texto = new Paragraph(string.Empty, ftProductos); PdfPCell celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.Border = Rectangle.NO_BORDER; tblLinea.AddCell(celda); texto = new Paragraph(objProducto.StrCodigo, ftProductos); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_LEFT; celda.Border = Rectangle.NO_BORDER; tblLinea.AddCell(celda); if (!string.IsNullOrEmpty(objProducto.StrDetalle)) texto = new Paragraph(objProducto.StrDescripcion + "\n" + objProducto.StrDetalle.Replace(tab.ToString(), " "), ftProductos); else texto = new Paragraph(objProducto.StrDescripcion, ftProductos); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_LEFT; celda.Border = Rectangle.NO_BORDER; if (objProducto.IntGrupoID == 0) celda.PaddingLeft = 0; else celda.PaddingLeft = 10; tblLinea.AddCell(celda); texto = new Paragraph((objProducto.SwKit ? string.Empty : objProducto.AmtCantidad.ToString("0.##")), ftProductos); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.Border = Rectangle.NO_BORDER; tblLinea.AddCell(celda); texto = new Paragraph((objProducto.SwKit ? string.Empty : objProducto.AmtValorUnitario.ToString("c")), ftProductos); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.Border = Rectangle.NO_BORDER; tblLinea.AddCell(celda); texto = new Paragraph((objProducto.SwKit ? string.Empty : objProducto.AmtImporte.ToString("c")), ftProductos); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.Border = Rectangle.NO_BORDER; tblLinea.AddCell(celda); document.Add(tblLinea); } document.Close(); m.Close(); return writer.PageNumber - 1; }
private static PdfPTable HeaderDocs(int PageNumber, string Titulo) { PdfPTable _Table = new PdfPTable(3); PdfPCell _Cell; Image _Imagen; Image _ImagenAplired; double _TotalTableWidth = _ActualPageWidth * 0.9; float[] _TableWidths = new float[] { (float)(_TotalTableWidth * 0.3), (float)(_TotalTableWidth * 0.4), (float)(_TotalTableWidth * 0.3) }; _Table.SetWidths(_TableWidths); _Table.WidthPercentage = 90; _Table.SpacingBefore = 15.0F; _Table.SpacingAfter = 10.0F; _Table.HorizontalAlignment = Element.ALIGN_CENTER; _Imagen = Image.GetInstance(_ImagenEmpresa); _Imagen.Alignment = Element.ALIGN_RIGHT; _Imagen.ScalePercent(35); _Cell = new PdfPCell(_Imagen) { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Rowspan = 3 }; _Table.AddCell(_Cell); _Phrase = new Phrase(Titulo, _Font9Bold); _Cell = new PdfPCell(_Phrase) { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Rowspan = 2 }; _Table.AddCell(_Cell); _ImagenAplired = Image.GetInstance(_ImagenApliredPath); _ImagenAplired.Alignment = Element.ALIGN_RIGHT; _ImagenAplired.ScalePercent(10); _ImagenAplired.SpacingAfter = 0.5F; _ImagenAplired.SpacingBefore = 0.2F; _Cell = new PdfPCell(_ImagenAplired) { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, FixedHeight = (float)(_ImagenAplired.Height * 0.2) }; _Table.AddCell(_Cell); string _StringFecha = String.Format(Resources.PDFResource.FechaHeaderString, _FechaDocumento); _Cell = new PdfPCell(new Phrase(_StringFecha, _Font9Normal)) { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE }; _Table.AddCell(_Cell); _Phrase = new Phrase(Titulo, _Font9Bold); _Cell = new PdfPCell(_Phrase) { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE }; _Table.AddCell(_Cell); _Phrase = new Phrase(String.Format(Resources.PDFResource.PaginaHeaderString, PageNumber.ToString("#0")), _Font9Normal); _Cell = new PdfPCell(_Phrase) { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE }; _Table.AddCell(_Cell); return(_Table); }
private PdfPTable ArmarPaginasConTablas(List <objFilaTabla> Filas, string TituloTabla, int HeaderRows) { int _NroCeldas = Filas[0].Valores.Count; _Table = new PdfPTable(_NroCeldas) { HeaderRows = HeaderRows, WidthPercentage = 100, SpacingBefore = 30.0F, HorizontalAlignment = Element.ALIGN_CENTER, }; _Table.SetWidths(Filas[0].Anchos); if (TituloTabla.Trim().Length > 0) { _Chunk = new Chunk { Font = FontFactory.GetFont("Arial", 9, Font.BOLD, BaseColor.WHITE) }; _Table.HeaderRows++; _Chunk.Append(TituloTabla); _Phrase = new Phrase(_Chunk); _Cell = new PdfPCell(_Phrase) { VerticalAlignment = Element.ALIGN_MIDDLE, Colspan = _NroCeldas, HorizontalAlignment = Element.ALIGN_CENTER, BackgroundColor = new BaseColor(System.Drawing.Color.FromArgb(0x4a3c8c)), BorderColor = BaseColor.WHITE }; _Table.AddCell(_Cell); } try { foreach (objFilaTabla _fila in Filas) { if (_fila.Titulo) { foreach (objCeldaTabla _Celda in _fila.Valores) { _Chunk = new Chunk(_Celda.Valor) { Font = FontFactory.GetFont("Arial", 9, Font.BOLD, BaseColor.WHITE) }; _Cell = new PdfPCell(new Phrase(_Chunk)) { Colspan = (_Celda.ColSpan > 0 ? _Celda.ColSpan : 1), VerticalAlignment = Element.ALIGN_MIDDLE, HorizontalAlignment = Element.ALIGN_CENTER, BackgroundColor = new BaseColor(System.Drawing.Color.FromArgb(0x4a3c8c)), BorderColor = BaseColor.WHITE }; _Table.AddCell(_Cell); } } else if (_fila.SubTitulo) { foreach (objCeldaTabla _Celda in _fila.Valores) { _Chunk = new Chunk(_Celda.Valor) { Font = FontFactory.GetFont("Arial", 9, Font.BOLD, new BaseColor(System.Drawing.Color.FromArgb(0x4a3c8c))) }; _Cell = new PdfPCell(new Phrase(_Chunk)) { Colspan = (_Celda.ColSpan > 0 ? _Celda.ColSpan : 1), VerticalAlignment = Element.ALIGN_MIDDLE, HorizontalAlignment = Element.ALIGN_CENTER, BackgroundColor = new BaseColor(System.Drawing.Color.FromArgb(0x4a3c8c)), BorderColor = BaseColor.WHITE }; _Table.AddCell(_Cell); } } else { foreach (objCeldaTabla _Celda in _fila.Valores) { switch (_Celda.Valor) { case "FondoRojo": _Cell = new PdfPCell(new Phrase("")) { Colspan = (_Celda.ColSpan > 1 ? _Celda.ColSpan : 1), BackgroundColor = BaseColor.RED, VerticalAlignment = Element.ALIGN_TOP, BorderColor = BaseColor.BLACK }; _Table.AddCell(_Cell); break; case "FondoAmarillo": _Cell = new PdfPCell(new Phrase("")) { Colspan = (_Celda.ColSpan > 1 ? _Celda.ColSpan : 1), BackgroundColor = BaseColor.YELLOW, VerticalAlignment = Element.ALIGN_TOP, BorderColor = BaseColor.BLACK }; _Table.AddCell(_Cell); break; case "FondoVerde": _Cell = new PdfPCell(new Phrase("")) { Colspan = (_Celda.ColSpan > 1 ? _Celda.ColSpan : 1), BackgroundColor = BaseColor.GREEN, VerticalAlignment = Element.ALIGN_TOP, BorderColor = BaseColor.BLACK }; _Table.AddCell(_Cell); break; default: _Chunk = new Chunk(_Celda.Valor) { Font = FontFactory.GetFont("Arial", 7, Font.NORMAL, BaseColor.BLACK) }; _Cell = new PdfPCell(new Phrase(_Chunk)) { HorizontalAlignment = _Celda.Alineacion, Colspan = (_Celda.ColSpan > 1 ? _Celda.ColSpan : 1), VerticalAlignment = Element.ALIGN_TOP, BorderColor = BaseColor.BLACK }; _Table.AddCell(_Cell); break; } } } } } catch { throw; } return(_Table); }
public MemoryStream GeneratePdfTemplate(PurchasingDispositionViewModel viewModel, int clientTimeZoneOffset) { Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 18); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9); Font small_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font smaller_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7); Font bold_font2 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font bold_font3 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9); Font bold_font4 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); PdfPCell cellLeftNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellCenterNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; PdfPCell cellCenterTopNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_TOP }; PdfPCell cellRightNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellJustifyNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_JUSTIFIED }; PdfPCell cellJustifyAllNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_JUSTIFIED_ALL }; PdfPCell cellCenter = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellRight = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellLeft = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellRightMerge = new PdfPCell() { Border = Rectangle.NO_BORDER | Rectangle.NO_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5 }; PdfPCell cellLeftMerge = new PdfPCell() { Border = Rectangle.NO_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5 }; Document document = new Document(PageSize.A4, 30, 30, 30, 30); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); string titleString = "DISPOSISI PEMBAYARAN"; Paragraph title = new Paragraph(titleString, bold_font4) { Alignment = Element.ALIGN_CENTER }; document.Add(title); bold_font.SetStyle(Font.NORMAL); string NoString = "NO : " + viewModel.DispositionNo; Paragraph dispoNumber = new Paragraph(NoString, bold_font4) { Alignment = Element.ALIGN_CENTER }; dispoNumber.SpacingAfter = 20f; document.Add(dispoNumber); #region Identity PdfPTable tableIdentity = new PdfPTable(5); tableIdentity.SetWidths(new float[] { 5f, 0.5f, 1f, 4f, 7f }); double ppn = (viewModel.Amount * 0.1); string pph = ""; double pphRate = 0; foreach (var item in viewModel.Items) { if (!item.UseVat) { ppn = 0; } if (item.UseIncomeTax) { pph = item.IncomeTax.name; pphRate = viewModel.Amount * (Convert.ToDouble(item.IncomeTax.rate) / 100); } break; } double amount = viewModel.Amount + ppn; cellLeftNoBorder.Phrase = new Phrase("Mohon Disposisi Pembelian", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code, normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{amount.ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Terbilang", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{ NumberToTextIDN.terbilang(amount) }", normal_font); cellLeftNoBorder.Colspan = 2; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Perhitungan :", bold_font3); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Biaya", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code, normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{viewModel.Amount.ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("(PPn)", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code, normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{ppn.ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Total", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code, normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{amount.ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("PPh pasal " + pph, normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code, normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{pphRate.ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Jumlah dibayar ke Supplier ", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code, normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{(amount-pphRate).ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Pembayaran ditransfer ke", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Bank, normal_font); cellLeftNoBorder.Colspan = 2; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Dibayar ke Kas Negara", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Currency.code, normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{(pphRate).ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); PdfPCell cellIdentity = new PdfPCell(tableIdentity); tableIdentity.ExtendLastRow = false; tableIdentity.SpacingAfter = 15f; document.Add(tableIdentity); #endregion #region Content PdfPTable tableContent = new PdfPTable(11); tableContent.SetWidths(new float[] { 6f, 5f, 4f, 3.5f, 3f, 3f, 2f, 2f, 3.5f, 2f, 4f }); cellCenter.Phrase = new Phrase("Nama Barang", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("No PR", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("No PO Eksternal", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Unit", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Kategori", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Jumlah", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Satuan", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Harga", bold_font); cellCenter.Colspan = 2; tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Total Harga", bold_font); cellCenter.Colspan = 2; tableContent.AddCell(cellCenter); double total = 0; foreach (PurchasingDispositionItemViewModel item in viewModel.Items) { for (int indexItem = 0; indexItem < item.Details.Count; indexItem++) { PurchasingDispositionDetailViewModel detail = item.Details[indexItem]; cellCenter.Colspan = 0; cellCenter.Phrase = new Phrase($"{detail.Product.name}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{detail.PRNo}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{item.EPONo}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{detail.Unit.name}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{detail.Category.name}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase(string.Format("{0:n2}", detail.PaidQuantity), smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{detail.DealUom.unit}", smaller_font); tableContent.AddCell(cellCenter); cellLeftMerge.Phrase = new Phrase($"{viewModel.Currency.code}", smaller_font); tableContent.AddCell(cellLeftMerge); cellRightMerge.Phrase = new Phrase($"{detail.PaidPrice.ToString("N", new CultureInfo("id-ID"))}", smaller_font); tableContent.AddCell(cellRightMerge); double subtotalPrice = detail.PaidPrice * detail.PaidQuantity; cellLeftMerge.Phrase = new Phrase($"{viewModel.Currency.code}", smaller_font); tableContent.AddCell(cellLeftMerge); cellRightMerge.Phrase = new Phrase($"{subtotalPrice.ToString("N", new CultureInfo("id-ID"))}", smaller_font); tableContent.AddCell(cellRightMerge); total += subtotalPrice; } } cellRight.Colspan = 9; cellRight.Phrase = new Phrase("Total Amount", bold_font); tableContent.AddCell(cellRight); cellLeftMerge.Phrase = new Phrase($"{viewModel.Currency.code}", smaller_font); tableContent.AddCell(cellLeftMerge); cellRightMerge.Phrase = new Phrase($"{total.ToString("N", new CultureInfo("id-ID"))}", smaller_font); tableContent.AddCell(cellRightMerge); PdfPCell cellContent = new PdfPCell(tableContent); // dont remove tableContent.ExtendLastRow = false; tableContent.SpacingAfter = 20f; document.Add(tableContent); #endregion #region note PdfPTable tableNote = new PdfPTable(3); tableNote.SetWidths(new float[] { 4f, 0.5f, 11f }); cellLeftNoBorder.Phrase = new Phrase("Note :", bold_font3); cellLeftNoBorder.Colspan = 4; tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Supplier / Agent", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Supplier.name, normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("No Order Confirmation", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.ConfirmationOrderNo, normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("No Invoice", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.InvoiceNo, normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("No Proforma", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.ProformaNo, normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Investasi", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Investation, normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Mohon dibayar Tanggal", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.PaymentDueDate.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("dd MMMM yyyy", new CultureInfo("id-ID")), normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Perhitungan", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Calculation, normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Keterangan", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Remark, normal_font); tableNote.AddCell(cellLeftNoBorder); PdfPCell cellNote = new PdfPCell(tableNote); // dont remove tableNote.ExtendLastRow = false; tableNote.SpacingAfter = 20f; document.Add(tableNote); #endregion #region signature PdfPTable tableSignature = new PdfPTable(4); PdfPCell cellSignatureContent = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; cellSignatureContent.Phrase = new Phrase("Menyetujui,", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("Mengetahui,", bold_font3); cellSignatureContent.Colspan = 2; tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Colspan = 0; cellSignatureContent.Phrase = new Phrase("Hormat Kami,", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( )", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( )", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( )", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( )", bold_font3); tableSignature.AddCell(cellSignatureContent); PdfPCell cellSignature = new PdfPCell(tableSignature); // dont remove tableSignature.ExtendLastRow = false; tableSignature.SpacingBefore = 20f; tableSignature.SpacingAfter = 20f; document.Add(tableSignature); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
//generar codigo de barra public ActionResult GenerarCodigo(string sLista) { List <string> listaEq = (List <string>)Utils.Deserialize(sLista, typeof(List <string>)); var generar = ""; Document pdfDoc = new Document(PageSize.A4, 5, 5, 10, 10); //Permite visualizar el contenido del documento que es descargado en "Mis descargas" PdfWriter.GetInstance(pdfDoc, System.Web.HttpContext.Current.Response.OutputStream); //Definiendo parametros para la fuente de la cabecera y pie de pagina iTextSharp.text.Font fuente = FontFactory.GetFont(FontFactory.HELVETICA, 8, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK); //Se define la cabecera del documento HeaderFooter cabecera = new HeaderFooter(new Phrase("Fecha: " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(), fuente), false);//'el valor es false porque no habra numeración pdfDoc.Header = cabecera; cabecera.Border = 0;// Rectangle.BOTTOM_BORDER cabecera.Alignment = HeaderFooter.ALIGN_RIGHT; HeaderFooter pie = new HeaderFooter(new Phrase("pagia", fuente), true); pdfDoc.Footer = pie; pie.Border = iTextSharp.text.Rectangle.TOP_BORDER; pie.Alignment = HeaderFooter.ALIGN_RIGHT; //Open PDF Document to write data pdfDoc.Open(); PdfPTable tblPrueba = new PdfPTable(1); tblPrueba.WidthPercentage = 100; PdfPTable TableValorqr = new PdfPTable(3); TableValorqr.WidthPercentage = 100; PdfPTable BarCodeTable = new PdfPTable(3); BarCodeTable.SetTotalWidth(new float[] { 100, 10, 100, }); BarCodeTable.DefaultCell.Border = PdfPCell.NO_BORDER; PdfPTable detalle = new PdfPTable(1); for (int i = 0; i < listaEq.Count; i++) { generar = listaEq[i].Split('|')[1]; var qr = GenerateQRCodeImage(generar); System.Drawing.Image imagen = qr; iTextSharp.text.Image pdfImage = iTextSharp.text.Image.GetInstance(imagen, System.Drawing.Imaging.ImageFormat.Jpeg); pdfImage.ScaleToFit(100.0F, 70.0F); PdfPCell letras = new PdfPCell(new Phrase("datos generales")); letras.HorizontalAlignment = 0; letras.Border = 1; BarCodeTable.AddCell(letras); PdfPCell celImg2 = new PdfPCell(pdfImage); celImg2.HorizontalAlignment = 0; celImg2.Border = 1; BarCodeTable.AddCell(celImg2); } PdfPCell addDetalle = new PdfPCell(BarCodeTable); addDetalle.Colspan = 0; addDetalle.Border = 0; addDetalle.PaddingBottom = 3; TableValorqr.AddCell(addDetalle); PdfPCell cCeldaValorss = new PdfPCell(BarCodeTable); cCeldaValorss.Colspan = 0; cCeldaValorss.Border = 1; cCeldaValorss.PaddingBottom = 3; tblPrueba.AddCell(cCeldaValorss); pdfDoc.Add(tblPrueba); // Close your PDF pdfDoc.Close(); Response.ContentType = "application/pdf"; // Set default file Name as current datetime Response.AddHeader("content-disposition", "attachment; filename=Documento.pdf"); Response.Write(pdfDoc); Response.Flush(); Response.End(); return(View()); }
public MemoryStream GeneratePdfTemplate(FormDto viewModel, int clientTimeZoneOffset, string userName) { Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 18); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9); Font small_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font smaller_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 7); Font bold_font2 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font bold_font3 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9); Font bold_font4 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10); PdfPCell cellLeftNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellCenterNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; PdfPCell cellCenterTopNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_TOP }; PdfPCell cellRightNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellJustifyNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_JUSTIFIED }; PdfPCell cellJustifyAllNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_JUSTIFIED_ALL }; PdfPCell cellCenter = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellRight = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellLeft = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellRightMerge = new PdfPCell() { Border = Rectangle.NO_BORDER | Rectangle.NO_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5 }; PdfPCell cellLeftMerge = new PdfPCell() { Border = Rectangle.NO_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5 }; Document document = new Document(PageSize.A4, 30, 30, 100, 30); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); writer.PageEvent = new TextEvents(viewModel.DispositionNo); document.Open(); string fmString = "FM-PB-00-06-011"; Paragraph fm = new Paragraph(fmString, bold_font4) { Alignment = Element.ALIGN_RIGHT }; //string titleString = "DISPOSISI PEMBAYARAN"; //Paragraph title = new Paragraph(titleString, bold_font4) { Alignment = Element.ALIGN_CENTER }; //document.Add(title); bold_font.SetStyle(Font.NORMAL); //string NoString = "NO : " + viewModel.DispositionNo; //Paragraph dispoNumber = new Paragraph(NoString, bold_font4) { Alignment = Element.ALIGN_CENTER }; //dispoNumber.SpacingAfter = 20f; //document.Add(dispoNumber); #region Identity PdfPTable tableIdentity = new PdfPTable(5); tableIdentity.SetWidths(new float[] { 5f, 0.5f, 2f, 7f, 4f }); double dpp = 0; foreach (var item in viewModel.Items) { foreach (var detail in item.Details) { dpp += detail.PaidPrice; } } double ppn = 0; string pph = ""; double pphRate = 0; foreach (var item in viewModel.Items) { if (!item.IsUseVat) { ppn = 0; } else { var vatRatDouble = Convert.ToDouble(item.VatRate); ppn = (dpp * vatRatDouble); } if (item.IsUseIncomeTax) { pph = item.IncomeTaxName; pphRate = dpp * (Convert.ToDouble(item.IncomeTaxRate) / 100); } break; } //Jumlah dibayar ke Supplier double paidToSupp = dpp + ppn - pphRate; //if (viewModel.IncomeTaxBy == "Dan Liris") //{ // paidToSupp = dpp + ppn; //} double amount = dpp + ppn; //if (viewModel.IncomeTaxBy == "Dan Liris") //{ // amount = dpp + ppn + pphRate; //} //calculate vat and incomeTax double vat = 0; double incomeTax = 0; foreach (var item in viewModel.Items) { if (item.IsPayVat) { vat += item.VatValue; } if (item.IsPayIncomeTax) { incomeTax += item.IncomeTaxValue; } } double AmountPDF = (viewModel.DPP + vat - incomeTax) + viewModel.MiscAmount; var payingDisposition = Math.Round((paidToSupp + viewModel.MiscAmount + pphRate), 2, MidpointRounding.AwayFromZero); cellLeftNoBorder.SetLeading(13f, 0f); cellLeftNoBorder.Phrase = new Phrase("Mohon Disposisi Pembayaran", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.PaymentType + " " + viewModel.CurrencyCode + " " + $"{(AmountPDF).ToString("N", new CultureInfo("id-ID"))}", normal_font);/*$"{viewModel.Amount.ToString("N", new CultureInfo("id-ID"))}", normal_font);*/ cellLeftNoBorder.Colspan = 2; tableIdentity.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase( viewModel.Currency.code + " " + $"{(paidToSupp + viewModel.PaymentCorrection + pphRate).ToString("N", new CultureInfo("id-ID")) }", normal_font); //tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 0; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Terbilang", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase($"{ NumberToTextIDN.terbilangv2(AmountPDF) }" + " " + (viewModel.CurrencyCode == "IDR" ? "Rupiah" : viewModel.CurrencyCode == "USD" ? "Dollar" : viewModel.CurrencyCode), normal_font); cellLeftNoBorder.Colspan = 2; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Perhitungan :", bold_font3); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); //calculate vat and incomeTax //double vat = 0; //double incomeTax = 0; //foreach(var item in viewModel.Items) //{ // if (item.IsPayVat) // { // vat += item.VatValue; // } // if (item.IsPayIncomeTax) // { // incomeTax += item.IncomeTaxValue; // } //} cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Biaya", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 3; cellLeftNoBorder.Phrase = new Phrase(viewModel.CurrencyCode + " " + $"{viewModel.DPP.ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("(PPn)", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 3; cellLeftNoBorder.Phrase = new Phrase(viewModel.CurrencyCode + " " + $"{viewModel.VatValue.ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Total", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 3; cellLeftNoBorder.Phrase = new Phrase(viewModel.CurrencyCode + " " + $"{(viewModel.DPP + vat).ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); var pphDanliris = pphRate; //if (viewModel.IncomeTaxBy == "Dan Liris") //{ // pphDanliris = 0; //} cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("PPh " + pph, normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 3; cellLeftNoBorder.Phrase = new Phrase(viewModel.CurrencyCode + " " + $"{viewModel.IncomeTaxValue.ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Jumlah dibayar ke Supplier ", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 2; cellLeftNoBorder.Phrase = new Phrase(viewModel.CurrencyCode + " " + $"{(viewModel.DPP + vat - incomeTax).ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Biaya Lain - Lain", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 3; cellLeftNoBorder.Phrase = new Phrase(viewModel.CurrencyCode + " " + $"{viewModel.MiscAmount.ToString("N", new CultureInfo("id-ID"))}", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); PdfPCell cellSuppLeft = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellSuppMid = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; PdfPCell cellSuppRight = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; cellSuppLeft.Phrase = new Phrase("Total dibayar ke Supplier", normal_font); tableIdentity.AddCell(cellSuppLeft); cellSuppMid.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellSuppMid); cellSuppRight.Colspan = 2; cellSuppRight.Phrase = new Phrase(viewModel.CurrencyCode + " " + $"{(AmountPDF).ToString("N", new CultureInfo("id-ID"))}", normal_font); tableIdentity.AddCell(cellSuppRight); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("", normal_font); cellLeftNoBorder.Colspan = 4; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Pembayaran ditransfer ke", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Bank, normal_font); cellLeftNoBorder.Colspan = 3; tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Dibayar ke Kas Negara", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableIdentity.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 3; cellLeftNoBorder.Phrase = new Phrase(viewModel.CurrencyCode + " " + $"{(viewModel.IncomeTaxValue).ToString("N", new CultureInfo("id-ID")) }", normal_font); tableIdentity.AddCell(cellLeftNoBorder); PdfPCell cellIdentity = new PdfPCell(tableIdentity); tableIdentity.ExtendLastRow = false; tableIdentity.SpacingAfter = 15f; document.Add(tableIdentity); #endregion #region Content PdfPTable tableContent = new PdfPTable(9); tableContent.SetWidths(new float[] { 6f, 5f, 4f, 3f, 3f, 2.5f, 2.5f, 3.5f, 3f }); cellCenter.Phrase = new Phrase("Nama Barang", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("No PO Internal", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("No PO Eksternal", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("QTY Dipesan", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("QTY Dibayar", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("QTY Sisa", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Satuan", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("Harga Satuan", bold_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase("% Over Qty", bold_font); tableContent.AddCell(cellCenter); double total = 0; double totalPurchase = 0; foreach (FormItemDto item in viewModel.Items) { for (int indexItem = 0; indexItem < item.Details.Count; indexItem++) { FormDetailDto detail = item.Details[indexItem]; var unitName = detail.UnitName; //var unitName = ""; //var unitId = detail.Unit._id; //if (unitId == "50") //{ // unitName = "WEAVING"; //} //else if (unitId == "35") //{ // unitName = "SPINNING 1"; //} //else //{ //unitName = detail.UnitName; //} cellLeft.Colspan = 0; cellLeft.Phrase = new Phrase($"{detail.ProductName}", smaller_font); tableContent.AddCell(cellLeft); cellCenter.Colspan = 0; cellCenter.Phrase = new Phrase($"{detail.IPONo}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{item.EPONo}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{Math.Round(detail.QTYOrder, 2)}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{Math.Round(detail.QTYPaid, 2)}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{Math.Round(detail.QTYRemains, 2)}", smaller_font); tableContent.AddCell(cellCenter); cellCenter.Phrase = new Phrase($"{detail.QTYUnit}", smaller_font); tableContent.AddCell(cellCenter); cellRightMerge.Phrase = new Phrase($"{detail.PricePerQTY.ToString("N", new CultureInfo("id-ID"))}", smaller_font); tableContent.AddCell(cellRightMerge); cellCenter.Phrase = new Phrase($"{detail.PercentageOverQTY.ToString("N", new CultureInfo("id-ID"))}", smaller_font); tableContent.AddCell(cellCenter); double subtotalPrice = detail.PercentageOverQTY; total += detail.PaidPrice; totalPurchase += (detail.PricePerQTY * detail.QTYOrder); } } PdfPCell cellContent = new PdfPCell(tableContent); // dont remove tableContent.ExtendLastRow = false; tableContent.SpacingAfter = 10f; document.Add(tableContent); #endregion #region note PdfPTable tableNote = new PdfPTable(3); tableNote.SetWidths(new float[] { 4f, 0.5f, 11f }); cellLeftNoBorder.Phrase = new Phrase("Note :", bold_font3); cellLeftNoBorder.Colspan = 4; tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Kategori", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Category, normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Colspan = 0; cellLeftNoBorder.Phrase = new Phrase("Supplier / Agent", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.SupplierName, normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("No Order Confirmation", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.ConfirmationOrderNo, normal_font); tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase("No Invoice", normal_font); //tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase(":", normal_font); //tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase(viewModel.InvoiceNo, normal_font); //tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("No Proforma/Invoice", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.ProformaNo, normal_font); tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase("Investasi", normal_font); //tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase(":", normal_font); //tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase(viewModel.Investation, normal_font); //tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Mohon dibayar Tanggal", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.PaymentDueDate.ToOffset(new TimeSpan(clientTimeZoneOffset, 0, 0)).ToString("dd MMMM yyyy", new CultureInfo("id-ID")), normal_font); tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase("Bank", normal_font); //tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase(":", normal_font); //tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase(viewModel.Bank, normal_font); //tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase("Keterangan", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(viewModel.Remark, normal_font); tableNote.AddCell(cellLeftNoBorder); var ppnPurchase = viewModel.VatValue > 0 ? (totalPurchase * 10 / 100) : 0; cellLeftNoBorder.Phrase = new Phrase("Total Pembelian", normal_font); tableNote.AddCell(cellLeftNoBorder); cellLeftNoBorder.Phrase = new Phrase(":", normal_font); tableNote.AddCell(cellLeftNoBorder); //cellLeftNoBorder.Phrase = new Phrase($"{viewModel.CurrencyCode}" + " " + $"{(totalPurchase + ppnPurchase).ToString("N", new CultureInfo("id-ID"))}", normal_font); cellLeftNoBorder.Phrase = new Phrase($"{viewModel.CurrencyCode}" + " " + $"{((viewModel.DPP + vat) - incomeTax).ToString("N", new CultureInfo("id-ID"))}", normal_font); tableNote.AddCell(cellLeftNoBorder); PdfPCell cellNote = new PdfPCell(tableNote); // dont remove tableNote.ExtendLastRow = false; tableNote.SpacingAfter = 20f; document.Add(tableNote); #endregion #region beban PdfPTable tableBeban = new PdfPTable(1); tableBeban.SetWidths(new float[] { 5f }); cellLeftNoBorder.Phrase = new Phrase("Beban Unit :", bold_font3);; tableBeban.AddCell(cellLeftNoBorder); var AmountPerUnit = viewModel.Items.SelectMany(s => s.Details) .GroupBy( key => new { key.UnitId, key.UnitName, key.UnitCode }, val => val, (key, val) => new { Key = key, Value = val } ).ToList(); foreach (var perUnit in AmountPerUnit) { var sumPerUnit = perUnit.Value.Sum(t => (t.PaidPrice) + (viewModel.Items.Where(a => a.Id == t.GarmentDispositionPurchaseItemId).FirstOrDefault().IsPayVat ? t.PaidPrice * 0.1 : 0) - (t.PaidPrice * (viewModel.Items.Where(a => a.Id == t.GarmentDispositionPurchaseItemId).FirstOrDefault()?.IncomeTaxRate / 100)))?.ToString("N", new CultureInfo("id-ID")); cellLeftNoBorder.Phrase = new Phrase($"- {perUnit.Key.UnitName} = {sumPerUnit}", bold_font3); tableBeban.AddCell(cellLeftNoBorder); } PdfPCell cellBeban = new PdfPCell(tableBeban); // dont remove tableBeban.ExtendLastRow = false; document.Add(tableBeban); #endregion #region signature PdfPTable tableSignature = new PdfPTable(5); tableSignature.SetWidths(new float[] { 4f, 4f, 4f, 4f, 4.5f }); PdfPCell cellSignatureContent = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; cellSignatureContent.Phrase = new Phrase("", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("", bold_font3); cellSignatureContent.Colspan = 3; tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Colspan = 0; cellSignatureContent.Phrase = new Phrase("Sukoharjo, " + viewModel.CreatedUtc.ToString("dd MMMM yyyy", new CultureInfo("id-ID")), bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Colspan = 2; cellSignatureContent.Phrase = new Phrase("Menyetujui,", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("Mengetahui,", bold_font3); cellSignatureContent.Colspan = 2; tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Colspan = 0; cellSignatureContent.Phrase = new Phrase("Hormat Kami,", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( Hendro Suseno )\n Direktur Keuangan", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( Verifikasi )", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( Kabag Pembelian )", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( Kasie Pembelian )", bold_font3); tableSignature.AddCell(cellSignatureContent); cellSignatureContent.Phrase = new Phrase("\n\n\n\n\n\n\n( " + viewModel.CreatedBy + " )", bold_font3); tableSignature.AddCell(cellSignatureContent); //PdfPCell cellSignatureContentDir = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER,VerticalAlignment=Element.ALIGN_TOP }; //cellSignatureContentDir.Phrase = new Phrase("\n\n\n\n\n\n\n Direktur Keuangan ", bold_font3); //tableSignature.AddCell(cellSignatureContentDir); //cellSignatureContentDir.Colspan = 4; //cellSignatureContentDir.Phrase = new Phrase("", bold_font3); //tableSignature.AddCell(cellSignatureContentDir); PdfPCell cellSignature = new PdfPCell(tableSignature); // dont remove tableSignature.ExtendLastRow = false; tableSignature.SpacingBefore = 10f; tableSignature.SpacingAfter = 20f; document.Add(tableSignature); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GetPDF(Response <QuotationDto> response, string fullNameUser) { MemoryStream memoryStream = new MemoryStream(); Generator generator = new Generator(); TextUtils textUtils = new TextUtils(); using (Document document = new Document(PageSize.A4, 40, 40, 140, 40)) { try { PdfWriter pdfWriter = PdfWriter.GetInstance(document, memoryStream); pdfWriter.CloseStream = false; pdfWriter.PageEvent = new ITextEvents(); document.Open(); for (int i = 1; i <= 29; i++) { if (i == 1) { var pdfPTable = generator.GetPageOne(response); document.Add(pdfPTable); document.NewPage(); } if (i == 2) { var elements = generator.GetPageTwo(response); document.Add(elements); document.NewPage(); } if (i == 3) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 4) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 5) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 6) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 7) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.SetPageSize(PageSize.A4.Rotate()); document.NewPage(); } if (i == 8) { var elements = generator.GetPageEight(response, fullNameUser); document.Add(elements); document.SetPageSize(PageSize.A4); document.NewPage(); } if (i == 9) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 10) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 11) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 12) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 13) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 14) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 15) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 16) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 17) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 18) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 19) { //document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate()); //document.SetPageSize(PageSize.A4.Rotate()); var titleFont = FontFactory.GetFont("Arial", 12, Font.BOLD); var titleFontBlue = FontFactory.GetFont("Arial", 14, Font.NORMAL, BaseColor.BLUE); var boldTableFont = FontFactory.GetFont("Arial", 8, Font.BOLD); var bodyFont = FontFactory.GetFont("Arial", 8, Font.NORMAL); var EmailFont = FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLUE); BaseColor TabelHeaderBackGroundColor = WebColors.GetRGBColor("#EEEEEE"); int countProfile = response.Data.QuotationProfile.Count; int totalColumns = countProfile + 2; //Create body table PdfPTable itemTable = new PdfPTable(totalColumns); itemTable.HorizontalAlignment = 0; itemTable.WidthPercentage = 100; //itemTable.SetWidths(new float[] { 5, 40, 10, 20, 25 }); // then set the column's __relative__ widths itemTable.SpacingAfter = 40; itemTable.DefaultCell.Border = Rectangle.BOX; PdfPCell cell1 = new PdfPCell(new Phrase("", boldTableFont)); cell1.BackgroundColor = TabelHeaderBackGroundColor; cell1.HorizontalAlignment = Element.ALIGN_CENTER; itemTable.AddCell(cell1); PdfPCell cell2 = new PdfPCell(new Phrase("", boldTableFont)); cell2.BackgroundColor = TabelHeaderBackGroundColor; cell2.HorizontalAlignment = 1; itemTable.AddCell(cell2); foreach (var item in response.Data.QuotationProfile) { itemTable.AddCell(new PdfPCell(new Phrase(item.ProfileName, boldTableFont))).HorizontalAlignment = Element.ALIGN_CENTER; } PdfPCell cell2A = new PdfPCell(new Phrase("", boldTableFont)); cell2A.BackgroundColor = TabelHeaderBackGroundColor; cell2A.HorizontalAlignment = Element.ALIGN_CENTER; itemTable.AddCell(cell2A); PdfPCell cell2B = new PdfPCell(new Phrase("", boldTableFont)); cell2B.BackgroundColor = TabelHeaderBackGroundColor; cell2B.HorizontalAlignment = 1; itemTable.AddCell(cell2B); foreach (var item in response.Data.QuotationProfile) { itemTable.AddCell(new PdfPCell(new Phrase(item.ServiceTypeName, boldTableFont))).HorizontalAlignment = Element.ALIGN_CENTER; } //foreach (DataRow row in dt.Rows) //{ // PdfPCell numberCell = new PdfPCell(new Phrase("1", bodyFont)); // numberCell.HorizontalAlignment = 1; // numberCell.PaddingLeft = 10f; // numberCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; // itemTable.AddCell(numberCell); // var _phrase = new Phrase(); // _phrase.Add(new Chunk("New Signup Subscription Plan\n", EmailFont)); // _phrase.Add(new Chunk("Subscription Plan description will add here.", bodyFont)); // PdfPCell descCell = new PdfPCell(_phrase); // descCell.HorizontalAlignment = 0; // descCell.PaddingLeft = 10f; // descCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; // itemTable.AddCell(descCell); // PdfPCell qtyCell = new PdfPCell(new Phrase("1", bodyFont)); // qtyCell.HorizontalAlignment = 1; // qtyCell.PaddingLeft = 10f; // qtyCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; // itemTable.AddCell(qtyCell); // //PdfPCell amountCell = new PdfPCell(new Phrase("$100", bodyFont)); // //amountCell.HorizontalAlignment = 1; // //amountCell.PaddingLeft = 10f; // //amountCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; // //itemTable.AddCell(amountCell); // //PdfPCell totalamtCell = new PdfPCell(new Phrase("$100", bodyFont)); // //totalamtCell.HorizontalAlignment = 1; // //totalamtCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; // //itemTable.AddCell(totalamtCell); //} //// Table footer //PdfPCell totalAmtCell1 = new PdfPCell(new Phrase("")); //totalAmtCell1.Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER; //itemTable.AddCell(totalAmtCell1); //PdfPCell totalAmtCell2 = new PdfPCell(new Phrase("")); //totalAmtCell2.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER; //itemTable.AddCell(totalAmtCell2); //PdfPCell totalAmtCell3 = new PdfPCell(new Phrase("")); //totalAmtCell3.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER; //itemTable.AddCell(totalAmtCell3); //PdfPCell totalAmtStrCell = new PdfPCell(new Phrase("Total Amount", boldTableFont)); //totalAmtStrCell.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER; //totalAmtStrCell.HorizontalAlignment = 1; //itemTable.AddCell(totalAmtStrCell); //PdfPCell totalAmtCell = new PdfPCell(new Phrase("$100", boldTableFont)); //totalAmtCell.HorizontalAlignment = 1; //itemTable.AddCell(totalAmtCell); //PdfPCell cell = new PdfPCell(new Phrase("***NOTICE: A finance charge of 1.5% will be made on unpaid balances after 30 days. ***", bodyFont)); //cell.Colspan = 5; //cell.HorizontalAlignment = 1; //itemTable.AddCell(cell); document.Add(itemTable); document.NewPage(); } if (i == 20) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 21) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 22) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 23) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 24) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 25) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 26) { Paragraph elements = new Paragraph("Anexo 4. Registro como proveedor de Antamina", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; Image image = Image.GetInstance(HttpContext.Current.Server.MapPath("~/images/certificado_registro.png")); image.ScaleToFit(450f, 550f); image.Alignment = Image.ALIGN_CENTER; image.PaddingTop = 20f; document.Add(elements); document.Add(image); document.NewPage(); } if (i == 27) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 28) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } if (i == 29) { Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black); elements.Alignment = Element.ALIGN_JUSTIFIED; document.Add(elements); document.NewPage(); } } document.Close(); byte[] byteInfo = memoryStream.ToArray(); memoryStream.Write(byteInfo, 0, byteInfo.Length); memoryStream.Position = 0; } catch (Exception ex) { ErrorUtilities.AddLog(ex); } } return(memoryStream); }
public ActionResult DesignationMasterPdf() { string FileName = Path.Combine(Server.MapPath("~/Downloads/DesignationDetails/")); string filetodownload = "Designation Report " + DateTime.Now.Date.ToString("dd-MM-yyyy") + ".pdf"; string pathString = System.IO.Path.Combine(FileName, filetodownload); var file = System.IO.File.Create(pathString); file.Close(); FileStream stream = new FileStream(pathString, FileMode.OpenOrCreate); Document doc = new Document(PageSize.A4.Rotate(), 40f, 40f, 20f, 20f); PdfWriter pdfWriter = PdfWriter.GetInstance(doc, stream); var F = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12, BaseColor.WHITE); var H = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 10, BaseColor.WHITE); var P = new BaseColor(102, 51, 153); var I = FontFactory.GetFont(FontFactory.HELVETICA, 9, P); DataTable dt = new DataTable(); SqlConnection SqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSQL_ConnectionString"].ConnectionString); SqlCommand Sqlcomrep = new SqlCommand(); Sqlcomrep.Connection = SqlCon; Sqlcomrep.CommandType = CommandType.StoredProcedure; Sqlcomrep.CommandTimeout = 500; Sqlcomrep.CommandText = "DesignationMList_get"; SqlDataAdapter sqlda = new SqlDataAdapter(Sqlcomrep); SqlCon.Open(); sqlda.Fill(dt); SqlCon.Close(); ////////////////////////////////////////////////////////// PdfPTable table0 = new PdfPTable(1); //table0.DefaultCell.Border = Rectangle.NO_BORDER; table0.WidthPercentage = 40; table0.HorizontalAlignment = Element.ALIGN_CENTER; PdfPCell cell0; cell0 = new PdfPCell(new Phrase("DESIGNATION MASTER", F)); cell0.VerticalAlignment = Element.ALIGN_MIDDLE; cell0.HorizontalAlignment = Element.ALIGN_CENTER; cell0.PaddingTop = 5; cell0.PaddingBottom = 7; // cell0.Rowspan = 3; cell0.BackgroundColor = new BaseColor(0, 119, 142); table0.AddCell(cell0); //////////////////////////////////////////////////////////// PdfPTable table = new PdfPTable(5); table.WidthPercentage = 40; PdfPCell cell; cell = new PdfPCell(new Phrase("Sl.No", H)); cell.Colspan = 1; cell.PaddingBottom = 5; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = new BaseColor(0, 119, 142); table.AddCell(cell); cell = new PdfPCell(new Phrase("DESIGNATION NAME", H)); cell.PaddingBottom = 5; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.Colspan = 4; cell.BackgroundColor = new BaseColor(0, 119, 142); table.AddCell(cell); /////////////////////////////// int slno = 0; for (int i = 0; i < dt.Rows.Count; i++) { slno = slno + 1; cell = new PdfPCell(new Phrase(slno.ToString(), I)); cell.Colspan = 1; cell.PaddingBottom = 5; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(cell); // cell = new PdfPCell(new Phrase("aaaaaaaaaaaaaa", I)); cell = new PdfPCell(new Phrase(dt.Rows[i].Field<string>("DesignationName").ToString(), I)); cell.Colspan = 4; cell.PaddingBottom = 5; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(cell); } // table0.SpacingBefore = 10f; table0.SpacingAfter = 12.5f; // table.SpacingBefore = 10f; // table.SpacingAfter = 12.5f; doc.Open(); doc.Add(table0); doc.Add(table); doc.Close(); return Json(filetodownload); }
public override void OnEndPage(iTextSharp.text.pdf.PdfWriter writer, iTextSharp.text.Document document) { base.OnEndPage(writer, document); iTextSharp.text.Font baseFontNormal = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK); //Create PdfTable object PdfPTable pdfTab = new PdfPTable(3); //Row 1 Phrase p11 = null; try { Image img = Image.GetInstance(NFe.Components.Propriedade.PastaExecutavel + "\\logounimake.png"); img.ScaleAbsolute(120, 25); //img.ScalePercent(10);//0,100); //img.ScaleAbsoluteHeight(20); //img.ScaleAbsoluteWidth(110); img.ScaleToFitHeight = false; //img.SetAbsolutePosition(100, 200); var ck = new Chunk(img, 0, 0); p11 = new Phrase(ck); } catch { p11 = new Phrase(ConfiguracaoApp.NomeEmpresa, baseFontNormal); } PdfPCell pdfCell1 = new PdfPCell(p11); pdfCell1.HorizontalAlignment = Element.ALIGN_LEFT;//.ALIGN_CENTER; pdfCell1.Border = 0; String text = "Página " + writer.PageNumber + " de "; //Add paging to header { //cb.BeginText(); //cb.SetFontAndSize(bf, 10); //cb.SetTextMatrix(document.PageSize.GetRight(107), document.PageSize.GetTop(45)); //cb.ShowText(text); //cb.EndText(); //float len = bf.GetWidthPoint(text, 10); ////Adds "12" in Page 1 of 12 //cb.AddTemplate(headerTemplate, document.PageSize.GetRight(107) + len, document.PageSize.GetTop(45)); } //Add paging to footer { float p1 = 92; cb.BeginText(); cb.SetFontAndSize(bf, 10); cb.SetTextMatrix(document.PageSize.GetRight(p1), document.PageSize.GetBottom(30)); cb.ShowText(text); cb.EndText(); cb.BeginText(); cb.SetFontAndSize(bf, 10); cb.SetTextMatrix(20f, document.PageSize.GetBottom(30)); cb.ShowText("Data da criação: " + PrintTime.ToLongDateString()); cb.EndText(); float len = bf.GetWidthPoint(text, 10); cb.AddTemplate(footerTemplate, document.PageSize.GetRight(p1) + len, document.PageSize.GetBottom(30)); } //Row 2 PdfPCell pdfCell4_SubTitle = new PdfPCell(new Phrase("Layouts arquivos texto", baseFontNormal)); pdfCell4_SubTitle.HorizontalAlignment = Element.ALIGN_CENTER; pdfCell4_SubTitle.VerticalAlignment = Element.ALIGN_TOP; pdfCell4_SubTitle.Border = 0; pdfCell4_SubTitle.Colspan = 3; //Row 3 //iTextSharp.text.Font baseFontBig = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 8f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK); //PdfPCell pdfCell5 = new PdfPCell(new Phrase("Data da criação:" + PrintTime.ToShortDateString(), baseFontBig)); //pdfCell5.HorizontalAlignment = Element.ALIGN_LEFT; //pdfCell5.VerticalAlignment = Element.ALIGN_MIDDLE; //pdfCell5.Border = 0; //PdfPCell pdfCell6 = new PdfPCell(); //pdfCell6.HorizontalAlignment = Element.ALIGN_CENTER; //pdfCell6.VerticalAlignment = Element.ALIGN_MIDDLE; //pdfCell6.Border = 0; //PdfPCell pdfCell7 = new PdfPCell(new Phrase("Hora:" + string.Format("{0:t}", PrintTime), baseFontBig)); //pdfCell7.HorizontalAlignment = Element.ALIGN_RIGHT; //pdfCell7.VerticalAlignment = Element.ALIGN_MIDDLE; //pdfCell7.Border = 0; //set the alignment of all three cells and set border to 0 PdfPCell pdfCell3 = new PdfPCell(); pdfCell3.HorizontalAlignment = Element.ALIGN_CENTER; pdfCell3.VerticalAlignment = Element.ALIGN_MIDDLE; pdfCell3.Border = 0; Phrase p1Header = new Phrase(ConfiguracaoApp.NomeEmpresa, baseFontNormal); PdfPCell pdfCell_p1Header = new PdfPCell(p1Header); pdfCell_p1Header.HorizontalAlignment = Element.ALIGN_CENTER; pdfCell_p1Header.VerticalAlignment = Element.ALIGN_BOTTOM; pdfCell_p1Header.Border = 0; //add all three cells into PdfTable pdfTab.AddCell(pdfCell1); pdfTab.AddCell(pdfCell_p1Header); pdfTab.AddCell(pdfCell3); pdfTab.AddCell(pdfCell4_SubTitle); //pdfTab.AddCell(pdfCell5); //pdfTab.AddCell(pdfCell6); //pdfTab.AddCell(pdfCell7); pdfTab.TotalWidth = document.PageSize.Width - 80f; pdfTab.WidthPercentage = 70; //pdfTab.HorizontalAlignment = Element.ALIGN_CENTER; //call WriteSelectedRows of PdfTable. This writes rows from PdfWriter in PdfTable //first param is start row. -1 indicates there is no end row and all the rows to be included to write //Third and fourth param is x and y position to start writing pdfTab.WriteSelectedRows(0, -1, 40, document.PageSize.Height - 30, writer.DirectContent); //set pdfContent value cb.MoveTo(20, document.PageSize.Height - 80); cb.LineTo(document.PageSize.Width - 20, document.PageSize.Height - 80); cb.Stroke(); //Move the pointer and draw line to separate header section from rest of page //cb.MoveTo(40, document.PageSize.Height - 100); //cb.LineTo(document.PageSize.Width - 40, document.PageSize.Height - 100); //cb.Stroke(); //Move the pointer and draw line to separate footer section from rest of page cb.MoveTo(20, document.PageSize.GetBottom(50)); cb.LineTo(document.PageSize.Width - 20, document.PageSize.GetBottom(50)); cb.Stroke(); }
protected void GenerateReport(object sender, EventArgs e) { //BECommon objBECommon = new BECommon(); //BCommon objBCommon = new BCommon(); //objBECommon.IntUserID = int.Parse(Session[BaseClass.EnumPageSessions.USERID].ToString()); //objBECommon.DateStartDate = StartDate; //objBECommon.DateEndDate = EndDate; //objBCommon.BGetExamBillingDetails(objBECommon); //DataTable objDt = objBECommon.DsResult.Tables[0]; //for (int i = 1; i < objBECommon.DsResult.Tables.Count; i++) //{ // objDt.Merge(objBECommon.DsResult.Tables[i]); //} //objDt.AcceptChanges(); ////gvReports.DataSource = objDt; //if (objDt != null && objDt.Rows.Count > 0) //{ // gvReports.DataSource = objDt; // //gvReports.Rebind(); // trExportButtons.Visible = true; // trGridView.Visible = true; //} //else //{ // gvReports.DataSource = new Object[0]; // trExportButtons.Visible = false; // trGridView.Visible = true; //} //string paidexamfee = string.Empty; //string paidondemandfee = string.Empty; //BEAdmin objBEAdmin = new BEAdmin(); //BAdmin objBAdmin = new BAdmin(); //objBAdmin.BGetPaymentMode(objBEAdmin); //if (objBEAdmin.DtResult != null && objBEAdmin.DtResult.Rows.Count > 0) //{ // paidexamfee = objBEAdmin.DtResult.Rows[0]["PaidBy_ExamFee"].ToString(); // paidondemandfee = objBEAdmin.DtResult.Rows[0]["PaidBy_OnDemandFee"].ToString(); //} //lblRecords.Text = objDt.Rows.Count.ToString(); ////lblExamFee.Text = "$" + objDt.Compute("SUM(ExamFee)", String.Empty); ////lblOnDemandFee.Text = "$" + objDt.Compute("SUM(OndemandFee)", String.Empty); //if (paidexamfee == "University" && paidondemandfee != "University") //{ // //tdondemandfee.Visible = false; // //tdondemandfeelabel.Visible = false; // //tdexamfeelabel.Visible = true; // //tdexamfee.Visible = true; // lblexamfeetitle.Text = "Total Exam Fee (University) :"; // lblondemandtitle.Text = "Total On-demand Fee (Student) :"; // lbltotalfeetitle.Text = "Total Fee (University) :"; // lblExamFee.Text = "$" + objDt.Compute("SUM(ExamFee)", String.Empty); // lblOnDemandFee.Text = "$" + objDt.Compute("SUM(OndemandFee)", String.Empty); // lblTotalFee.Text = "$" + objDt.Compute("SUM(ExamFee)", String.Empty); //} //else if (paidexamfee != "University" && paidondemandfee == "University") //{ // //tdexamfeelabel.Visible = false; // //tdexamfee.Visible = false; // //tdondemandfee.Visible = true; // //tdondemandfeelabel.Visible = true; // lblexamfeetitle.Text = "Total Exam Fee (Student) :"; // lblondemandtitle.Text = "Total On-demand Fee (University) :"; // lbltotalfeetitle.Text = "Total Fee (University) :"; // lblExamFee.Text = "$" + objDt.Compute("SUM(ExamFee)", String.Empty); // lblOnDemandFee.Text = "$" + objDt.Compute("SUM(OndemandFee)", String.Empty); // lblTotalFee.Text = "$" + objDt.Compute("SUM(OndemandFee)", String.Empty); //} //else if (paidexamfee == "University" && paidondemandfee == "University") //{ // //tdexamfeelabel.Visible = true; // //tdexamfee.Visible = true; // //tdondemandfee.Visible = true; // //tdondemandfeelabel.Visible = true; // lblexamfeetitle.Text = "Total Exam Fee (University) :"; // lblondemandtitle.Text = "Total On-demand Fee (University) :"; // lbltotalfeetitle.Text = "Total Fee (University) :"; // lblExamFee.Text = "$" + objDt.Compute("SUM(ExamFee)", String.Empty); // lblOnDemandFee.Text = "$" + objDt.Compute("SUM(OndemandFee)", String.Empty); // lblTotalFee.Text = "$" + objDt.Compute("SUM(TotalFee)", String.Empty); //} //else if (paidexamfee != "University" && paidondemandfee != "University") //{ // //lblTotalFee.Text = "$" + objDt.Compute("SUM(TotalFee)", String.Empty); // //tdexamfeelabel.Visible = false; // //tdexamfee.Visible = false; // //tdondemandfee.Visible = false; // //tdondemandfeelabel.Visible = false; // //tdtotalfee.Visible = false; // //tdtotalfeelabel.Visible = false; // lblexamfeetitle.Text = "Total Exam Fee (Student) :"; // lblondemandtitle.Text = "Total On-demand Fee (Student) :"; // lbltotalfeetitle.Text = "Total Fee (Student) :"; // lblExamFee.Text = "$" + objDt.Compute("SUM(ExamFee)", String.Empty); // lblOnDemandFee.Text = "$" + objDt.Compute("SUM(OndemandFee)", String.Empty); // lblTotalFee.Text = "$" + objDt.Compute("SUM(TotalFee)", String.Empty); //} BEAdmin objBEAdmin = new BEAdmin(); BAdmin objBAdmin = new BAdmin(); objBAdmin.BGetClientContactDetails(objBEAdmin); string ExamIDSeries = string.Empty; string strOrgName = string.Empty; string strStreet1 = string.Empty; string strStreet2 = string.Empty; string strCity = string.Empty; string strRegion = string.Empty; string strPostalCode = string.Empty; string strName = string.Empty; string strDesignation = string.Empty; if (objBEAdmin.DsResult != null && objBEAdmin.DsResult.Tables[0].Rows.Count > 0) { ExamIDSeries = objBEAdmin.DsResult.Tables[0].Rows[0]["ExamIDSeries"].ToString(); } if (objBEAdmin.DsResult != null && objBEAdmin.DsResult.Tables[1].Rows.Count > 0) { strOrgName = objBEAdmin.DsResult.Tables[1].Rows[0]["OrganizationName"].ToString(); strStreet1 = objBEAdmin.DsResult.Tables[1].Rows[0]["Street1"].ToString(); strStreet2 = objBEAdmin.DsResult.Tables[1].Rows[0]["Street2"].ToString(); strCity = objBEAdmin.DsResult.Tables[1].Rows[0]["City"].ToString(); strRegion = objBEAdmin.DsResult.Tables[1].Rows[0]["Region"].ToString(); strPostalCode = objBEAdmin.DsResult.Tables[1].Rows[0]["PostalCode"].ToString(); strName = objBEAdmin.DsResult.Tables[1].Rows[0]["Name"].ToString(); strDesignation = objBEAdmin.DsResult.Tables[1].Rows[0]["Designation"].ToString(); } Document document = new Document(PageSize.A4, 88f, 88f, 10f, 10f); Font NormalFont = FontFactory.GetFont("Times New Roman", 12, Font.NORMAL, Color.BLACK); using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream()) { PdfWriter writer = PdfWriter.GetInstance(document, memoryStream); //Phrase phrase = null; PdfPCell cell = null; PdfPTable table = null; //Color color = null; document.Open(); //Header Table table = new PdfPTable(1); table.TotalWidth = 450f; table.LockedWidth = true; table.SetWidths(new float[] { 1f }); document.Add(table); table = new PdfPTable(4); table.HorizontalAlignment = Element.ALIGN_CENTER; table.LockedWidth = true; table.SetWidths(new float[] { 1f, 1f, 1f, 1f }); table.SpacingBefore = 20f; table.TotalWidth = 450f; cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER); cell.Colspan = 1; table.AddCell(cell); cell = PhraseCell(new Phrase("Secure Proctor", FontFactory.GetFont("Times New Roman", 12, Font.UNDERLINE, Color.BLACK)), PdfPCell.ALIGN_CENTER); cell.Colspan = 2; cell.PaddingTop = 20f; table.AddCell(cell); cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER); cell.Colspan = 1; cell.PaddingBottom = 60f; table.AddCell(cell); cell = PhraseCell(new Phrase("BILL TO:\n", FontFactory.GetFont("Times New Roman", 10, Font.BOLD, Color.BLACK)), PdfPCell.ALIGN_LEFT); cell.Colspan = 2; table.AddCell(cell); cell = PhraseCell(new Phrase("Date:", FontFactory.GetFont("Times New Roman", 10, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_RIGHT); cell.Colspan = 1; cell.PaddingRight = 29f; table.AddCell(cell); cell = PhraseCell(new Phrase(String.Format("{0:d}", DateTime.Today), FontFactory.GetFont("Times New Roman", 10, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_LEFT); cell.Colspan = 1; table.AddCell(cell); cell = PhraseCell(new Phrase(strOrgName, FontFactory.GetFont("Times New Roman", 10, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_LEFT); cell.Colspan = 2; table.AddCell(cell); cell = PhraseCell(new Phrase("Invoice #:", FontFactory.GetFont("Times New Roman", 10, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_RIGHT); cell.Colspan = 1; cell.PaddingRight = 10f; table.AddCell(cell); cell = PhraseCell(new Phrase(String.Format("{0:yyMMdd}", DateTime.Today) + ExamIDSeries, FontFactory.GetFont("Times New Roman", 10, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_LEFT); cell.Colspan = 1; table.AddCell(cell); cell = PhraseCell(new Phrase(strName + "\n", FontFactory.GetFont("Times New Roman", 10, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_LEFT); cell.Colspan = 2; table.AddCell(cell); cell = PhraseCell(new Phrase("Terms:", FontFactory.GetFont("Times New Roman", 10, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_RIGHT); cell.Colspan = 1; cell.PaddingRight = 22f; table.AddCell(cell); cell = PhraseCell(new Phrase("Due On Receipt", FontFactory.GetFont("Times New Roman", 10, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_LEFT); cell.Colspan = 1; table.AddCell(cell); cell = PhraseCell(new Phrase(strDesignation + "\n", FontFactory.GetFont("Times New Roman", 10, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_LEFT); cell.Colspan = 3; table.AddCell(cell); cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_LEFT); cell.Colspan = 1; table.AddCell(cell); cell = PhraseCell(new Phrase(strStreet1 + " " + strStreet2 + "\n", FontFactory.GetFont("Times New Roman", 10, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_LEFT); cell.Colspan = 3; table.AddCell(cell); cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_LEFT); cell.Colspan = 1; table.AddCell(cell); cell = PhraseCell(new Phrase(strCity + "," + strRegion + " " + strPostalCode, FontFactory.GetFont("Times New Roman", 10, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_LEFT); cell.Colspan = 3; table.AddCell(cell); cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_LEFT); cell.Colspan = 1; table.AddCell(cell); cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER); cell.Colspan = 1; table.AddCell(cell); cell = PhraseCell(new Phrase("INVOICE", FontFactory.GetFont("Times New Roman", 14, Font.UNDERLINE, Color.BLACK)), PdfPCell.ALIGN_CENTER); cell.Colspan = 2; cell.PaddingTop = 20f; table.AddCell(cell); cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER); cell.Colspan = 1; cell.PaddingBottom = 40f; table.AddCell(cell); document.Add(table); table = new PdfPTable(6); table.HorizontalAlignment = Element.ALIGN_CENTER; table.LockedWidth = true; table.SetWidths(new float[] { 1f, 1f, 1f, 1f, 1f, 1f }); table.SpacingBefore = 20f; table.TotalWidth = 450f; cell = PhraseCell(new Phrase("DESCRIPTION", FontFactory.GetFont("Times New Roman", 12, Font.BOLD, Color.BLACK)), PdfPCell.ALIGN_CENTER); cell.Colspan = 3; cell.MinimumHeight = 40f; cell.PaddingTop = 10f; cell.BorderColor = new Color(System.Drawing.Color.Black); cell.Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; table.AddCell(cell); cell = PhraseCell(new Phrase("Quantity", FontFactory.GetFont("Times New Roman", 10, Font.BOLD, Color.BLACK)), PdfPCell.ALIGN_CENTER); cell.Colspan = 1; cell.BorderColor = new Color(System.Drawing.Color.Black); cell.Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; table.AddCell(cell); cell = PhraseCell(new Phrase("", FontFactory.GetFont("Times New Roman", 10, Font.BOLD, Color.BLACK)), PdfPCell.ALIGN_CENTER); cell.Colspan = 1; cell.BorderColor = new Color(System.Drawing.Color.Black); cell.Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; table.AddCell(cell); cell = PhraseCell(new Phrase("Amount", FontFactory.GetFont("Times New Roman", 10, Font.BOLD, Color.BLACK)), PdfPCell.ALIGN_CENTER); cell.Colspan = 1; cell.BorderColor = new Color(System.Drawing.Color.Black); cell.Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; table.AddCell(cell); document.Add(table); table = new PdfPTable(6); table.HorizontalAlignment = Element.ALIGN_CENTER; table.LockedWidth = true; table.SetWidths(new float[] { 1f, 1f, 1f, 1f, 1f, 1f }); table.TotalWidth = 450f; cell = PhraseCell(new Phrase(ddlMonths.SelectedItem.Text + " Proctoring " + strOrgName, FontFactory.GetFont("Times New Roman", 8, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_LEFT); cell.Colspan = 3; cell.MinimumHeight = 80f; cell.PaddingTop = 5f; cell.BorderColor = new Color(System.Drawing.Color.Black); cell.Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; table.AddCell(cell); cell = PhraseCell(new Phrase(lblRecords.Text, FontFactory.GetFont("Times New Roman", 8, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_RIGHT); cell.Colspan = 1; cell.MinimumHeight = 80f; cell.BorderColor = new Color(System.Drawing.Color.Black); cell.Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; table.AddCell(cell); cell = PhraseCell(new Phrase("", FontFactory.GetFont("Times New Roman", 8, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_RIGHT); cell.Colspan = 1; cell.MinimumHeight = 80f; cell.BorderColor = new Color(System.Drawing.Color.Black); cell.Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; table.AddCell(cell); cell = PhraseCell(new Phrase(lblTotalFee.Text, FontFactory.GetFont("Times New Roman", 8, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_RIGHT); cell.Colspan = 1; cell.MinimumHeight = 80f; cell.BorderColor = new Color(System.Drawing.Color.Black); cell.Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; table.AddCell(cell); document.Add(table); table = new PdfPTable(6); table.HorizontalAlignment = Element.ALIGN_CENTER; table.LockedWidth = true; table.SetWidths(new float[] { 1f, 1f, 1f, 1f, 1f, 1f }); table.TotalWidth = 450f; cell = PhraseCell(new Phrase(" Please make checks payable to Secure Proctor and remit to 20 Pickering St,\n Needham, MA 02492", FontFactory.GetFont("Times New Roman", 7, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_LEFT); cell.Colspan = 4; cell.MinimumHeight = 40f; cell.PaddingTop = 5f; cell.BorderColor = new Color(System.Drawing.Color.Black); cell.Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; table.AddCell(cell); cell = PhraseCell(new Phrase("TOTAL", FontFactory.GetFont("Times New Roman", 8, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_RIGHT); cell.Colspan = 1; cell.BorderColor = new Color(System.Drawing.Color.Black); cell.Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.PaddingTop = 5f; table.AddCell(cell); cell = PhraseCell(new Phrase(lblTotalFee.Text, FontFactory.GetFont("Times New Roman", 8, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_RIGHT); cell.Colspan = 1; cell.PaddingTop = 5f; cell.BorderColor = new Color(System.Drawing.Color.Black); cell.Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; table.AddCell(cell); document.Add(table); document.Close(); byte[] bytes = memoryStream.ToArray(); memoryStream.Close(); Response.Clear(); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "attachment; filename=Invoice.pdf"); Response.ContentType = "application/pdf"; Response.Buffer = true; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.BinaryWrite(bytes); Response.End(); Response.Close(); } }
public void To_pdf() { Document doc = new Document(PageSize.A4, 10, 10, 10, 10); if (!Directory.Exists(@"C:\PedidosBingBang")) { Directory.CreateDirectory(@"C:\PedidosBingBang"); } if (!Directory.Exists(@"C:\reptemp")) { Directory.CreateDirectory(@"C:\reptemp"); } foreach (string fichero in Directory.GetFiles(@"C:\reptemp", "*.pdf")) { File.Delete(fichero); } string filename = "PEDIDO_" + CrearEtiqueta() + ".pdf"; if (filename.Trim() != "") { PdfWriter.GetInstance(doc, new FileStream(@"C:\reptemp\" + filename, FileMode.Create)); doc.Open(); iTextSharp.text.Image imagenlogo; string dirLOgo = Application.StartupPath + @"\logo big uniformes1.png"; imagenlogo = iTextSharp.text.Image.GetInstance(dirLOgo); //Properties.Resources.logo_big_uniformes;//Dirreccion a la imagen que se hace referencia imagenlogo.SetAbsolutePosition(30, doc.PageSize.Height - 100); //Posicion en el eje cartesiano imagenlogo.ScaleAbsoluteWidth(200); //Ancho de la imagen imagenlogo.ScaleAbsoluteHeight(70); //Altura de la imagen doc.Add(imagenlogo); //Agrega la imagen al documento //////////////////////// TABLA ENCABEZADO////////////////////////////////////////////////////// iTextSharp.text.Font tipoFont = FontFactory.GetFont("arial", 9, 3, BaseColor.BLACK); iTextSharp.text.Font tipoFontCont = FontFactory.GetFont("arial", 9, BaseColor.BLUE); iTextSharp.text.Font coloraviso = FontFactory.GetFont("arial", 12, BaseColor.RED); DateTime fechaHoy = DateTime.Today; float[] widths = new float[] { 2f, 1f, 1f, 2f }; PdfPTable table = new PdfPTable(4); table.TotalWidth = 300f; table.LockedWidth = true; table.HorizontalAlignment = Element.ALIGN_RIGHT; table.SetWidths(widths); var backCell = System.Drawing.Color.LightGray; var backCellDatos = System.Drawing.Color.WhiteSmoke; var colorBorde = System.Drawing.Color.Gray; /////// CELDAS ENCABEZADO PdfPCell fecha = new PdfPCell(new Phrase("FECHA:", tipoFont)); fecha.Border = 0; fecha.HorizontalAlignment = 2; fecha.BackgroundColor = new BaseColor(backCell); fecha.BorderColor = new BaseColor(colorBorde); fecha.BorderWidthBottom = 1f; table.AddCell(fecha); PdfPCell DATOfecha = new PdfPCell(new Phrase(" " + fechaHoy.ToString("dd-MM-yyyy"), tipoFontCont)); DATOfecha.BackgroundColor = new BaseColor(backCellDatos); DATOfecha.Border = 0; DATOfecha.Colspan = 3; DATOfecha.BorderColor = new BaseColor(colorBorde); DATOfecha.BorderWidthBottom = 1f; table.AddCell(DATOfecha); //table.AddCell("Cell 2"); PdfPCell CTE = new PdfPCell(new Phrase("CLIENTE:", tipoFont)); CTE.Border = 0; CTE.HorizontalAlignment = 2; CTE.BackgroundColor = new BaseColor(backCell); //CTE.Colspan = 4; CTE.BorderColor = new BaseColor(colorBorde); CTE.BorderWidthBottom = 1f; table.AddCell(CTE); PdfPCell NomCTE = new PdfPCell(new Phrase(" " + FP.txtNombre.Text, tipoFontCont)); NomCTE.BackgroundColor = new BaseColor(backCellDatos); NomCTE.Border = 0; NomCTE.Colspan = 3; NomCTE.BorderColor = new BaseColor(colorBorde); NomCTE.BorderWidthBottom = 1f; table.AddCell(NomCTE); PdfPCell FACT = new PdfPCell(new Phrase("FACTURA A:", tipoFont)); FACT.Border = 0; FACT.HorizontalAlignment = 2; FACT.BackgroundColor = new BaseColor(backCell); //FACT.Colspan = 4; FACT.BorderColor = new BaseColor(colorBorde); FACT.BorderWidthBottom = 1f; table.AddCell(FACT); PdfPCell Nomfact = new PdfPCell(new Phrase(" " + FP.txtFact.Text, tipoFontCont)); Nomfact.BackgroundColor = new BaseColor(backCellDatos); Nomfact.Border = 0; Nomfact.Colspan = 3; Nomfact.BorderColor = new BaseColor(colorBorde); Nomfact.BorderWidthBottom = 1f; table.AddCell(Nomfact); PdfPCell cOLONIA = new PdfPCell(new Phrase("CALLE, NUMERO Y COLONIA:", tipoFont)); cOLONIA.Border = 0; cOLONIA.HorizontalAlignment = 2; cOLONIA.BackgroundColor = new BaseColor(backCell); //cOLONIA.Colspan = 2; cOLONIA.BorderColor = new BaseColor(colorBorde); cOLONIA.BorderWidthBottom = 1f; table.AddCell(cOLONIA); PdfPCell dATOcolonia = new PdfPCell(new Phrase(" " + FP.txtCalle.Text, tipoFontCont)); dATOcolonia.BackgroundColor = new BaseColor(backCellDatos); dATOcolonia.Border = 0; dATOcolonia.Colspan = 3; dATOcolonia.BorderColor = new BaseColor(colorBorde); dATOcolonia.BorderWidthBottom = 1f; table.AddCell(dATOcolonia); PdfPCell CP = new PdfPCell(new Phrase("CP:", tipoFont)); CP.Border = 0; CP.HorizontalAlignment = 2; CP.BackgroundColor = new BaseColor(backCell); CP.BorderColor = new BaseColor(colorBorde); CP.BorderWidthBottom = 1f; table.AddCell(CP); PdfPCell DATOCP = new PdfPCell(new Phrase(" " + FP.txtCP.Text, tipoFontCont)); DATOCP.BackgroundColor = new BaseColor(backCellDatos); DATOCP.Border = 0; DATOCP.Colspan = 3; DATOCP.BorderColor = new BaseColor(colorBorde); DATOCP.BorderWidthBottom = 1f; table.AddCell(DATOCP); PdfPCell MPIO = new PdfPCell(new Phrase("MUNICIPIO:", tipoFont)); MPIO.Border = 0; MPIO.HorizontalAlignment = 2; MPIO.BackgroundColor = new BaseColor(backCell); MPIO.BorderColor = new BaseColor(colorBorde); MPIO.BorderWidthBottom = 1f; table.AddCell(MPIO); PdfPCell DATOMPIO = new PdfPCell(new Phrase(" " + FP.txtMuni.Text, tipoFontCont)); DATOMPIO.BackgroundColor = new BaseColor(backCellDatos); DATOMPIO.Border = 0; DATOMPIO.Colspan = 3; DATOMPIO.BorderColor = new BaseColor(colorBorde); DATOMPIO.BorderWidthBottom = 1f; table.AddCell(DATOMPIO); PdfPCell CD = new PdfPCell(new Phrase("CUIDAD:", tipoFont)); CD.Border = 0; CD.HorizontalAlignment = 2; CD.BackgroundColor = new BaseColor(backCell); CD.BorderColor = new BaseColor(colorBorde); CD.BorderWidthBottom = 1f; table.AddCell(CD); PdfPCell DATOCD = new PdfPCell(new Phrase(" " + FP.txtCiud.Text, tipoFontCont)); DATOCD.BackgroundColor = new BaseColor(backCellDatos); DATOCD.Border = 0; DATOCD.Colspan = 3; DATOCD.BorderColor = new BaseColor(colorBorde); DATOCD.BorderWidthBottom = 1f; table.AddCell(DATOCD); PdfPCell EDO = new PdfPCell(new Phrase("ESTADO:", tipoFont)); EDO.Border = 0; EDO.HorizontalAlignment = 2; EDO.BackgroundColor = new BaseColor(backCell); EDO.BorderColor = new BaseColor(colorBorde); EDO.BorderWidthBottom = 1f; table.AddCell(EDO); PdfPCell DATOEDO = new PdfPCell(new Phrase(" " + FP.txtEdo.Text, tipoFontCont)); DATOEDO.BackgroundColor = new BaseColor(backCellDatos); DATOEDO.Border = 0; DATOEDO.Colspan = 3; DATOEDO.BorderColor = new BaseColor(colorBorde); DATOEDO.BorderWidthBottom = 1f; table.AddCell(DATOEDO); PdfPCell TRASP = new PdfPCell(new Phrase("TRASPORTE:", tipoFont)); TRASP.Border = 0; TRASP.HorizontalAlignment = 2; TRASP.BackgroundColor = new BaseColor(backCell); TRASP.BorderColor = new BaseColor(colorBorde); TRASP.BorderWidthBottom = 1f; table.AddCell(TRASP); PdfPCell DATOTRASP = new PdfPCell(new Phrase(" " + FP.txtTrasp.Text, tipoFontCont)); DATOTRASP.BackgroundColor = new BaseColor(backCellDatos); DATOTRASP.Border = 0; DATOTRASP.Colspan = 3; DATOTRASP.BorderColor = new BaseColor(colorBorde); DATOTRASP.BorderWidthBottom = 1f; table.AddCell(DATOTRASP); PdfPCell USO = new PdfPCell(new Phrase("USO CFDI:", tipoFont)); USO.Border = 0; USO.HorizontalAlignment = 2; USO.BackgroundColor = new BaseColor(backCell); USO.BorderColor = new BaseColor(colorBorde); USO.BorderWidthBottom = 1f; table.AddCell(USO); PdfPCell DATOUSO = new PdfPCell(new Phrase(" " + FP.cmbUso.Text, tipoFontCont)); DATOUSO.BackgroundColor = new BaseColor(backCellDatos); DATOUSO.Border = 0; DATOUSO.Colspan = 3; DATOUSO.BorderColor = new BaseColor(colorBorde); DATOUSO.BorderWidthBottom = 1f; table.AddCell(DATOUSO); doc.Add(table); ////////////////////////////////////////////////////////7 iTextSharp.text.Font ARIAL = FontFactory.GetFont("ARIAL", 10, 3); ARIAL.Color = new iTextSharp.text.BaseColor(255, 0, 0); // Chunk begin = new Chunk("IMPORTANTE", ARIAL); Chunk chunk = new Chunk("IMPORTANTE", ARIAL); doc.Add(new Paragraph(chunk)); doc.Add(new Paragraph("Una vez realizado el pedido y además siendo verificado y aceptado por el cliente, se les informa que no se aceptan devoluciones.")); doc.Add(new Paragraph(" ")); GenerarDocumento(doc); doc.Close(); if (!this.guardar) { //FRMvisor visor = new FRMvisor(Application.StartupPath + @"\repPDF\" + filename); //visor.cargarPDF(); //visor.ShowDialog(); Process.Start(@"C:\reptemp\" + filename);//Esta parte se puede omitir, si solo se desea guardar el archivo, y que este no se ejecute al instante } else { File.Copy(@"C:\reptemp\" + filename, @"C:\PedidosBingBang\" + filename, true); rutaPDF = @"C:\PedidosBingBang\" + filename; } } }
public void gerarReciboCompraProduto(Pedido pedCompra, Venda venda) { var usuario_compra = _usuarioService.GetUsuarioById(pedCompra.UserId); var usuario_venda = _usuarioService.GetUsuarioById(venda.UserIdVenda); Document doc = new Document(PageSize.A4); doc.SetMargins(40, 40, 40, 80); doc.AddCreationDate(); string caminho = AppDomain.CurrentDomain.BaseDirectory + "ReciboCompra.pdf"; PdfWriter.GetInstance(doc, new FileStream(caminho, FileMode.Create)); doc.Open(); //Título Paragraph quebraLinha = new Paragraph("\n", _fonte); Paragraph titulo = new Paragraph("Recibo de Compra\n\n", _fonteTitulo); titulo.Alignment = Element.ALIGN_CENTER; doc.Add(titulo); //Dados Pedido PdfPTable tab_pedido = new PdfPTable(3); //Cabeçalho var cel_dt_pedido = new PdfPCell(); var cel_dt_recibo = new PdfPCell(); var cel_num_pedido = new PdfPCell(); cel_dt_pedido.AddElement(new Paragraph("DATA PEDIDO", _fonte)); cel_dt_recibo.AddElement(new Paragraph("DATA RECIBO", _fonte)); cel_num_pedido.AddElement(new Paragraph("NÚMERO PEDIDO", _fonte)); tab_pedido.AddCell(cel_dt_pedido); tab_pedido.AddCell(cel_dt_recibo); tab_pedido.AddCell(cel_num_pedido); //Dados double num = pedCompra.NumPedido; tab_pedido.AddCell(new PdfPCell(new Phrase(pedCompra.DataPedidoRealizado.ToString()))); tab_pedido.AddCell(new PdfPCell(new Phrase(pedCompra.DataPagamentoConfirmado.ToString()))); tab_pedido.AddCell(new PdfPCell(new Phrase(num.ToString()))); //Cabeçalho var cel_vl_produto = new PdfPCell(); var cel_vl_frete = new PdfPCell(); var cel_vl_total = new PdfPCell(); cel_vl_produto.AddElement(new Paragraph("VALOR COMPRA", _fonte)); cel_vl_frete.AddElement(new Paragraph("VALOR FRETE", _fonte)); cel_vl_total.AddElement(new Paragraph("VALOR FINAL", _fonte)); tab_pedido.AddCell(cel_vl_produto); tab_pedido.AddCell(cel_vl_frete); tab_pedido.AddCell(cel_vl_total); //Dados tab_pedido.AddCell(new PdfPCell(new Phrase(venda.VlTotalCompra.ToString("0.00")))); tab_pedido.AddCell(new PdfPCell(new Phrase(venda.VlFreteCompra.ToString("0.00")))); tab_pedido.AddCell(new PdfPCell(new Phrase(venda.VlFinalCompra.ToString("0.00")))); doc.Add(tab_pedido); doc.Add(quebraLinha); //--------------------------------------------------------------------------------- //Dados Comprador PdfPTable tab_comprador = new PdfPTable(2); //Cabeçalho var cel_nome_comprador = new PdfPCell(); var cel_cpf_comprador = new PdfPCell(); cel_nome_comprador.AddElement(new Paragraph("NOME COMPRADOR", _fonte)); cel_cpf_comprador.AddElement(new Paragraph("CPF COMPRADOR", _fonte)); tab_comprador.AddCell(cel_nome_comprador); tab_comprador.AddCell(cel_cpf_comprador); //Dados tab_comprador.AddCell(new PdfPCell(new Phrase(usuario_compra.Name))); tab_comprador.AddCell(new PdfPCell(new Phrase(usuario_compra.Cpf.ToString()))); doc.Add(tab_comprador); doc.Add(quebraLinha); //--------------------------------------------------------------------------------- //Dados Vendedor PdfPTable tab_vendedor = new PdfPTable(2); //Cabeçalho var cel_nome_vendedor = new PdfPCell(); var cel_cpf_vendedor = new PdfPCell(); cel_nome_vendedor.AddElement(new Paragraph("NOME VENDEDOR", _fonte)); cel_cpf_vendedor.AddElement(new Paragraph("CPF VENDEDOR", _fonte)); tab_vendedor.AddCell(cel_nome_vendedor); tab_vendedor.AddCell(cel_cpf_vendedor); //Dados tab_vendedor.AddCell(new PdfPCell(new Phrase(usuario_venda.Name))); tab_vendedor.AddCell(new PdfPCell(new Phrase(usuario_venda.Cpf.ToString()))); doc.Add(tab_vendedor); doc.Add(quebraLinha); //--------------------------------------------------------------------------------- //Dados Endereço PdfPTable tab_endereco = new PdfPTable(4); //Cabeçalho var cel_cidade = new PdfPCell(); var cel_estado = new PdfPCell(); var cel_cep = new PdfPCell(); var cel_bairro = new PdfPCell(); cel_cidade.AddElement(new Paragraph("CIDADE", _fonte)); cel_estado.AddElement(new Paragraph("ESTADO", _fonte)); cel_cep.AddElement(new Paragraph("CEP", _fonte)); cel_bairro.AddElement(new Paragraph("BAIRRO", _fonte)); tab_endereco.AddCell(cel_cidade); tab_endereco.AddCell(cel_estado); tab_endereco.AddCell(cel_cep); tab_endereco.AddCell(cel_bairro); //Dados tab_endereco.AddCell(new PdfPCell(new Phrase(pedCompra.Cidade))); tab_endereco.AddCell(new PdfPCell(new Phrase(pedCompra.Uf))); tab_endereco.AddCell(new PdfPCell(new Phrase(pedCompra.Cep))); tab_endereco.AddCell(new PdfPCell(new Phrase(pedCompra.Bairro))); //----- //Cabeçalho var cel_rua = new PdfPCell(); var cel_numero = new PdfPCell(); var cel_complemento = new PdfPCell(); cel_rua.AddElement(new Paragraph("RUA", _fonte)); cel_numero.AddElement(new Paragraph("NÚMERO", _fonte)); cel_complemento.AddElement(new Paragraph("COMPLEMENTO", _fonte)); tab_endereco.AddCell(cel_rua); tab_endereco.AddCell(cel_numero); tab_endereco.AddCell(cel_complemento); tab_endereco.AddCell(new PdfPCell(new Phrase(" "))); //Dados tab_endereco.AddCell(new PdfPCell(new Phrase(pedCompra.Rua))); tab_endereco.AddCell(new PdfPCell(new Phrase(pedCompra.Numero.ToString()))); tab_endereco.AddCell(new PdfPCell(new Phrase(pedCompra.Complemento))); tab_endereco.AddCell(new PdfPCell(new Phrase(" "))); doc.Add(tab_endereco); doc.Add(quebraLinha); //--------------------------------------------------------------------------------- //Produtos PdfPTable tab_produtos = new PdfPTable(5); var cel_produto = new PdfPCell(); var cel_qtd = new PdfPCell(); var cel_preco = new PdfPCell(); var cel_frete = new PdfPCell(); var cel_vl_final = new PdfPCell(); cel_produto.AddElement(new Paragraph("PRODUTO", _fonte)); cel_qtd.AddElement(new Paragraph("QTD", _fonte)); cel_preco.AddElement(new Paragraph("PREÇO", _fonte)); cel_frete.AddElement(new Paragraph("FRETE", _fonte)); cel_vl_final.AddElement(new Paragraph("VALOR", _fonte)); tab_produtos.AddCell(cel_produto); tab_produtos.AddCell(cel_qtd); tab_produtos.AddCell(cel_preco); tab_produtos.AddCell(cel_frete); tab_produtos.AddCell(cel_vl_final); tab_produtos.AddCell(new PdfPCell(new Phrase(venda.NomeProduto))); double t = venda.Quandidade; tab_produtos.AddCell(new PdfPCell(new Phrase(t.ToString()))); tab_produtos.AddCell(new PdfPCell(new Phrase(venda.VlTotalCompra.ToString("0.00")))); tab_produtos.AddCell(new PdfPCell(new Phrase(venda.VlFreteCompra.ToString("0.00")))); tab_produtos.AddCell(new PdfPCell(new Phrase((venda.VlFinalCompra).ToString("0.00")))); for (int i = 0; i < 8; i++) { tab_produtos.AddCell(new PdfPCell(new Phrase(" "))); } tab_produtos.AddCell(new PdfPCell(new Phrase("VALOR FINAL:"))); tab_produtos.AddCell(new PdfPCell(new Phrase(venda.VlTotalCompra.ToString("0.00")))); doc.Add(tab_produtos); doc.Add(quebraLinha); //--------------------------------------------------------------------------------- doc.Close(); }
private void btnIn_Click(object sender, EventArgs e) { if (gunaDataGridView1.Rows.Count > 0) { SaveFileDialog sfd = new SaveFileDialog { Filter = "PDF (*.pdf)|*.pdf", FileName = "Output.pdf" }; bool fileError = false; if (sfd.ShowDialog() == DialogResult.OK) { if (File.Exists(sfd.FileName)) { try { File.Delete(sfd.FileName); } catch (IOException ex) { fileError = true; frm.capNhatLoiNhan("Đang có chương trình mở file này!!!"); frm.ShowDialog(); } } if (!fileError) { try { PdfPTable pdfTable = new PdfPTable(gunaDataGridView1.Columns.Count); pdfTable.DefaultCell.Padding = 3; pdfTable.WidthPercentage = 100; pdfTable.HorizontalAlignment = Element.ALIGN_LEFT; BaseFont bf = BaseFont.CreateFont(@"C:\WINDOWS\Fonts\TIMES.TTF", BaseFont.IDENTITY_H, true); iTextSharp.text.Font fonttitle = new iTextSharp.text.Font(bf, 15); iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 10); iTextSharp.text.Font fonttext = new iTextSharp.text.Font(bf, 12); Paragraph header = new Paragraph { Alignment = Element.ALIGN_CENTER }; Paragraph text = new Paragraph(); Chunk c1 = new Chunk("BÁO CÁO THỐNG KÊ TRÌNH ĐỘ NGOẠI NGỮ \n", fonttitle); Chunk c2 = new Chunk(DateTime.Now.ToShortDateString() + "\n\n", font); header.Add(c1); header.Add(c2); foreach (DataGridViewColumn column in gunaDataGridView1.Columns) { PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText, fonttext)); pdfTable.AddCell(cell); } foreach (DataGridViewRow row in gunaDataGridView1.Rows) { foreach (DataGridViewCell cell in row.Cells) { PdfPCell cell1 = new PdfPCell(new Phrase(cell.Value.ToString(), fonttext)); pdfTable.AddCell(cell1); } } using (FileStream stream = new FileStream(sfd.FileName, FileMode.Create)) { Document pdfDoc = new Document(PageSize.A4, 10f, 20f, 20f, 10f); PdfWriter.GetInstance(pdfDoc, stream); pdfDoc.Open(); pdfDoc.Add(header); pdfDoc.Add(pdfTable); pdfDoc.Close(); stream.Close(); } frm.capNhatLoiNhan("Xuất dữ liệu thành công!!!"); frm.ShowDialog(); } catch (Exception ex) { frm.capNhatLoiNhan("Có lỗi xảy ra!!!"); frm.ShowDialog(); } } } } else { frm.capNhatLoiNhan("Không có bản ghi nào được xuất!!!"); frm.ShowDialog(); } }
}//Скрывает интерфейс разных методов прогноза private void PdfToolStripMenuItem_Click(object sender, EventArgs e) { //Объект документа пдф iTextSharp.text.Document doc = new iTextSharp.text.Document(); doc.SetPageSize(PageSize.A4.Rotate()); try { //Создаем объект записи пдф-документа в файл PdfWriter.GetInstance(doc, new FileStream("pdfTables.pdf", FileMode.Create)); } catch (IOException) { MessageBox.Show("Пожалуйста, для сохранения файла, закройте файл pdf и нажмите ОК"); try { PdfWriter.GetInstance(doc, new FileStream("pdfTables.pdf", FileMode.Create)); } catch (Exception) { MessageBox.Show("Не удалост вывести в pdf файл!"); return; } } //Открываем документ doc.Open(); //Определение шрифта необходимо для сохранения кириллического текста //Иначе мы не увидим кириллический текст //Если мы работаем только с англоязычными текстами, то шрифт можно не указывать string FONT_LOCATION = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "arial.TTF"); //определяем В СИСТЕМЕ(чтобы не копировать файл) расположение шрифта arial.ttf BaseFont baseFont = BaseFont.CreateFont(FONT_LOCATION, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); //создаем шрифт iTextSharp.text.Font fontParagraph = new iTextSharp.text.Font(baseFont, 10, iTextSharp.text.Font.NORMAL); //регистрируем + можно задать параметры для него(17 - размер, последний параметр - стиль) //Создаем объект таблицы и передаем в нее число столбцов таблицы из нашего датасета PdfPTable table = new PdfPTable(dataGridView1.ColumnCount); //MyDataSet.Tables[i].Columns.Count); //Добавим в таблицу общий заголовок PdfPCell cell = new PdfPCell(new Phrase("")); //cell.Colspan = dataGridView1.ColumnCount; //cell.HorizontalAlignment = 1; ////Убираем границу первой ячейки, чтобы был как заголовок //cell.Border = 0; //table.AddCell(cell); //Сначала добавляем заголовки таблицы for (int j = 0; j < dataGridView1.ColumnCount; j++) { cell = new PdfPCell(new Phrase(new Phrase(dataGridView1.Columns[j].HeaderText, fontParagraph))); //Фоновый цвет (необязательно, просто сделаем по красивее) cell.BackgroundColor = iTextSharp.text.BaseColor.LIGHT_GRAY; table.AddCell(cell); } //Добавляем все остальные ячейки for (int j = 0; j < dataGridView1.RowCount - 1; j++) { for (int k = 0; k < dataGridView1.ColumnCount; k++) { if (dataGridView1.Rows[j].Cells[k].Value != null) { table.AddCell(new Phrase(Math.Round(Convert.ToDouble(dataGridView1.Rows[j].Cells[k].Value), 2).ToString(), fontParagraph)); } else { table.AddCell(new Phrase(" ", fontParagraph)); } } } //if (ComboBoxMethod.SelectedIndex != 1 && textBoxErrorIndic.Text != "") //fileCSV += "Среднеквадратическая ошибка расчёта ;" + textBoxErrorIndic.Text + ";"; //table.AddCell(new Phrase(Math.Round(Convert.ToDouble(textBoxErrorIndic.Text), 2).ToString(), fontParagraph)); // table.AddCell(new Phrase("123", fontParagraph)); /**/ chart1.SaveImage(Application.StartupPath + @"\1.bmp", System.Drawing.Imaging.ImageFormat.Bmp); iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(Application.StartupPath + @"/1.bmp"); jpg.Alignment = iTextSharp.text.Image.ALIGN_CENTER; //Добавляем таблицу в документ doc.Add(table); if (ComboBoxMethod.SelectedIndex != 1 && textBoxErrorIndic.Text != "") { doc.Add(new Phrase("\n Среднеквадратическая ошибка прогноза: " + Math.Round(Convert.ToDouble(textBoxErrorIndic.Text), 3).ToString(), fontParagraph)); } if (ComboBoxMethod.SelectedIndex == 2 && textBoxErrorForecast.Text != "") { doc.Add(new Phrase("\n Ошибка прогноза: " + Math.Round(Convert.ToDouble(textBoxErrorForecast.Text), 3).ToString(), fontParagraph)); } doc.NewPage(); jpg.ScalePercent(80); doc.Add(jpg); //Закрываем документ doc.Close(); Process.Start("pdfTables.pdf"); }
public ActionResult GetPdf(Guid id) { var variant = db.Variants.Find(id); if (variant == null) { return(HttpNotFound()); } if (variant.ResultData == null) { return(HttpNotFound()); } var fileName = variant.Name + ".pdf"; iTextSharp.text.Font supFont = new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 6); Chunk o = new Chunk("o", supFont); o.SetTextRise(7); Chunk two = new Chunk("2", supFont); two.SetTextRise(7); BaseFont bf = BaseFont.CreateFont(Server.MapPath("~/Content/FreeSans.ttf"), "Cp1251", BaseFont.EMBEDDED); iTextSharp.text.Font russian12 = new iTextSharp.text.Font(bf, 12); iTextSharp.text.Font russian14 = new iTextSharp.text.Font(bf, 14); iTextSharp.text.Font russian16 = new iTextSharp.text.Font(bf, 16); var doc = new Document(); MemoryStream stream = new MemoryStream(); PdfWriter.GetInstance(doc, stream); doc.Open(); var header = new Paragraph(new Phrase(variant.Name, russian16)); header.Alignment = Element.ALIGN_CENTER; header.SpacingAfter = 20; doc.Add(header); var paragraph = new Paragraph(new Phrase("Исходные данные:", russian14)); paragraph.Alignment = Element.ALIGN_CENTER; doc.Add(paragraph); PdfPTable table = GetTable(); PdfPCell cell = GetCell("Характеристики заготовок", russian12); cell.BackgroundColor = new BaseColor(Color.LightBlue); cell.Padding = 5; cell.Colspan = 2; table.AddCell(cell); table.AddCell(GetCell("Высота заготовки", russian12)); table.AddCell(GetCell(variant.InputData.BarHeight.ToString() + " м", russian12)); table.AddCell(GetCell("Толщина заготовки", russian12)); table.AddCell(GetCell(variant.InputData.BarThickness.ToString() + " м", russian12)); table.AddCell(GetCell("Длина заготовки", russian12)); table.AddCell(GetCell(variant.InputData.BarLength.ToString() + " м", russian12)); table.AddCell(GetCell("Число рядов", russian12)); table.AddCell(GetCell(variant.InputData.BarNumber.ToString(), russian12)); table.AddCell(GetCell("Начальная температура", russian12)); Phrase phrase = new Phrase(variant.InputData.StartSteelTemperature.ToString() + " ", russian12); phrase.Add(o); phrase.Add("C"); table.AddCell(GetCell(phrase)); table.AddCell(GetCell("Конечная температура верхней поверхности", russian12)); phrase = new Phrase(variant.InputData.EndTopSteelTemperature.ToString() + " ", russian12); phrase.Add(o); phrase.Add("C"); table.AddCell(GetCell(phrase)); table.AddCell(GetCell("Конечная температура нижней поверхности", russian12)); phrase = new Phrase(variant.InputData.EndBottomSteelTemperature.ToString() + " ", russian12); phrase.Add(o); phrase.Add("C"); table.AddCell(GetCell(phrase)); table.AddCell(GetCell("Температура поверхности в сечении 1", russian12)); phrase = new Phrase(variant.InputData.TopSteelTemperatureSector1.ToString() + " ", russian12); phrase.Add(o); phrase.Add("C"); table.AddCell(GetCell(phrase)); table.AddCell(GetCell("Тип стали", russian12)); table.AddCell(GetCell(EnumHelper <SteelTypeForDensity> .GetDisplayValue(variant.InputData.SteelTypeForDensity), russian12)); table.AddCell(GetCell("Тип стали по содержанию элементов", russian12)); table.AddCell(GetCell(EnumHelper <SteelTypeProperty> .GetDisplayValue(variant.InputData.SteelTypeProperty), russian12)); doc.Add(table); table = GetTable(); cell = GetCell("Характеристики печи", russian12); cell.BackgroundColor = new BaseColor(Color.LightBlue); cell.Padding = 5; cell.Colspan = 2; table.AddCell(cell); table.AddCell(GetCell("Высота рабочего пространства в зоне 1", russian12)); table.AddCell(GetCell(variant.InputData.FurnanceHeightZone1.ToString() + " м", russian12)); table.AddCell(GetCell("Высота рабочей поверхности в сечении 0", russian12)); table.AddCell(GetCell(variant.InputData.WorkHeightSector0.ToString() + " м", russian12)); table.AddCell(GetCell("Высота рабочей поверхности в сечении 1", russian12)); table.AddCell(GetCell(variant.InputData.WorkHeightSector1.ToString() + " м", russian12)); table.AddCell(GetCell("Высота рабочей поверхности в сечении 2", russian12)); table.AddCell(GetCell(variant.InputData.WorkHeightSector2.ToString() + " м", russian12)); table.AddCell(GetCell("Ширина печи", russian12)); table.AddCell(GetCell(variant.InputData.FurnanceWidth.ToString() + " м", russian12)); table.AddCell(GetCell("Производительность печи", russian12)); table.AddCell(GetCell(variant.InputData.FurnanceProductivity.ToString() + " тонн/ч", russian12)); table.AddCell(GetCell("Тип горелок", russian12)); table.AddCell(GetCell(EnumHelper <TorchType> .GetDisplayValue((variant.InputData.TorchType)), russian12)); doc.Add(table); table = GetTable(); cell = GetCell("Характеристики среды", russian12); cell.BackgroundColor = new BaseColor(Color.LightBlue); cell.Padding = 5; cell.Colspan = 2; table.AddCell(cell); table.AddCell(GetCell("Температура воздуха в рекуператоре", russian12)); phrase = new Phrase(variant.InputData.AirTemperature.ToString() + " ", russian12); phrase.Add(o); phrase.Add("C"); table.AddCell(GetCell(phrase)); table.AddCell(GetCell("Температура газов в сечении 0", russian12)); phrase = new Phrase(variant.InputData.GasTemperatureSector0.ToString() + " ", russian12); phrase.Add(o); phrase.Add("C"); table.AddCell(GetCell(phrase)); table.AddCell(GetCell("Температура газов в сечении 1", russian12)); phrase = new Phrase(variant.InputData.GasTemperatureSector1.ToString() + " ", russian12); phrase.Add(o); phrase.Add("C"); table.AddCell(GetCell(phrase)); table.AddCell(GetCell("Температура газов в сечении 2", russian12)); phrase = new Phrase(variant.InputData.GasTemperatureSector2.ToString() + " ", russian12); phrase.Add(o); phrase.Add("C"); table.AddCell(GetCell(phrase)); doc.Add(table); table = GetTable(); cell = GetCell("Характеристики топлива", russian12); cell.BackgroundColor = new BaseColor(Color.LightBlue); cell.Padding = 5; cell.Colspan = 2; table.AddCell(cell); table.AddCell(GetCell("Теплота сгорания всей смеси", russian12)); phrase = new Phrase(variant.InputData.HeatFull.ToString() + " Вт/м", russian12); phrase.Add(two); table.AddCell(GetCell(phrase)); table.AddCell(GetCell("Теплота сгорания природного газа", russian12)); phrase = new Phrase(variant.InputData.HeatNatural.ToString() + " Вт/м", russian12); phrase.Add(two); table.AddCell(GetCell(phrase)); table.AddCell(GetCell("Теплота сгорания доменного газа", russian12)); phrase = new Phrase(variant.InputData.HeatBlast.ToString() + " Вт/м", russian12); phrase.Add(two); table.AddCell(GetCell(phrase)); doc.Add(table); paragraph = new Paragraph(new Phrase("Результаты:", russian14)); paragraph.Alignment = Element.ALIGN_CENTER; doc.Add(paragraph); table = GetTable(); cell = GetCell("Время нагрева заготовок", russian12); cell.BackgroundColor = new BaseColor(Color.LightBlue); cell.Padding = 5; cell.Colspan = 2; table.AddCell(cell); table.AddCell(GetCell("Зона 1", russian12)); table.AddCell(GetCell(variant.ResultData.HeatingTimeZone1.ToString() + " ч", russian12)); table.AddCell(GetCell("Зона 2", russian12)); table.AddCell(GetCell(variant.ResultData.HeatingTimeZone2.ToString() + " ч", russian12)); table.AddCell(GetCell("Зона 3", russian12)); table.AddCell(GetCell(variant.ResultData.HeatingTimeZone3.ToString() + " ч", russian12)); table.AddCell(GetCell("Общее", russian12)); table.AddCell(GetCell(variant.ResultData.HeatingTimeFull.ToString() + " ч", russian12)); doc.Add(table); table = GetTable(); cell = GetCell("Длины зон", russian12); cell.BackgroundColor = new BaseColor(Color.LightBlue); cell.Padding = 5; cell.Colspan = 2; table.AddCell(cell); table.AddCell(GetCell("Зона 1", russian12)); table.AddCell(GetCell(variant.ResultData.LengthZone1.ToString() + " м", russian12)); table.AddCell(GetCell("Зона 2", russian12)); table.AddCell(GetCell(variant.ResultData.LengthZone2.ToString() + " м", russian12)); table.AddCell(GetCell("Зона 3", russian12)); table.AddCell(GetCell(variant.ResultData.LengthZone3.ToString() + " м", russian12)); table.AddCell(GetCell("Общая", russian12)); table.AddCell(GetCell(variant.ResultData.LengthFull.ToString() + " м", russian12)); doc.Add(table); table = GetTable(); cell = GetCell("Горение топлива", russian12); cell.BackgroundColor = new BaseColor(Color.LightBlue); cell.Padding = 5; cell.Colspan = 2; table.AddCell(cell); table.AddCell(GetCell("Температура газовой среды", russian12)); phrase = new Phrase(variant.ResultData.ConsumptionTemperature.ToString() + " ", russian12); phrase.Add(o); phrase.Add("C"); table.AddCell(GetCell(phrase)); doc.Add(table); table = GetTable(); cell = GetCell("Средний тепловой поток", russian12); cell.BackgroundColor = new BaseColor(Color.LightBlue); cell.Padding = 5; cell.Colspan = 2; table.AddCell(cell); table.AddCell(GetCell("В зоне 1", russian12)); phrase = new Phrase(variant.ResultData.AverageHeatFlowZone1.ToString() + " Вт/м", russian12); phrase.Add(two); table.AddCell(GetCell(phrase)); table.AddCell(GetCell("В зоне 2", russian12)); phrase = new Phrase(variant.ResultData.AverageHeatFlowZone2.ToString() + " Вт/м", russian12); phrase.Add(two); table.AddCell(GetCell(phrase)); doc.Add(table); table = GetTable(); cell = GetCell("Температура массы слитка", russian12); cell.BackgroundColor = new BaseColor(Color.LightBlue); cell.Padding = 5; cell.Colspan = 2; table.AddCell(cell); table.AddCell(GetCell("В сечении 1", russian12)); phrase = new Phrase(variant.ResultData.BarTemperatureSection1.ToString() + " ", russian12); phrase.Add(o); phrase.Add("C"); table.AddCell(GetCell(phrase)); table.AddCell(GetCell("В сечении 2", russian12)); phrase = new Phrase(variant.ResultData.BarTemperatureSection2.ToString() + " ", russian12); phrase.Add(o); phrase.Add("C"); table.AddCell(GetCell(phrase)); table.AddCell(GetCell("В сечении 3", russian12)); phrase = new Phrase(variant.ResultData.BarTemperatureSection3.ToString() + " ", russian12); phrase.Add(o); phrase.Add("C"); table.AddCell(GetCell(phrase)); doc.Add(table); table = GetTable(); cell = GetCell("Удельный тепловой поток", russian12); cell.BackgroundColor = new BaseColor(Color.LightBlue); cell.Padding = 5; cell.Colspan = 2; table.AddCell(cell); table.AddCell(GetCell("В сечении 0", russian12)); phrase = new Phrase(variant.ResultData.SummaryHeatFlowSector0.ToString() + " Вт/м", russian12); phrase.Add(two); table.AddCell(GetCell(phrase)); table.AddCell(GetCell("В сечении 1 для зоны 1", russian12)); phrase = new Phrase(variant.ResultData.SummaryHeatFlowSector1Zone1.ToString() + " Вт/м", russian12); phrase.Add(two); table.AddCell(GetCell(phrase)); table.AddCell(GetCell("В сечении 1 для зоны 2", russian12)); phrase = new Phrase(variant.ResultData.SummaryHeatFlowSector1Zone2.ToString() + " Вт/м", russian12); phrase.Add(two); table.AddCell(GetCell(phrase)); table.AddCell(GetCell("В сечении 2", russian12)); phrase = new Phrase(variant.ResultData.SummaryHeatFlowSector2.ToString() + " Вт/м", russian12); phrase.Add(two); table.AddCell(GetCell(phrase)); doc.Add(table); var user = db.Users.Find(User.Identity.GetUserId()); paragraph = new Paragraph(new Phrase("Выполнил:", russian14)); paragraph.SpacingBefore = 20; doc.Add(paragraph); paragraph = new Paragraph(new Phrase(user.Position, russian12)); doc.Add(paragraph); paragraph = new Paragraph(new Phrase(user.FIO, russian12)); doc.Add(paragraph); paragraph = new Paragraph(new Phrase("Подпись: ________" + " " + DateTime.Now.ToString("dd.MM.yyyyг."), russian12)); paragraph.SpacingBefore = 20; doc.Add(paragraph); doc.Close(); Response.AppendHeader("Content-Disposition", "inline; filename=" + fileName); return(File(stream.ToArray(), "application/pdf")); }
public void GenerarDocumentos(Document document) { //se crea un objeto PdfTable con el numero de columnas del dataGridView PdfPTable datatable = new PdfPTable(grdDatos.ColumnCount); //asignamos algunas propiedades para el diseño del pdf datatable.DefaultCell.Padding = 1; float[] headerwidths = GetTamañoColumnas(grdDatos); datatable.SetWidths(headerwidths); datatable.WidthPercentage = 100; datatable.DefaultCell.BorderWidth = 1; //DEFINIMOS EL COLOR DE LAS CELDAS EN EL PDF datatable.DefaultCell.BackgroundColor = iTextSharp.text.BaseColor.WHITE; //DEFINIMOS EL COLOR DE LOS BORDES datatable.DefaultCell.BorderColor = iTextSharp.text.BaseColor.LIGHT_GRAY; //LA FUENTE DE NUESTRO TEXTO iTextSharp.text.Font fuente = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.COURIER, 8); Phrase objP = new Phrase("A", fuente); datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; //SE GENERA EL ENCABEZADO DE LA TABLA EN EL PDF for (int i = 0; i < grdDatos.ColumnCount; i++) { objP = new Phrase(grdDatos.Columns[i].HeaderText, fuente); datatable.HorizontalAlignment = Element.ALIGN_CENTER; PdfPCell cel = new PdfPCell(); cel.AddElement(objP); cel.Padding = 3; cel.BackgroundColor = iTextSharp.text.BaseColor.LIGHT_GRAY; datatable.AddCell(cel); } datatable.HeaderRows = 2; datatable.DefaultCell.BorderWidth = 1; //SE GENERA EL CUERPO DEL PDF for (int i = 0; i < grdDatos.RowCount; i++) { for (int j = 0; j < grdDatos.ColumnCount; j++) { if (grdDatos[j, i].Value != null) { objP = new Phrase(grdDatos[j, i].Value.ToString(), fuente); objP.Font.Color = iTextSharp.text.BaseColor.BLACK; if (j == 8) { double val = Convert.ToDouble(grdDatos[j, i].Value); if (val > 0) { objP.Font.Color = iTextSharp.text.BaseColor.RED; } } PdfPCell cel = new PdfPCell(); cel.Padding = 3; cel.AddElement(objP); datatable.AddCell(cel); } } datatable.CompleteRow(); } document.Add(datatable); }
public void Run(Stream stream, CMSDataContext db, IEnumerable <ContributorInfo> q, StatementSpecification cs, int set = 0) { pageEvents.set = set; pageEvents.PeopleId = 0; IEnumerable <ContributorInfo> contributors = q; var toDate = ToDate.Date.AddHours(24).AddSeconds(-1); PdfContentByte dc; var font = FontFactory.GetFont(FontFactory.HELVETICA, 11); var boldfont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 11); var doc = new Document(PageSize.LETTER); doc.SetMargins(36f, 30f, 24f, 36f); var w = PdfWriter.GetInstance(doc, stream); w.PageEvent = pageEvents; doc.Open(); dc = w.DirectContent; var prevfid = 0; var runningtotals = db.ContributionsRuns.OrderByDescending(mm => mm.Id).First(); runningtotals.Processed = 0; db.SubmitChanges(); var count = 0; foreach (var ci in contributors) { if (set > 0 && pageEvents.FamilySet[ci.PeopleId] != set) { continue; } var contributions = APIContribution.Contributions(db, ci, FromDate, toDate, cs.Funds).ToList(); var pledges = APIContribution.Pledges(db, ci, toDate, cs.Funds).ToList(); var giftsinkind = APIContribution.GiftsInKind(db, ci, FromDate, toDate, cs.Funds).ToList(); var nontaxitems = db.Setting("DisplayNonTaxOnStatement", "false").ToBool() ? APIContribution.NonTaxItems(db, ci, FromDate, toDate, cs.Funds).ToList() : new List <NonTaxContribution>(); if ((contributions.Count + pledges.Count + giftsinkind.Count + nontaxitems.Count) == 0) { runningtotals.Processed += 1; runningtotals.CurrSet = set; db.SubmitChanges(); if (set == 0) { pageEvents.FamilySet[ci.PeopleId] = 0; } continue; } pageEvents.NextPeopleId = ci.PeopleId; doc.NewPage(); if (prevfid != ci.FamilyId) { prevfid = ci.FamilyId; pageEvents.EndPageSet(); pageEvents.PeopleId = ci.PeopleId; } if (set == 0) { pageEvents.FamilySet[ci.PeopleId] = 0; } count++; var css = @" <style> h1 { font-size: 24px; font-weight:normal; margin-bottom:0; } h2 { font-size: 11px; font-weight:normal; margin-top: 0; } p { font-size: 11px; } </style> "; //----Church Name var t1 = new PdfPTable(1); t1.TotalWidth = 72f * 5f; t1.DefaultCell.Border = Rectangle.NO_BORDER; string html1 = db.ContentHtml("StatementHeader", Resource1.ContributionStatementHeader); string html2 = db.ContentHtml("StatementNotice", Resource1.ContributionStatementNotice); var mh = new MyHandler(); using (var sr = new StringReader(css + html1)) XMLWorkerHelper.GetInstance().ParseXHtml(mh, sr); var cell = new PdfPCell(t1.DefaultCell); foreach (var e in mh.elements) { if (e.Chunks.Count > 0) { cell.AddElement(e); } } //cell.FixedHeight = 72f * 1.25f; t1.AddCell(cell); t1.AddCell("\n"); var t1a = new PdfPTable(1); t1a.TotalWidth = 72f * 5f; t1a.DefaultCell.Border = Rectangle.NO_BORDER; var ae = new PdfPTable(1); ae.DefaultCell.Border = Rectangle.NO_BORDER; ae.WidthPercentage = 100; var a = new PdfPTable(1); a.DefaultCell.Indent = 25f; a.DefaultCell.Border = Rectangle.NO_BORDER; a.AddCell(new Phrase(ci.Name, font)); foreach (var line in ci.MailingAddress.SplitLines()) { a.AddCell(new Phrase(line, font)); } cell = new PdfPCell(a) { Border = Rectangle.NO_BORDER }; //cell.FixedHeight = 72f * 1.0625f; ae.AddCell(cell); cell = new PdfPCell(t1a.DefaultCell); cell.AddElement(ae); t1a.AddCell(ae); //-----Notice var t2 = new PdfPTable(1); t2.TotalWidth = 72f * 3f; t2.DefaultCell.Border = Rectangle.NO_BORDER; var envno = ""; if (db.Setting("PrintEnvelopeNumberOnStatement")) { var ev = Person.GetExtraValue(db, ci.PeopleId, "EnvelopeNumber"); var s = Util.PickFirst(ev.Data, ev.IntValue.ToString(), ev.StrValue); if (s.HasValue()) { envno = $" env: {Util.PickFirst(ev.Data, ev.IntValue.ToString(), ev.StrValue)}"; } } t2.AddCell(db.Setting("NoPrintDateOnStatement") ? new Phrase($"\nid:{ci.PeopleId}{envno} {ci.CampusId}", font) : new Phrase($"\nprinted: {DateTime.Now:M/d/yy} id:{ci.PeopleId}{envno} {ci.CampusId}", font)); t2.AddCell(""); var mh2 = new MyHandler(); using (var sr = new StringReader(css + html2)) XMLWorkerHelper.GetInstance().ParseXHtml(mh2, sr); cell = new PdfPCell(t1.DefaultCell); foreach (var e in mh2.elements) { if (e.Chunks.Count > 0) { cell.AddElement(e); } } t2.AddCell(cell); // POSITIONING OF ADDRESSES //----Header var yp = doc.BottomMargin + db.Setting("StatementRetAddrPos", "10.125").ToFloat() * 72f; t1.WriteSelectedRows(0, -1, doc.LeftMargin - 0.1875f * 72f, yp, dc); yp = doc.BottomMargin + db.Setting("StatementAddrPos", "8.3375").ToFloat() * 72f; t1a.WriteSelectedRows(0, -1, doc.LeftMargin, yp, dc); yp = doc.BottomMargin + 10.125f * 72f; t2.WriteSelectedRows(0, -1, doc.LeftMargin + 72f * 4.4f, yp, dc); //----Contributions doc.Add(new Paragraph(" ")); doc.Add(new Paragraph(" ") { SpacingBefore = 72f * 2.125f }); doc.Add(new Phrase($"\n Period: {FromDate:d} - {toDate:d}", boldfont)); var pos = w.GetVerticalPosition(true); var ct = new ColumnText(dc); float gutter = 20f; float colwidth = (doc.Right - doc.Left - gutter) / 2; var t = new PdfPTable(new[] { 10f, 24f, 10f }); t.WidthPercentage = 100; t.DefaultCell.Border = Rectangle.NO_BORDER; t.HeaderRows = 2; cell = new PdfPCell(t.DefaultCell); cell.Colspan = 3; cell.Phrase = new Phrase("Contributions\n", boldfont); t.AddCell(cell); t.DefaultCell.Border = Rectangle.BOTTOM_BORDER; t.AddCell(new Phrase("Date", boldfont)); t.AddCell(new Phrase("Description", boldfont)); cell = new PdfPCell(t.DefaultCell); cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.Phrase = new Phrase("Amount", boldfont); t.AddCell(cell); t.DefaultCell.Border = Rectangle.NO_BORDER; var total = 0m; foreach (var c in contributions) { t.AddCell(new Phrase(c.ContributionDate.ToString2("d"), font)); t.AddCell(new Phrase(c.FundName, font)); cell = new PdfPCell(t.DefaultCell); cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.Phrase = new Phrase(c.ContributionAmount.ToString2("N2"), font); t.AddCell(cell); total += (c.ContributionAmount ?? 0); } t.DefaultCell.Border = Rectangle.TOP_BORDER; cell = new PdfPCell(t.DefaultCell); cell.Colspan = 2; cell.Phrase = new Phrase("Total Contributions for period", boldfont); t.AddCell(cell); cell = new PdfPCell(t.DefaultCell); cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.Phrase = new Phrase(total.ToString("N2"), font); t.AddCell(cell); ct.AddElement(t); //------Pledges if (pledges.Count > 0) { t = new PdfPTable(new float[] { 16f, 12f, 12f }); t.WidthPercentage = 100; t.DefaultCell.Border = Rectangle.NO_BORDER; t.HeaderRows = 2; cell = new PdfPCell(t.DefaultCell); cell.Colspan = 3; cell.Phrase = new Phrase("\n\nPledges\n", boldfont); t.AddCell(cell); t.DefaultCell.Border = Rectangle.BOTTOM_BORDER; t.AddCell(new Phrase("Fund", boldfont)); cell = new PdfPCell(t.DefaultCell); cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.Phrase = new Phrase("Pledge", boldfont); t.AddCell(cell); cell = new PdfPCell(t.DefaultCell); cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.Phrase = new Phrase("Given", boldfont); t.AddCell(cell); t.DefaultCell.Border = Rectangle.NO_BORDER; foreach (var c in pledges) { t.AddCell(new Phrase(c.FundName, font)); cell = new PdfPCell(t.DefaultCell); cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.Phrase = new Phrase(c.Pledged.ToString2("N2"), font); t.AddCell(cell); cell = new PdfPCell(t.DefaultCell); cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.Phrase = new Phrase(c.Given.ToString2("N2"), font); t.AddCell(cell); } ct.AddElement(t); } //------Gifts In Kind if (giftsinkind.Count > 0) { t = new PdfPTable(new float[] { 12f, 18f, 20f }); t.WidthPercentage = 100; t.DefaultCell.Border = Rectangle.NO_BORDER; t.HeaderRows = 2; cell = new PdfPCell(t.DefaultCell); cell.Colspan = 3; cell.Phrase = new Phrase("\n\nGifts in Kind\n", boldfont); t.AddCell(cell); t.DefaultCell.Border = Rectangle.BOTTOM_BORDER; t.AddCell(new Phrase("Date", boldfont)); cell = new PdfPCell(t.DefaultCell); cell.Phrase = new Phrase("Fund", boldfont); t.AddCell(cell); cell = new PdfPCell(t.DefaultCell); cell.Phrase = new Phrase("Description", boldfont); t.AddCell(cell); t.DefaultCell.Border = Rectangle.NO_BORDER; foreach (var c in giftsinkind) { t.AddCell(new Phrase(c.ContributionDate.ToString2("d"), font)); cell = new PdfPCell(t.DefaultCell); cell.Phrase = new Phrase(c.FundName, font); t.AddCell(cell); cell = new PdfPCell(t.DefaultCell); cell.Phrase = new Phrase(c.Description, font); t.AddCell(cell); } ct.AddElement(t); } //-----Summary t = new PdfPTable(new float[] { 29f, 9f }); t.WidthPercentage = 100; t.DefaultCell.Border = Rectangle.NO_BORDER; t.HeaderRows = 2; cell = new PdfPCell(t.DefaultCell); cell.Colspan = 2; cell.Phrase = new Phrase("\n\nPeriod Summary\n", boldfont); t.AddCell(cell); t.DefaultCell.Border = Rectangle.BOTTOM_BORDER; t.AddCell(new Phrase("Fund", boldfont)); cell = new PdfPCell(t.DefaultCell); cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.Phrase = new Phrase("Amount", boldfont); t.AddCell(cell); t.DefaultCell.Border = Rectangle.NO_BORDER; foreach (var c in APIContribution.GiftSummary(db, ci, FromDate, toDate, cs.Funds)) { t.AddCell(new Phrase(c.FundName, font)); cell = new PdfPCell(t.DefaultCell); cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.Phrase = new Phrase(c.Total.ToString2("N2"), font); t.AddCell(cell); } t.DefaultCell.Border = Rectangle.TOP_BORDER; t.AddCell(new Phrase("Total contributions for period", boldfont)); cell = new PdfPCell(t.DefaultCell); cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.Phrase = new Phrase(total.ToString("N2"), font); t.AddCell(cell); ct.AddElement(t); //------NonTax if (nontaxitems.Count > 0) { t = new PdfPTable(new float[] { 10f, 24f, 10f }); t.WidthPercentage = 100; t.DefaultCell.Border = Rectangle.NO_BORDER; t.HeaderRows = 2; cell = new PdfPCell(t.DefaultCell); cell.Colspan = 3; cell.Phrase = new Phrase("\n\nNon Tax-Deductible Items\n", boldfont); t.AddCell(cell); t.DefaultCell.Border = Rectangle.BOTTOM_BORDER; t.AddCell(new Phrase("Date", boldfont)); t.AddCell(new Phrase("Description", boldfont)); cell = new PdfPCell(t.DefaultCell); cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.Phrase = new Phrase("Amount", boldfont); t.AddCell(cell); t.DefaultCell.Border = Rectangle.NO_BORDER; var ntotal = 0m; foreach (var c in nontaxitems) { t.AddCell(new Phrase(c.ContributionDate.ToString2("d"), font)); t.AddCell(new Phrase(c.FundName, font)); cell = new PdfPCell(t.DefaultCell); cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.Phrase = new Phrase(c.ContributionAmount.ToString2("N2"), font); t.AddCell(cell); ntotal += (c.ContributionAmount ?? 0); } t.DefaultCell.Border = Rectangle.TOP_BORDER; cell = new PdfPCell(t.DefaultCell); cell.Colspan = 2; cell.Phrase = new Phrase("Total Non Tax-Deductible Items for period", boldfont); t.AddCell(cell); cell = new PdfPCell(t.DefaultCell); cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.Phrase = new Phrase(ntotal.ToString("N2"), font); t.AddCell(cell); ct.AddElement(t); } var col = 0; var status = 0; while (ColumnText.HasMoreText(status)) { if (col == 0) { ct.SetSimpleColumn(doc.Left, doc.Bottom, doc.Left + colwidth, pos); } else if (col == 1) { ct.SetSimpleColumn(doc.Right - colwidth, doc.Bottom, doc.Right, pos); } status = ct.Go(); ++col; if (col > 1) { col = 0; pos = doc.Top; doc.NewPage(); } } runningtotals.Processed += 1; runningtotals.CurrSet = set; db.SubmitChanges(); } if (count == 0) { doc.NewPage(); doc.Add(new Paragraph("no data")); var a = new Anchor("see this help document docs.touchpointsoftware.com/Finance/ContributionStatements.html") { Reference = "http://docs.touchpointsoftware.com/Finance/ContributionStatements.html#troubleshooting" }; doc.Add(a); } doc.Close(); if (set == LastSet()) { runningtotals.Completed = DateTime.Now; } db.SubmitChanges(); }
public MemoryStream GeneratePdfTemplate(RegradingResultDocsViewModel viewModel) { BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED); BaseFont bf_bold = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED); var normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); var bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Document document = new Document(PageSize.A5); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); writer.CloseStream = false; document.Open(); PdfContentByte cb = writer.DirectContent; cb.BeginText(); //cb.SetFontAndSize(bf, 8); //cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "PT DANLIRIS", 50, 378, 0); //cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "SUKOHARJO", 50, 368, 0); cb.SetFontAndSize(bf_bold, 8); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "FM.FP-01-PR.01-09.1-02", 290, 570, 0); cb.SetFontAndSize(bf_bold, 14); cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "BON Results RE-GRADING KAIN Here", 210, 540, 0); cb.SetFontAndSize(bf, 8); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "No Bon", 20, 500, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 90, 500, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, viewModel.Code, 100, 500, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Unit", 20, 490, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 90, 490, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, viewModel.Bon.UnitName, 100, 490, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Item name", 20, 480, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 90, 480, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, viewModel.Product.Name, 100, 480, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Long Datang", 20, 470, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 90, 470, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, string.Format("{0:n}", viewModel.TotalLength), 100, 470, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Grade Datang", 20, 460, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 90, 460, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, viewModel.OriginalGrade, 100, 460, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Date", 240, 500, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 290, 500, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, viewModel.CreatedUtc.ToString("MM-dd-yyyy"), 300, 500, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Nama Mesin", 240, 490, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 290, 490, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, viewModel.Machine.Name, 300, 490, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Operator", 240, 480, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 290, 480, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, viewModel.Operator, 300, 480, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Shift", 240, 470, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ":", 290, 470, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, viewModel.Shift, 300, 470, 0); cb.EndText(); #region CreateTable PdfPTable table = new PdfPTable(3); PdfPCell cell; table.TotalWidth = 380f; float[] widths = new float[] { 4f, 4f, 7f }; table.SetWidths(widths); cell = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; var rightCell = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; var leftCell = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; //Create cells headers. //cell.Phrase = new Phrase("Grade Asli", bold_font); //table.AddCell(cell); cell.Phrase = new Phrase("Results Regrade", bold_font); table.AddCell(cell); //cell.Phrase = new Phrase("Long Before", bold_font); //table.AddCell(cell); cell.Phrase = new Phrase("Long Re-grade", bold_font); table.AddCell(cell); cell.Phrase = new Phrase("Keterangan", bold_font); table.AddCell(cell); //int index = 1; foreach (var detail in viewModel.Details) { cell = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; //cell.Phrase = new Phrase(detail.GradeBefore, normal_font); //table.AddCell(cell); cell.Phrase = new Phrase(detail.Grade, normal_font); table.AddCell(cell); //cell.Phrase = new Phrase(string.Format("{0:n}", detail.LengthBeforeReGrade), normal_font); //table.AddCell(cell); cell.Phrase = new Phrase(string.Format("{0:n}", detail.Length), normal_font); table.AddCell(cell); cell = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 5 }; cell.Phrase = new Phrase(detail.Remark, normal_font); table.AddCell(cell); //index++; } table.WriteSelectedRows(0, -1, 20, 450, cb); #endregion cb.BeginText(); cb.SetTextMatrix(15, 23); cb.SetFontAndSize(bf, 8); cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Penerima,", 100, 110, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "(.................................)", 100, 50, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Operator", 100, 35, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Mengetahui,", 320, 110, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "(.................................)", 320, 50, 0); cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Kasubsie", 320, 35, 0); cb.EndText(); document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
private static void SetTableLocalForeignCurrency(Document document, ReportDto report, int timezoneOffset) { var table = new PdfPTable(18) { WidthPercentage = 100, HorizontalAlignment = Element.ALIGN_LEFT }; var cellCenter = new PdfPCell() { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_CENTER }; var cellCenterWithBackground = new PdfPCell() { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_CENTER, BackgroundColor = BaseColor.LightGray }; var cellLeft = new PdfPCell() { HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_CENTER }; var cellRight = new PdfPCell() { HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_CENTER }; cellCenterWithBackground.Rowspan = 2; cellCenterWithBackground.Phrase = new Phrase("Tanggal Bon", _subHeaderFont); table.AddCell(cellCenterWithBackground); cellCenterWithBackground.Phrase = new Phrase("Supplier", _subHeaderFont); table.AddCell(cellCenterWithBackground); cellCenterWithBackground.Phrase = new Phrase("Nama Barang", _subHeaderFont); table.AddCell(cellCenterWithBackground); cellCenterWithBackground.Phrase = new Phrase("No. Surat Jalan", _subHeaderFont); table.AddCell(cellCenterWithBackground); cellCenterWithBackground.Phrase = new Phrase("No. BP Besar", _subHeaderFont); table.AddCell(cellCenterWithBackground); cellCenterWithBackground.Phrase = new Phrase("No. BP Kecil", _subHeaderFont); table.AddCell(cellCenterWithBackground); cellCenterWithBackground.Phrase = new Phrase("No. Invoice", _subHeaderFont); table.AddCell(cellCenterWithBackground); cellCenterWithBackground.Phrase = new Phrase("No. Faktur Pajak", _subHeaderFont); table.AddCell(cellCenterWithBackground); cellCenterWithBackground.Phrase = new Phrase("No. NI", _subHeaderFont); table.AddCell(cellCenterWithBackground); cellCenterWithBackground.Phrase = new Phrase("Kategori Pembukuan", _subHeaderFont); table.AddCell(cellCenterWithBackground); cellCenterWithBackground.Phrase = new Phrase("Kuantitas", _subHeaderFont); table.AddCell(cellCenterWithBackground); cellCenterWithBackground.Phrase = new Phrase("Mata Uang", _subHeaderFont); table.AddCell(cellCenterWithBackground); cellCenterWithBackground.Phrase = new Phrase("Kurs", _subHeaderFont); table.AddCell(cellCenterWithBackground); cellCenterWithBackground.Rowspan = 1; cellCenterWithBackground.Colspan = 4; cellCenterWithBackground.Phrase = new Phrase("Pembelian", _subHeaderFont); table.AddCell(cellCenterWithBackground); cellCenterWithBackground.Rowspan = 2; cellCenterWithBackground.Colspan = 1; cellCenterWithBackground.Phrase = new Phrase("Total (IDR)", _subHeaderFont); table.AddCell(cellCenterWithBackground); cellCenterWithBackground.Rowspan = 1; cellCenterWithBackground.Colspan = 1; cellCenterWithBackground.Phrase = new Phrase("DPP Valas", _subHeaderFont); table.AddCell(cellCenterWithBackground); cellCenterWithBackground.Phrase = new Phrase("DPP (IDR)", _subHeaderFont); table.AddCell(cellCenterWithBackground); cellCenterWithBackground.Phrase = new Phrase("PPN (IDR)", _subHeaderFont); table.AddCell(cellCenterWithBackground); cellCenterWithBackground.Phrase = new Phrase("PPh (IDR)", _subHeaderFont); table.AddCell(cellCenterWithBackground); foreach (var accountingCategory in _accountingCategories) { var items = report.Data.Where(element => element.AccountingCategoryName == accountingCategory).ToList(); var currencyCodes = items.Select(element => element.CurrencyCode).Distinct().ToList(); if (items.Count > 0) { cellLeft.Colspan = 18; cellLeft.Phrase = new Phrase(GetAccountingCategoryFullString(accountingCategory), _normalBoldFont); table.AddCell(cellLeft); cellLeft.Colspan = 1; } foreach (var item in items) { cellCenter.Rowspan = 1; cellCenter.Colspan = 1; cellCenter.Phrase = new Phrase(item.CustomsArrivalDate.AddHours(timezoneOffset).ToString("dd/MM/yyyy"), _normalFont); table.AddCell(cellCenter); cellLeft.Phrase = new Phrase($"{item.SupplierCode} - {item.SupplierName}", _normalFont); table.AddCell(cellLeft); cellLeft.Phrase = new Phrase(item.ProductName, _normalFont); table.AddCell(cellLeft); cellCenter.Phrase = new Phrase(item.GarmentDeliveryOrderNo, _normalFont); table.AddCell(cellCenter); cellCenter.Phrase = new Phrase(item.BillNo, _normalFont); table.AddCell(cellCenter); cellCenter.Phrase = new Phrase(item.PaymentBill, _normalFont); table.AddCell(cellCenter); cellCenter.Phrase = new Phrase(item.InvoiceNo, _normalFont); table.AddCell(cellCenter); cellCenter.Phrase = new Phrase(item.VATNo, _normalFont); table.AddCell(cellCenter); cellCenter.Phrase = new Phrase(item.InternalNoteNo, _normalFont); table.AddCell(cellCenter); cellCenter.Phrase = new Phrase(item.AccountingCategoryName, _normalFont); table.AddCell(cellCenter); cellRight.Phrase = new Phrase(item.InternalNoteQuantity.ToString("0,0.00", CultureInfo.InvariantCulture), _normalFont); table.AddCell(cellRight); cellRight.Phrase = new Phrase(item.CurrencyCode, _normalFont); table.AddCell(cellRight); cellRight.Phrase = new Phrase(item.CurrencyRate.ToString("0,0.00", CultureInfo.InvariantCulture), _normalFont); table.AddCell(cellRight); cellRight.Phrase = new Phrase(item.CurrencyDPPAmount.ToString("0,0.00", CultureInfo.InvariantCulture), _normalFont); table.AddCell(cellRight); cellRight.Phrase = new Phrase(item.DPPAmount.ToString("0,0.00", CultureInfo.InvariantCulture), _normalFont); table.AddCell(cellRight); cellRight.Phrase = new Phrase(item.VATAmount.ToString("0,0.00", CultureInfo.InvariantCulture), _normalFont); table.AddCell(cellRight); cellRight.Phrase = new Phrase(item.IncomeTaxAmount.ToString("0,0.00", CultureInfo.InvariantCulture), _normalFont); table.AddCell(cellRight); cellRight.Phrase = new Phrase(item.Total.ToString("0,0.00", CultureInfo.InvariantCulture), _normalFont); table.AddCell(cellRight); } if (items.Count > 0) { var currencyTotalRemark = $"RINCIAN TOTAL {GetAccountingCategoryFullString(accountingCategory)}"; cellRight.Colspan = 11; cellRight.Rowspan = currencyCodes.Count; cellRight.Phrase = new Phrase(currencyTotalRemark, _normalBoldFont); table.AddCell(cellRight); cellRight.Colspan = 1; cellRight.Rowspan = 1; foreach (var currencyCode in currencyCodes) { var dppTotal = items.Sum(item => item.DPPAmount); var currencyDPPTotal = items.Sum(item => item.CurrencyDPPAmount); var vatTotal = items.Sum(item => item.VATAmount); var incomeTaxTotal = items.Sum(item => item.IncomeTaxAmount); var grandTotal = items.Sum(item => item.Total); cellCenter.Colspan = 2; cellCenter.Phrase = new Phrase(currencyCode, _normalBoldFont); table.AddCell(cellCenter); cellCenter.Colspan = 1; cellRight.Phrase = new Phrase(currencyDPPTotal.ToString("0,0.00", CultureInfo.InvariantCulture), _normalBoldFont); table.AddCell(cellRight); cellRight.Phrase = new Phrase(dppTotal.ToString("0,0.00", CultureInfo.InvariantCulture), _normalBoldFont); table.AddCell(cellRight); cellRight.Phrase = new Phrase(vatTotal.ToString("0,0.00", CultureInfo.InvariantCulture), _normalBoldFont); table.AddCell(cellRight); cellRight.Phrase = new Phrase(incomeTaxTotal.ToString("0,0.00", CultureInfo.InvariantCulture), _normalBoldFont); table.AddCell(cellRight); cellRight.Phrase = new Phrase(grandTotal.ToString("0,0.00", CultureInfo.InvariantCulture), _normalBoldFont); table.AddCell(cellRight); } var totalRemark = $"TOTAL {GetAccountingCategoryFullString(accountingCategory)}"; cellRight.Colspan = 17; cellRight.Phrase = new Phrase(totalRemark, _normalBoldFont); table.AddCell(cellRight); var total = items.Sum(item => item.Total); cellRight.Colspan = 1; cellRight.Phrase = new Phrase(total.ToString("0,0.00", CultureInfo.InvariantCulture), _normalBoldFont); table.AddCell(cellRight); } } document.Add(table); document.Add(new Paragraph("\n")); }
public MemoryStream GeneratePdfTemplate(DOSalesViewModel viewModel, int clientTimeZoneOffset) { const int MARGIN = 15; Font header_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 18); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Document document = new Document(PageSize.A4, MARGIN, MARGIN, MARGIN, MARGIN); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); #region Header PdfPTable headerTable = new PdfPTable(2); headerTable.SetWidths(new float[] { 10f, 10f }); headerTable.WidthPercentage = 100; PdfPTable headerTable1 = new PdfPTable(1); PdfPTable headerTable2 = new PdfPTable(1); PdfPCell cellHeader1 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeader2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderBody = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderCS2 = new PdfPCell() { Border = Rectangle.NO_BORDER, Colspan = 2 }; cellHeaderBody.Phrase = new Phrase("PT. DANLIRIS", header_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", header_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("No. " + viewModel.DOSalesNo, bold_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("FM-PJ-00-03-005 / R2", bold_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", header_font); headerTable1.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("Harap dikeluarkan barang tersebut di bawah ini : ", normal_font); headerTable1.AddCell(cellHeaderBody); cellHeader1.AddElement(headerTable1); headerTable.AddCell(cellHeader1); cellHeaderBody.Phrase = new Phrase("", normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.HorizontalAlignment = Element.ALIGN_CENTER; cellHeaderBody.Phrase = new Phrase("Sukoharjo, " + viewModel.DOSalesDate?.AddHours(clientTimeZoneOffset).ToString("dd MMMM yyyy", new CultureInfo("id-ID")), normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.HorizontalAlignment = Element.ALIGN_CENTER; cellHeaderBody.Phrase = new Phrase("Kepada", normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.HorizontalAlignment = Element.ALIGN_CENTER; cellHeaderBody.Phrase = new Phrase("Yth. Bpk./Ibu. " + viewModel.HeadOfStorage, normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.HorizontalAlignment = Element.ALIGN_CENTER; cellHeaderBody.Phrase = new Phrase("Bag. " + viewModel.StorageName + " / Div. " + viewModel.StorageDivision, normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.HorizontalAlignment = Element.ALIGN_CENTER; cellHeaderBody.Phrase = new Phrase("D.O. PENJUALAN", bold_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.HorizontalAlignment = Element.ALIGN_CENTER; cellHeaderBody.Phrase = new Phrase("Order dari " + viewModel.BuyerName, normal_font); headerTable2.AddCell(cellHeaderBody); cellHeaderBody.Phrase = new Phrase("", normal_font); headerTable2.AddCell(cellHeaderBody); cellHeader2.AddElement(headerTable2); headerTable.AddCell(cellHeader2); cellHeaderCS2.Phrase = new Phrase("", normal_font); headerTable.AddCell(cellHeaderCS2); document.Add(headerTable); #endregion Header Dictionary <string, double> units = new Dictionary <string, double>(); Dictionary <string, double> percentageUnits = new Dictionary <string, double>(); int index = 1; double totalPackingQuantity = 0; double totalImperialQuantity = 0; double totalMetricQuantity = 0; #region Body PdfPTable bodyTable = new PdfPTable(6); PdfPCell bodyCell = new PdfPCell(); float[] widthsBody = new float[] { 3f, 10f, 7f, 7f, 7f, 7f }; bodyTable.SetWidths(widthsBody); bodyTable.WidthPercentage = 100; bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase("No.", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Nama Barang", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Kode Barang", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Total Packing\n(" + viewModel.PackingUom + ")", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Total Panjang\n(" + viewModel.LengthUom + ")", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Phrase = new Phrase("Total Panjang\n( yard )", bold_font); bodyTable.AddCell(bodyCell); foreach (DOSalesDetailViewModel item in viewModel.DOSalesDetails) { bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.VerticalAlignment = Element.ALIGN_TOP; bodyCell.Phrase = new Phrase((index++).ToString(), normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyCell.Phrase = new Phrase(item.UnitName + " " + item.UnitRemark, normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_LEFT; bodyCell.Phrase = new Phrase(item.UnitCode, normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_RIGHT; bodyCell.Phrase = new Phrase(string.Format("{0:n2}", item.TotalPacking), normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_RIGHT; bodyCell.Phrase = new Phrase(string.Format("{0:n2}", item.TotalLength), normal_font); bodyTable.AddCell(bodyCell); bodyCell.HorizontalAlignment = Element.ALIGN_RIGHT; bodyCell.Phrase = new Phrase(string.Format("{0:n2}", item.TotalLengthConversion), normal_font); bodyTable.AddCell(bodyCell); } foreach (DOSalesDetailViewModel total in viewModel.DOSalesDetails) { totalPackingQuantity += total.TotalPacking; totalImperialQuantity += total.TotalLength; totalMetricQuantity += total.TotalLengthConversion; } bodyCell.Colspan = 2; bodyCell.Border = Rectangle.NO_BORDER; bodyCell.Phrase = new Phrase("", normal_font); bodyTable.AddCell(bodyCell); bodyCell.Colspan = 1; bodyCell.Border = Rectangle.BOX; bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase("Total", bold_font); bodyTable.AddCell(bodyCell); bodyCell.Colspan = 1; bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase(string.Format("{0:n2}", totalPackingQuantity), bold_font); bodyTable.AddCell(bodyCell); bodyCell.Colspan = 1; bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase(string.Format("{0:n2}", totalImperialQuantity), bold_font); bodyTable.AddCell(bodyCell); bodyCell.Colspan = 1; bodyCell.HorizontalAlignment = Element.ALIGN_CENTER; bodyCell.Phrase = new Phrase(string.Format("{0:n2}", totalMetricQuantity), bold_font); bodyTable.AddCell(bodyCell); document.Add(bodyTable); #endregion Body #region Footer PdfPTable footerTable = new PdfPTable(1); PdfPCell cellFooterLeft = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; float[] widthsFooter = new float[] { 10f }; footerTable.SetWidths(widthsFooter); footerTable.WidthPercentage = 100; cellFooterLeft.Phrase = new Phrase("", normal_font); footerTable.AddCell(cellFooterLeft); cellFooterLeft.Phrase = new Phrase("", normal_font); footerTable.AddCell(cellFooterLeft); cellFooterLeft.Phrase = new Phrase("Disp : " + viewModel.Disp + " Op : " + viewModel.Op + " Sc : " + viewModel.Sc, normal_font); footerTable.AddCell(cellFooterLeft); cellFooterLeft.Colspan = 3; cellFooterLeft.Phrase = new Phrase("", bold_font); footerTable.AddCell(cellFooterLeft); cellFooterLeft.Colspan = 3; cellFooterLeft.Phrase = new Phrase("Dikirim Kepada : " + viewModel.DestinationBuyerName, bold_font); footerTable.AddCell(cellFooterLeft); cellFooterLeft.Colspan = 3; cellFooterLeft.Phrase = new Phrase("Keterangan : " + viewModel.Remark, bold_font); footerTable.AddCell(cellFooterLeft); cellFooterLeft.Colspan = 3; cellFooterLeft.Phrase = new Phrase("", bold_font); footerTable.AddCell(cellFooterLeft); PdfPTable signatureTable = new PdfPTable(3) { HorizontalAlignment = Element.ALIGN_CENTER }; PdfPCell signatureCell = new PdfPCell() { HorizontalAlignment = Element.ALIGN_CENTER }; float[] widthsSignanture = new float[] { 10f, 10f, 10f }; signatureTable.SetWidths(widthsSignanture); signatureTable.WidthPercentage = 100; signatureCell.Phrase = new Phrase("Adm.Penjualan", normal_font); signatureTable.AddCell(signatureCell); signatureCell.Phrase = new Phrase("Gudang", normal_font); signatureTable.AddCell(signatureCell); signatureCell.Phrase = new Phrase("Terima kasih :\nBagian Penjualan", normal_font); signatureTable.AddCell(signatureCell); signatureTable.AddCell(new PdfPCell() { Phrase = new Phrase("--------------------------------", normal_font), FixedHeight = 40, VerticalAlignment = Element.ALIGN_BOTTOM, HorizontalAlignment = Element.ALIGN_CENTER }); signatureTable.AddCell(new PdfPCell() { Phrase = new Phrase("--------------------------------", normal_font), FixedHeight = 40, VerticalAlignment = Element.ALIGN_BOTTOM, HorizontalAlignment = Element.ALIGN_CENTER }); signatureTable.AddCell(new PdfPCell() { Phrase = new Phrase("--------------------------------", normal_font), FixedHeight = 40, VerticalAlignment = Element.ALIGN_BOTTOM, HorizontalAlignment = Element.ALIGN_CENTER }); footerTable.AddCell(new PdfPCell(signatureTable)); cellFooterLeft.Phrase = new Phrase("", normal_font); footerTable.AddCell(cellFooterLeft); document.Add(footerTable); #endregion Footer document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }