private void setBillPageHeader(Document document) { try { //Set Header Font var smallHeaderFont = FontFactory.GetFont("verdana", Convert.ToInt32(ConfigurationManager.AppSettings["smallHeaderFont"]), iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK); var headerFont = FontFactory.GetFont("verdana", Convert.ToInt32(ConfigurationManager.AppSettings["headerFont"]), iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK); var bigheaderFont = FontFactory.GetFont("verdana", Convert.ToInt32(ConfigurationManager.AppSettings["bigheaderFont"]), iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK); PdfPTable table = new PdfPTable(1); table.DeleteBodyRows(); table.WidthPercentage = 100; table.HorizontalAlignment = 0; table.SpacingBefore = 5; table.SpacingAfter = 5; newCell(table, "\n", 1, 0); newCell(table, "AN ISO 9000-2000 CERTIFIED HOSPITAL", smallHeaderFont, 1, 0); newCell(table, "Dr. V. S. Paramshetti, Miraj", headerFont, 1, 0); newCell(table, "\n", 1, 0); newCell(table, "RECEIPT", bigheaderFont, 1, 2); document.Add(table); } catch (Exception ex) { throw ex; } }
public ActionResult GeneratePdf(List <PdfView> sList, string date, string fromuser) { var document = new Document(PageSize.A4, 10, 10, 42, 35); PdfWriter.GetInstance(document, Response.OutputStream); document.Open(); var head = new Paragraph(date + "\n\n"); head.Alignment = Element.ALIGN_LEFT; document.Add(head); var serial = new Paragraph("MoveBy : " + fromuser); serial.Alignment = Element.ALIGN_LEFT; document.Add(serial); var table = new PdfPTable(4) { TotalWidth = 316f }; var widths = new float[] { 4f, 2f, 2f, 2f }; table.SetWidths(widths); table.HorizontalAlignment = 0; table.SpacingBefore = 30f; table.SpacingAfter = 40f; table.DeleteBodyRows(); table.AddCell("Code"); table.AddCell("Category"); table.AddCell("Brand"); table.AddCell("To"); foreach (var c in sList) { table.AddCell(c.AssecCode); table.AddCell(c.Category); table.AddCell(c.Brand); table.AddCell(c.ToBranch); } document.Add(table); var signeture = new Paragraph("Signature" + " " + "Signature\n\n" + "----------------" + " " + "---------------"); signeture.Alignment = Element.ALIGN_BOTTOM; document.Add(signeture); document.Close(); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment; filename =Movement.pdf"); Response.End(); return(RedirectToAction("Entry")); }
/// <summary> /// Create the slice header /// </summary> /// <param name="doc"> /// The <see cref="Document"/> /// </param> /// <param name="state"> /// The current <see cref="HtmlRenderer.RendererState"/> /// </param> private void CreateSliceHeader(IElementListener doc, RendererState state) { Table headerTable = this.CreateSliceHeaderTable(state); PdfPTable table = CreatePdf(headerTable); if (table != null) { doc.Add(table); table.DeleteBodyRows(); } }
private void setPrescriptionPageBody(Document document, OPDHistoryModel model) { try { var boldTableFont = FontFactory.GetFont("verdana", Convert.ToInt32(ConfigurationManager.AppSettings["bodyboldTable11"]), iTextSharp.text.Font.BOLD); var bodyFontNormal = FontFactory.GetFont("verdana", Convert.ToInt32(ConfigurationManager.AppSettings["bodyboldTable12"]), iTextSharp.text.Font.NORMAL); var headerFont = FontFactory.GetFont("verdana", Convert.ToInt32(ConfigurationManager.AppSettings["headerFont"]), iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK); var bigheaderFont = FontFactory.GetFont("verdana", Convert.ToInt32(ConfigurationManager.AppSettings["bigheaderFont"]), iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK); setPrescriptionPageHeader(document); PdfPTable table = new PdfPTable(2); table.DeleteBodyRows(); table.WidthPercentage = 100; table.HorizontalAlignment = 0; table.SpacingBefore = 5; table.SpacingAfter = 10; newCell(table, "DRUG SLIP", bigheaderFont, 1, 2, 2); blankCell(table, 2); newCell(table, "Name : " + model.PatientDetails.FullName, bodyFontNormal); newCell(table, "Date. : " + model.InTime.Value.ToShortDateString(), bodyFontNormal, 2, 0); newCell(table, "O.P.D No. : " + model.CasePaperNumber, bodyFontNormal, 0, 0, 2); blankCell(table, 2); newCell(table, "", bodyFontNormal, 0, 2, 2); newCell(table, "Rx", bigheaderFont, 0, 0); newCell(table, "Date: " + DateTime.Now.ToShortDateString(), boldTableFont, 2, 0); blankCell(table, 2); string[] splitArray = model.Madicines.Split(new string[] { "\\line" }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in splitArray) { string[] spArray = item.Split('$'); newCell(table, spArray[0].Trim(), bodyFontNormal, 0, 0); newCell(table, spArray[1].Trim(), bodyFontNormal, 0, 0); blankCell(table, 2); } for (int i = 0; i < 5; i++) { blankCell(table, 2); } newCell(table, "Doctor's Sign.", bodyFontNormal, 2, 0, 2); document.Add(table); } catch (Exception ex) { throw ex; } }
static void Main(string[] args) { using (var pdfDoc = new Document(PageSize.A4)) { var pdfWriter = PdfWriter.GetInstance(pdfDoc, new FileStream("Test.pdf", FileMode.Create)); pdfDoc.Open(); var table1 = new PdfPTable(3); table1.HeaderRows = 2; table1.FooterRows = 1; //header row var headerCell = new PdfPCell(new Phrase("header")); headerCell.Colspan = 3; headerCell.HorizontalAlignment = Element.ALIGN_CENTER; table1.AddCell(headerCell); //footer row var footerCell = new PdfPCell(new Phrase("footer")); footerCell.Colspan = 3; footerCell.HorizontalAlignment = Element.ALIGN_CENTER; table1.AddCell(footerCell); //adding some rows for (int i = 0; i < 70; i++) { //adds a new row table1.AddCell(new Phrase("Cell[0], Row[" + i + "]")); table1.AddCell(new Phrase("Cell[1], Row[" + i + "]")); table1.AddCell(new Phrase("Cell[2], Row[" + i + "]")); //sets the number of rows per page if (i > 0 && table1.Rows.Count % 7 == 0) { pdfDoc.Add(table1); table1.DeleteBodyRows(); pdfDoc.NewPage(); } } pdfDoc.Add(table1); } //open the final file with adobe reader for instance. Process.Start("Test.pdf"); }
private void Form1_Load(object sender, EventArgs e) { string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); Document document = new Document(); /* chapter06/PdfPTableSplit.java */ PdfWriter.GetInstance(document, new FileStream("PersistantHeader.pdf", FileMode.Create)); document.Open(); /* chapter06/PdfPTableMemoryFriendly.java */ PdfPTable table = new PdfPTable(2); table.WidthPercentage = 100; table.HeaderRows = 1; PdfPCell h1 = new PdfPCell(new Paragraph("Header 1")); h1.GrayFill = .7f; table.AddCell(h1); PdfPCell h2 = new PdfPCell(new Paragraph("Header 2")); h2.GrayFill = .7f; table.AddCell(h2); PdfPCell cell; for (int row = 1; row <= 2000; row++) { if (row % 50 == 0) { document.Add(table); table.DeleteBodyRows(); table.SkipFirstHeader = true; } cell = new PdfPCell(new Paragraph(row.ToString())); table.AddCell(cell); cell = new PdfPCell(new Paragraph("Quick brown fox jumps over the lazy dog.")); table.AddCell(cell); } document.Add(table); document.Close(); webBrowser1.Navigate(string.Concat(appPath, "\\", @"PersistantHeader.pdf")); }
private void setBillHeaderFooter(PdfWriter writer, iTextSharp.text.Document document) { try { //Set Header Font var smallHeaderFont = FontFactory.GetFont("verdana", Convert.ToInt32(ConfigurationManager.AppSettings["smallHeaderFont"]), iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK); var headerFont = FontFactory.GetFont("verdana", Convert.ToInt32(ConfigurationManager.AppSettings["headerFont"]), iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK); PdfPTable headerTable = new PdfPTable(1); headerTable.DeleteBodyRows(); headerTable.WidthPercentage = 100; headerTable.HorizontalAlignment = 0; headerTable.SpacingBefore = 2; headerTable.SpacingAfter = 1; Chunk c1 = new Chunk("\n", smallHeaderFont); Chunk c2 = new Chunk("AN ISO 9000-2000 CERTIFIED HOSPITAL\n", smallHeaderFont); Chunk c3 = new Chunk("Dr. V. S. Paramshetti, Miraj\n", headerFont); Chunk c4 = new Chunk("RECEIPT", headerFont); //Set header text Phrase headerPhrase = new Phrase(""); headerPhrase.Add(c1); headerPhrase.Add(c2); headerPhrase.Add(c3); headerPhrase.Add(c4); //Add header HeaderFooter header = new HeaderFooter(headerPhrase, false); header.Alignment = Element.ALIGN_CENTER; document.Add(headerPhrase); } catch (Exception ex) { throw ex; } //Add footer //HeaderFooter footer = new HeaderFooter(new Phrase(String.Format("Signature"), headerFont), false); //document.Footer = footer; //footer.Alignment = Element.ALIGN_RIGHT; //footer.Border = 0; }
/// <summary> /// Commit the current table and reset state /// </summary> /// <param name="state"> /// The state /// </param> /// <param name="doc"> /// The pdf document to commit the current table /// </param> private static void CommitTable(RendererState state, IDocListener doc) { if (state.Table != null) { PopulateTable(state); // containerTable.Write(writer); PdfPTable table = CreatePdf(state.Table); if (table != null) { doc.Add(table); table.DeleteBodyRows(); } doc.NewPage(); state.Reset(); } }
public MemoryStream GeneratePdfTemplate(CostCalculationGarmentViewModel viewModel, int timeoffset) { BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED); BaseFont bf_bold = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED); 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); Font bold_font_8 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); DateTime now = DateTime.Now; Document document = new Document(PageSize.A4, 10, 10, 10, 10); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); writer.CloseStream = false; document.Open(); PdfContentByte cb = writer.DirectContent; float margin = 10; float printedOnHeight = 10; float startY = 840 - margin; #region Header cb.BeginText(); cb.SetFontAndSize(bf, 10); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "PT. DAN LIRIS", 10, 820, 0); cb.SetFontAndSize(bf_bold, 12); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "COST CALCULATION EXPORT GARMENT", 10, 805, 0); cb.EndText(); #endregion #region Detail 1 (Top) PdfPTable table_detail1 = new PdfPTable(9); table_detail1.TotalWidth = 500f; float[] detail1_widths = new float[] { 1f, 0.1f, 2f, 1f, 0.1f, 2f, 1f, 0.1f, 2f }; table_detail1.SetWidths(detail1_widths); PdfPCell cell_detail1 = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 1, PaddingBottom = 2, PaddingTop = 2 }; PdfPCell cell_colon = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE }; cell_colon.Phrase = new Phrase(":", normal_font); cell_detail1.Phrase = new Phrase("RO", normal_font); table_detail1.AddCell(cell_detail1); table_detail1.AddCell(cell_colon); cell_detail1.Phrase = new Phrase($"{viewModel.RO_Number}", normal_font); table_detail1.AddCell(cell_detail1); cell_detail1.Phrase = new Phrase("SIZE RANGE", normal_font); table_detail1.AddCell(cell_detail1); table_detail1.AddCell(cell_colon); cell_detail1.Phrase = new Phrase($"{viewModel.SizeRange}", normal_font); table_detail1.AddCell(cell_detail1); cell_detail1.Phrase = new Phrase("LEAD TIME", normal_font); table_detail1.AddCell(cell_detail1); table_detail1.AddCell(cell_colon); cell_detail1.Phrase = new Phrase($"{viewModel.LeadTime} hari", normal_font); table_detail1.AddCell(cell_detail1); cell_detail1.Phrase = new Phrase("ARTICLE", normal_font); table_detail1.AddCell(cell_detail1); table_detail1.AddCell(cell_colon); cell_detail1.Phrase = new Phrase($"{viewModel.Article}", normal_font); table_detail1.AddCell(cell_detail1); cell_detail1.Phrase = new Phrase("SECTION", normal_font); table_detail1.AddCell(cell_detail1); table_detail1.AddCell(cell_colon); cell_detail1.Phrase = new Phrase($"{viewModel.Section}", normal_font); table_detail1.AddCell(cell_detail1); cell_detail1.Phrase = new Phrase("FABRIC", normal_font); table_detail1.AddCell(cell_detail1); table_detail1.AddCell(cell_colon); cell_detail1.Phrase = new Phrase($"{viewModel.FabricAllowance}%", normal_font); table_detail1.AddCell(cell_detail1); cell_detail1.Phrase = new Phrase("DATE", normal_font); table_detail1.AddCell(cell_detail1); table_detail1.AddCell(cell_colon); cell_detail1.Phrase = new Phrase($"{viewModel._CreatedUtc.ToString("dd MMMM yyyy")}", normal_font); table_detail1.AddCell(cell_detail1); cell_detail1.Phrase = new Phrase("COMMODITY", normal_font); table_detail1.AddCell(cell_detail1); table_detail1.AddCell(cell_colon); cell_detail1.Phrase = new Phrase($"{viewModel.Commodity.name}", normal_font); table_detail1.AddCell(cell_detail1); cell_detail1.Phrase = new Phrase("ACC", normal_font); table_detail1.AddCell(cell_detail1); table_detail1.AddCell(cell_colon); cell_detail1.Phrase = new Phrase($"{viewModel.AccessoriesAllowance}%", normal_font); table_detail1.AddCell(cell_detail1); cell_detail1.Phrase = new Phrase("KONVEKSI", normal_font); table_detail1.AddCell(cell_detail1); table_detail1.AddCell(cell_colon); cell_detail1.Phrase = new Phrase($"{viewModel.Convection}", normal_font); table_detail1.AddCell(cell_detail1); cell_detail1.Phrase = new Phrase("", normal_font); table_detail1.AddCell(cell_detail1); table_detail1.AddCell(cell_detail1); table_detail1.AddCell(cell_detail1); table_detail1.AddCell(cell_detail1); table_detail1.AddCell(cell_detail1); table_detail1.AddCell(cell_detail1); #endregion #region Image float imageHeight; try { byte[] imageByte = Convert.FromBase64String(Base64.GetBase64File(viewModel.ImageFile)); Image image = Image.GetInstance(imgb: imageByte); if (image.Width > 60) { float percentage = 0.0f; percentage = 60 / image.Width; image.ScalePercent(percentage * 100); } imageHeight = image.ScaledHeight; float imageY = 800 - imageHeight; image.SetAbsolutePosition(520, imageY); cb.AddImage(image, inlineImage: true); } catch (Exception) { imageHeight = 0; } #endregion #region Draw Top float row1Y = 800; table_detail1.WriteSelectedRows(0, -1, 10, row1Y, cb); #endregion bool isDollar = viewModel.Rate.Id != 0; #region Detail 2.1 (Bottom, Column 1.1) PdfPTable table_bottom_column1_1 = new PdfPTable(2); table_bottom_column1_1.TotalWidth = 180f; float[] table_bottom_column1_1_widths = new float[] { 1f, 2f }; table_bottom_column1_1.SetWidths(table_bottom_column1_1_widths); PdfPCell cell_bottom_column1_1 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7 }; cell_bottom_column1_1.Phrase = new Phrase("QTY", normal_font); table_bottom_column1_1.AddCell(cell_bottom_column1_1); cell_bottom_column1_1.Phrase = new Phrase($"{viewModel.Quantity} {viewModel.UOM.unit}", normal_font); table_bottom_column1_1.AddCell(cell_bottom_column1_1); cell_bottom_column1_1.Phrase = new Phrase("DESCRIPTION", normal_font); table_bottom_column1_1.AddCell(cell_bottom_column1_1); cell_bottom_column1_1.Phrase = new Phrase($"{viewModel.CommodityDescription}", normal_font); table_bottom_column1_1.AddCell(cell_bottom_column1_1); cell_bottom_column1_1.Phrase = new Phrase("CONT/STYLE", normal_font); table_bottom_column1_1.AddCell(cell_bottom_column1_1); cell_bottom_column1_1.Phrase = new Phrase($"{viewModel.Article}", normal_font); table_bottom_column1_1.AddCell(cell_bottom_column1_1); cell_bottom_column1_1.Phrase = new Phrase("BUYER", normal_font); table_bottom_column1_1.AddCell(cell_bottom_column1_1); cell_bottom_column1_1.Phrase = new Phrase($"{viewModel.Buyer.name}", normal_font); table_bottom_column1_1.AddCell(cell_bottom_column1_1); cell_bottom_column1_1.Phrase = new Phrase("DELIVERY", normal_font); table_bottom_column1_1.AddCell(cell_bottom_column1_1); cell_bottom_column1_1.Phrase = new Phrase($"{viewModel.DeliveryDate.AddHours(timeoffset).ToString("dd/MM/yyyy")}", normal_font); table_bottom_column1_1.AddCell(cell_bottom_column1_1); #endregion #region Detail 2_2 (Bottom, Column 1.2) PdfPTable table_bottom_column1_2 = new PdfPTable(2); table_bottom_column1_2.TotalWidth = 180f; float[] table_bottom_column1_2_widths = new float[] { 1f, 1f }; table_bottom_column1_2.SetWidths(table_bottom_column1_2_widths); PdfPCell cell_bottom_column1_2 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 3 }; cell_bottom_column1_2.Phrase = new Phrase("FOB PRICE", bold_font); table_bottom_column1_2.AddCell(cell_bottom_column1_2); cell_bottom_column1_2.Phrase = new Phrase("CMT PRICE", bold_font); table_bottom_column1_2.AddCell(cell_bottom_column1_2); double CM_Price = 0; foreach (CostCalculationGarment_MaterialViewModel item in viewModel.CostCalculationGarment_Materials) { CM_Price += item.CM_Price ?? 0; } double ConfirmPrice = viewModel.ConfirmPrice ?? 0; double CMT = CM_Price > 0 ? ConfirmPrice : 0; string CMT_Price = this.GetCurrencyValue(CMT, isDollar); double FOB = ConfirmPrice + CM_Price; string FOB_Price = this.GetCurrencyValue(FOB, isDollar); cell_bottom_column1_2.Phrase = new Phrase($"{FOB_Price}", normal_font); table_bottom_column1_2.AddCell(cell_bottom_column1_2); cell_bottom_column1_2.Phrase = new Phrase($"{CMT_Price}", normal_font); table_bottom_column1_2.AddCell(cell_bottom_column1_2); #endregion #region Detail 2.3 (Bottom, Column 1.3) PdfPTable table_bottom_column1_3 = new PdfPTable(2); table_bottom_column1_3.TotalWidth = 180f; float[] table_bottom_column1_3_widths = new float[] { 1f, 1f }; table_bottom_column1_3.SetWidths(table_bottom_column1_3_widths); PdfPCell cell_bottom_column1_3 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 3 }; cell_bottom_column1_3.Phrase = new Phrase("CNF PRICE", bold_font); table_bottom_column1_3.AddCell(cell_bottom_column1_3); cell_bottom_column1_3.Phrase = new Phrase("CIF PRICE", bold_font); table_bottom_column1_3.AddCell(cell_bottom_column1_3); string CNF_Price = this.GetCurrencyValue(0, isDollar); cell_bottom_column1_3.Phrase = new Phrase($"{CNF_Price}", normal_font); table_bottom_column1_3.AddCell(cell_bottom_column1_3); string CIF_Price = this.GetCurrencyValue(0, isDollar); cell_bottom_column1_3.Phrase = new Phrase($"{CIF_Price}", normal_font); table_bottom_column1_3.AddCell(cell_bottom_column1_3); #endregion #region Detail 3.1 (Bottom, Column 2.1) PdfPTable table_bottom_column2_1 = new PdfPTable(3); table_bottom_column2_1.TotalWidth = 190f; float[] table_bottom_column2_1_widths = new float[] { 1.5f, 1f, 1.5f }; table_bottom_column2_1.SetWidths(table_bottom_column2_1_widths); PdfPCell cell_bottom_column2_1 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 3 }; PdfPCell cell_bottom_column2_1_colspan2 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 3, Colspan = 2 }; cell_bottom_column2_1.Phrase = new Phrase("TOTAL", normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1); double total = 0; foreach (CostCalculationGarment_MaterialViewModel item in viewModel.CostCalculationGarment_Materials) { total += item.Total; } total += viewModel.ProductionCost; cell_bottom_column2_1_colspan2.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(total), normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1_colspan2); cell_bottom_column2_1.Phrase = new Phrase("OTL 1", normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1); double OTL1CalculatedValue = viewModel.OTL1.CalculatedValue ?? 0; cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(OTL1CalculatedValue)}", normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1); double afterOTL1 = total + OTL1CalculatedValue; cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(afterOTL1)}", normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1); cell_bottom_column2_1.Phrase = new Phrase("OTL 2", normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1); double OTL2CalculatedValue = viewModel.OTL2.CalculatedValue ?? 0; cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(OTL2CalculatedValue)}", normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1); double afterOTL2 = afterOTL1 + OTL2CalculatedValue; cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(afterOTL2)}", normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1); cell_bottom_column2_1.Phrase = new Phrase("RISK", normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1); cell_bottom_column2_1.Phrase = new Phrase(String.Format("{0:0.00}%", viewModel.Risk), normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1); double afterRisk = (100 + viewModel.Risk) * afterOTL2 / 100;; cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(afterRisk)}", normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1); cell_bottom_column2_1.Phrase = new Phrase("BEA ANGKUT", normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1); cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(viewModel.FreightCost)}", normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1); double afterFreightCost = afterRisk + viewModel.FreightCost; cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(afterFreightCost)}", normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1); cell_bottom_column2_1.Phrase = new Phrase("SUB TOTAL", normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1); cell_bottom_column2_1_colspan2.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(afterFreightCost)}", normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1_colspan2); cell_bottom_column2_1.Phrase = new Phrase("NET/FOB (%)", normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1); cell_bottom_column2_1.Phrase = new Phrase(String.Format("{0:0.00}%", viewModel.NETFOBP), normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1); cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(viewModel.NETFOB)}", normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1); cell_bottom_column2_1.Phrase = new Phrase("COMM (%)", normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1); cell_bottom_column2_1.Phrase = new Phrase(String.Format("{0:0.00}%", viewModel.CommissionPortion), normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1); cell_bottom_column2_1.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(viewModel.CommissionRate)}", normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1); cell_bottom_column2_1.Phrase = new Phrase("CONFIRM PRICE", normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1);; double confirmPrice = viewModel.ConfirmPrice ?? 0 + viewModel.Rate.Value ?? 0; double confirmPriceWithRate = isDollar ? confirmPrice * viewModel.Rate.Value ?? 1 : confirmPrice; cell_bottom_column2_1_colspan2.Phrase = new Phrase($"{Number.ToRupiahWithoutSymbol(confirmPriceWithRate)}", normal_font); table_bottom_column2_1.AddCell(cell_bottom_column2_1_colspan2); #endregion #region Detail 3.2 (Bottom, Column 2.2) PdfPTable table_bottom_column2_2 = new PdfPTable(4); table_bottom_column2_2.TotalWidth = 190f; float[] table_bottom_column2_2_widths = new float[] { 1f, 1.25f, 1f, 1.25f }; table_bottom_column2_2.SetWidths(table_bottom_column2_2_widths); PdfPCell cell_bottom_column2_2 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3, Colspan = 2 }; cell_bottom_column2_2 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3, Colspan = 2 }; cell_bottom_column2_2.Phrase = new Phrase("FREIGHT", normal_font); table_bottom_column2_2.AddCell(cell_bottom_column2_2); cell_bottom_column2_2 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3, Colspan = 2 }; string freight = this.GetCurrencyValue(viewModel.Freight ?? 0, isDollar); cell_bottom_column2_2.Phrase = new Phrase($"= {freight}", normal_font); table_bottom_column2_2.AddCell(cell_bottom_column2_2); cell_bottom_column2_2 = new PdfPCell() { Border = Rectangle.LEFT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3, Colspan = 2 }; cell_bottom_column2_2.Phrase = new Phrase("INSURANCE", normal_font); table_bottom_column2_2.AddCell(cell_bottom_column2_2); cell_bottom_column2_2 = new PdfPCell() { Border = Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3, Colspan = 2 }; string insurance = this.GetCurrencyValue(viewModel.Insurance ?? 0, isDollar); cell_bottom_column2_2.Phrase = new Phrase($"= {insurance}", normal_font); table_bottom_column2_2.AddCell(cell_bottom_column2_2); cell_bottom_column2_2 = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3, Colspan = 2 }; cell_bottom_column2_2.Phrase = new Phrase("CONFIRM PRICE", normal_font); table_bottom_column2_2.AddCell(cell_bottom_column2_2); cell_bottom_column2_2 = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3, Colspan = 2 }; string confirmPriceFOB = this.GetCurrencyValue(viewModel.ConfirmPrice ?? 0, isDollar); cell_bottom_column2_2.Phrase = new Phrase($"= {confirmPriceFOB}", normal_font); table_bottom_column2_2.AddCell(cell_bottom_column2_2); cell_bottom_column2_2 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3 }; cell_bottom_column2_2.Phrase = new Phrase("SMV CUT", normal_font); table_bottom_column2_2.AddCell(cell_bottom_column2_2); cell_bottom_column2_2 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3 }; cell_bottom_column2_2.Phrase = new Phrase($"= {viewModel.SMV_Cutting}", normal_font); table_bottom_column2_2.AddCell(cell_bottom_column2_2); cell_bottom_column2_2 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3 }; cell_bottom_column2_2.Phrase = new Phrase("SMV SEW", normal_font); table_bottom_column2_2.AddCell(cell_bottom_column2_2); cell_bottom_column2_2 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3 }; cell_bottom_column2_2.Phrase = new Phrase($"= {viewModel.SMV_Sewing}", normal_font); table_bottom_column2_2.AddCell(cell_bottom_column2_2); cell_bottom_column2_2 = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3 }; cell_bottom_column2_2.Phrase = new Phrase("SMV FIN", normal_font); table_bottom_column2_2.AddCell(cell_bottom_column2_2); cell_bottom_column2_2 = new PdfPCell() { Border = Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3 }; cell_bottom_column2_2.Phrase = new Phrase($"= {viewModel.SMV_Finishing}", normal_font); table_bottom_column2_2.AddCell(cell_bottom_column2_2); cell_bottom_column2_2 = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3 }; cell_bottom_column2_2.Phrase = new Phrase("SMV TOT", normal_font); table_bottom_column2_2.AddCell(cell_bottom_column2_2); cell_bottom_column2_2 = new PdfPCell() { Border = Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingTop = 5, PaddingRight = 3, PaddingBottom = 5, PaddingLeft = 3 }; cell_bottom_column2_2.Phrase = new Phrase($"= {viewModel.SMV_Total}", normal_font); table_bottom_column2_2.AddCell(cell_bottom_column2_2); #endregion #region Detail 4 (Bottom, Column 3.1) PdfPTable table_bottom_column3_1 = new PdfPTable(2); table_bottom_column3_1.TotalWidth = 180f; float[] table_bottom_column3_1_widths = new float[] { 1f, 2f }; table_bottom_column3_1.SetWidths(table_bottom_column3_1_widths); PdfPCell cell_bottom_column3_1 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7 }; cell_bottom_column3_1.Phrase = new Phrase("DESCRIPTION", normal_font); table_bottom_column3_1.AddCell(cell_bottom_column3_1); cell_bottom_column3_1.Phrase = new Phrase($"{viewModel.Description}", normal_font); table_bottom_column3_1.AddCell(cell_bottom_column3_1); #endregion #region Signature PdfPTable table_signature = new PdfPTable(3); table_signature.TotalWidth = 570f; float[] signature_widths = new float[] { 1f, 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 }; //cell_signature.Phrase = new Phrase("", normal_font); //table_signature.AddCell(cell_signature); //cell_signature.Phrase = new Phrase("", normal_font); //table_signature.AddCell(cell_signature); string signatureArea = string.Empty; for (int i = 0; i < 5; i++) { signatureArea += Environment.NewLine; } cell_signature.Phrase = new Phrase(signatureArea, normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase(signatureArea, normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase(signatureArea, normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("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.Phrase = new Phrase("Kadiv. Penjualan", normal_font); table_signature.AddCell(cell_signature); #endregion #region Cost Calculation Material PdfPTable table_ccm = new PdfPTable(7); table_ccm.TotalWidth = 570f; float[] ccm_widths = new float[] { 1.25f, 3.5f, 3.5f, 5f, 3f, 4f, 4f }; table_ccm.SetWidths(ccm_widths); PdfPCell cell_ccm_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_ccm_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_ccm_right = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2 }; cell_ccm_center.Phrase = new Phrase("NO", bold_font); table_ccm.AddCell(cell_ccm_center); cell_ccm_center.Phrase = new Phrase("KATEGORI", bold_font); table_ccm.AddCell(cell_ccm_center); cell_ccm_center.Phrase = new Phrase("KODE PRODUK", bold_font); table_ccm.AddCell(cell_ccm_center); cell_ccm_center.Phrase = new Phrase("DESKRIPSI", bold_font); table_ccm.AddCell(cell_ccm_center); cell_ccm_center.Phrase = new Phrase("QUANTITY", bold_font); table_ccm.AddCell(cell_ccm_center); cell_ccm_center.Phrase = new Phrase("USD. PTC/PC", bold_font); table_ccm.AddCell(cell_ccm_center); cell_ccm_center.Phrase = new Phrase("USD. TOTAL", bold_font); table_ccm.AddCell(cell_ccm_center); double Total = 0; float row1Height = imageHeight > table_detail1.TotalHeight ? imageHeight : table_detail1.TotalHeight; float row2Y = row1Y - row1Height - 10; float[] row3Heights = { table_bottom_column1_1.TotalHeight + 10 + table_bottom_column1_2.TotalHeight + 10 + table_bottom_column1_3.TotalHeight, table_bottom_column2_1.TotalHeight + 10 + table_bottom_column2_2.TotalHeight, table_bottom_column3_1.TotalHeight }; float dollarDetailHeight = 10; if (isDollar) { row3Heights[1] += dollarDetailHeight; } float row3Height = row3Heights.Max(); float secondHighestRow3Height = row3Heights[1] > row3Heights[2] ? row3Heights[1] : row3Heights[2]; bool signatureInsideRow3 = row3Heights.Max() == row3Heights[0] && row3Heights[0] - 10 - secondHighestRow3Height > table_signature.TotalHeight; float row2RemainingHeight = row2Y - 10 - row3Height - printedOnHeight - margin; float row2AllowedHeight = row2Y - printedOnHeight - margin; for (int i = 0; i < viewModel.CostCalculationGarment_Materials.Count; i++) { //NO cell_ccm_center.Phrase = new Phrase((i + 1).ToString(), normal_font); table_ccm.AddCell(cell_ccm_center); //KATEGORI cell_ccm_left.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].Category.name, normal_font); table_ccm.AddCell(cell_ccm_left); //KODE PRODUK cell_ccm_left.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].Product.code, normal_font); table_ccm.AddCell(cell_ccm_left); //DESKRIPSI cell_ccm_left.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].Description, normal_font); table_ccm.AddCell(cell_ccm_left); cell_ccm_right.Phrase = new Phrase(String.Format("{0} {1}", viewModel.CostCalculationGarment_Materials[i].Quantity, viewModel.CostCalculationGarment_Materials[i].UOMQuantity.unit), normal_font); table_ccm.AddCell(cell_ccm_right); cell_ccm_right.Phrase = new Phrase(String.Format("{0}/{1}", Number.ToRupiahWithoutSymbol(viewModel.CostCalculationGarment_Materials[i].Price), viewModel.CostCalculationGarment_Materials[i].UOMPrice.unit), normal_font); table_ccm.AddCell(cell_ccm_right); cell_ccm_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.CostCalculationGarment_Materials[i].Total), normal_font); table_ccm.AddCell(cell_ccm_right); Total += viewModel.CostCalculationGarment_Materials[i].Total; float currentHeight = table_ccm.TotalHeight; if (currentHeight / row2RemainingHeight > 1) { if (currentHeight / row2AllowedHeight > 1) { PdfPRow headerRow = table_ccm.GetRow(0); PdfPRow lastRow = table_ccm.GetRow(table_ccm.Rows.Count - 1); table_ccm.DeleteLastRow(); table_ccm.WriteSelectedRows(0, -1, 10, row2Y, cb); table_ccm.DeleteBodyRows(); this.DrawPrintedOn(now, bf, cb); document.NewPage(); table_ccm.Rows.Add(headerRow); table_ccm.Rows.Add(lastRow); table_ccm.CalculateHeights(); row2Y = startY; row2RemainingHeight = row2Y - 10 - row3Height - printedOnHeight - margin; row2AllowedHeight = row2Y - printedOnHeight - margin; } } } cell_ccm_right = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2, Colspan = 6 }; cell_ccm_right.Phrase = new Phrase("TOTAL", bold_font_8); table_ccm.AddCell(cell_ccm_right); cell_ccm_right = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2 }; cell_ccm_right.Phrase = new Phrase(Number.ToRupiah(Total), bold_font_8); table_ccm.AddCell(cell_ccm_right); #endregion #region Draw Middle and Bottom table_ccm.WriteSelectedRows(0, -1, 10, row2Y, cb); float row3Y = row2Y - table_ccm.TotalHeight - 10; float row3RemainingHeight = row3Y - printedOnHeight - margin; if (row3RemainingHeight < row3Height) { this.DrawPrintedOn(now, bf, cb); row3Y = startY; document.NewPage(); } table_bottom_column1_1.WriteSelectedRows(0, -1, 10, row3Y, cb); float detail1_2Y = row3Y - table_bottom_column1_1.TotalHeight - 10; table_bottom_column1_2.WriteSelectedRows(0, -1, 10, detail1_2Y, cb); float detail1_3Y = detail1_2Y - table_bottom_column1_2.TotalHeight - 10; table_bottom_column1_3.WriteSelectedRows(0, -1, 10, detail1_3Y, cb); table_bottom_column2_1.WriteSelectedRows(0, -1, 200, row3Y, cb); float noteY = row3Y - table_bottom_column2_1.TotalHeight; float table_bottom_column2_2Y; if (isDollar) { noteY = noteY - 15; table_bottom_column2_2Y = noteY - 5; cb.BeginText(); cb.SetFontAndSize(bf, 7); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, $"NOTE: 1 US$ = {Number.ToRupiah(viewModel.Rate.Value)}", 200, noteY, 0); cb.EndText(); } else { table_bottom_column2_2Y = noteY - 10; } table_bottom_column2_2.WriteSelectedRows(0, -1, 200, table_bottom_column2_2Y, cb); //table_bottom_column1_2.WriteSelectedRows(0, -1, 400, row3Y, cb); table_bottom_column3_1.WriteSelectedRows(0, -1, 400, row3Y, cb); float table_signatureX; float table_signatureY; if (signatureInsideRow3) { table_signatureX = margin + table_bottom_column2_2.TotalWidth + 10; table_signatureY = row3Y - row3Height + table_signature.TotalHeight; table_signature.TotalWidth = 390f; } else { table_signatureX = margin; table_signatureY = row3Y - row3Height - 10; float signatureRemainingHeight = table_signatureY - printedOnHeight - margin; if (signatureRemainingHeight < table_signature.TotalHeight) { this.DrawPrintedOn(now, bf, cb); table_signatureY = startY; document.NewPage(); } } table_signature.WriteSelectedRows(0, -1, table_signatureX, table_signatureY, cb); this.DrawPrintedOn(now, bf, cb); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(RO_RetailViewModel 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); 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); Font bold_font_8 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font font_9 = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9); DateTime now = DateTime.Now; Document document = new Document(PageSize.A4, 10, 10, 10, 10); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); writer.CloseStream = false; document.Open(); PdfContentByte cb = writer.DirectContent; float margin = 10; float printedOnHeight = 10; float startY = 840 - margin; #region Header cb.BeginText(); cb.SetFontAndSize(bf, 10); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "PT. EFRATA RETAILINDO", 10, 820, 0); cb.SetFontAndSize(bf_bold, 12); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "RO RETAIL", 10, 805, 0); cb.EndText(); #endregion #region Top PdfPTable table_top = new PdfPTable(9); float[] top_widths = new float[] { 1f, 0.1f, 2f, 1f, 0.1f, 2f, 1f, 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_MIDDLE, PaddingRight = 1, PaddingBottom = 2, PaddingTop = 2 }; PdfPCell cell_colon = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE }; PdfPCell cell_top_keterangan = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, 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.CostCalculationRetail.RO}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("ARTICLE", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.CostCalculationRetail.Article}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("STYLE", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.CostCalculationRetail.Style.name}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("COUNTER", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.CostCalculationRetail.Counter.name}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("COLOUR", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.Color.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.CostCalculationRetail.DeliveryDate.ToString("dd MMMM yyyy")}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("RO QUANTITY", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top_keterangan.Phrase = new Phrase($"{viewModel.Total}", normal_font); table_top.AddCell(cell_top_keterangan); #endregion #region Image byte[] imageByte; try { imageByte = Convert.FromBase64String(Base64.GetBase64File(viewModel.CostCalculationRetail.ImageFile)); } catch (Exception) { var webClient = new WebClient(); imageByte = webClient.DownloadData("https://bateeqstorage.blob.core.windows.net/other/no-image.jpg"); } Image image = Image.GetInstance(imgb: imageByte); if (image.Width > 60) { float percentage = 0.0f; percentage = 60 / image.Width; image.ScalePercent(percentage * 100); } #endregion #region Draw Top float row1Y = 800; float imageY = 800 - image.ScaledHeight; table_top.WriteSelectedRows(0, -1, 10, row1Y, cb); image.SetAbsolutePosition(520, imageY); cb.AddImage(image, inlineImage: true); #endregion #region Fabric Table 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); float row1Height = image.ScaledHeight > table_top.TotalHeight ? image.ScaledHeight : table_top.TotalHeight; float rowYTittleFab = row1Y - row1Height - 10; float allowedRow2Height = rowYTittleFab - printedOnHeight - margin; table_fabric_top.WriteSelectedRows(0, -1, 10, rowYTittleFab, cb); #endregion #region Fabric Table PdfPTable table_fabric = new PdfPTable(5); table_fabric.TotalWidth = 570f; float[] fabric_widths = new float[] { 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 }; float rowYFab = rowYTittleFab - table_fabric_top.TotalHeight - 5; float allowedRow2HeightFab = rowYFab - printedOnHeight - margin; cell_fabric_center.Phrase = new Phrase("FABRIC", bold_font); table_fabric.AddCell(cell_fabric_center); cell_fabric_center.Phrase = new Phrase("NAME", 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.CostCalculationRetail.CostCalculationRetail_Materials) { if (materialModel.Category.Name == "FAB") { 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.Material.Name != null ? materialModel.Material.Name : "", 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 != null ? String.Format("{0} " + materialModel.UOMQuantity.Name, materialModel.Quantity) : "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.WriteSelectedRows(0, -1, 10, rowYFab, cb); #endregion #region Accessoris Table 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); float rowYTittleAcc = rowYFab - table_fabric.TotalHeight - 10; float allowedRow2HeightTopAcc = rowYTittleFab - printedOnHeight - margin; table_acc_top.WriteSelectedRows(0, -1, 10, rowYTittleAcc, cb); #endregion #region Accessoris Table PdfPTable table_accessories = new PdfPTable(5); table_accessories.TotalWidth = 570f; float[] accessories_widths = new float[] { 5f, 5f, 5f, 5f, 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 }; float rowYAcc = rowYTittleAcc - table_fabric_top.TotalHeight - 5; float allowedRow2HeightAcc = rowYAcc - printedOnHeight - margin; cell_acc_center.Phrase = new Phrase("ACCESSORIES", bold_font); table_accessories.AddCell(cell_acc_center); cell_acc_center.Phrase = new Phrase("NAME", bold_font); table_accessories.AddCell(cell_acc_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.CostCalculationRetail.CostCalculationRetail_Materials) { if (materialModel.Category.Name == "ACC") { cell_acc_left.Phrase = new Phrase(materialModel.Category.SubCategory != null ? materialModel.Category.SubCategory : "", normal_font); table_accessories.AddCell(cell_acc_left); cell_acc_left.Phrase = new Phrase(materialModel.Material.Name != null ? materialModel.Material.Name : "", 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.Name, materialModel.Quantity) : "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.WriteSelectedRows(0, -1, 10, rowYAcc, cb); #endregion #region Ongkos Table Title PdfPTable table_ong_top = new PdfPTable(1); table_ong_top.TotalWidth = 570f; float[] ong_width_top = new float[] { 5f }; table_ong_top.SetWidths(ong_width_top); PdfPCell cell_top_ong = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 1, PaddingBottom = 2, PaddingTop = 2 }; cell_top_ong.Phrase = new Phrase("ONGKOS", bold_font); table_ong_top.AddCell(cell_top_ong); float rowYTittleOng = rowYAcc - table_accessories.TotalHeight - 10; float allowedRow2HeightTopOng = rowYTittleOng - printedOnHeight - margin; #endregion #region Ongkos Table PdfPTable table_budget = new PdfPTable(5); table_budget.TotalWidth = 570f; float[] budget_widths = new float[] { 5f, 5f, 5f, 5f, 5f }; table_budget.SetWidths(budget_widths); var ongIndex = 0; PdfPCell cell_budget_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_budget_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 }; float rowYBudget = rowYTittleOng - table_ong_top.TotalHeight - 5; float allowedRow2HeightBudget = rowYBudget - printedOnHeight - margin; cell_budget_center.Phrase = new Phrase("ONGKOS", bold_font); table_budget.AddCell(cell_budget_center); cell_budget_center.Phrase = new Phrase("NAME", bold_font); table_budget.AddCell(cell_budget_center); cell_budget_center.Phrase = new Phrase("DESCRIPTION", bold_font); table_budget.AddCell(cell_budget_center); cell_budget_center.Phrase = new Phrase("QUANTITY", bold_font); table_budget.AddCell(cell_budget_center); cell_budget_center.Phrase = new Phrase("REMARK", bold_font); table_budget.AddCell(cell_budget_center); foreach (var materialModel in viewModel.CostCalculationRetail.CostCalculationRetail_Materials) { if (materialModel.Category.Name == "ONG") { cell_budget_left.Phrase = new Phrase(materialModel.Category.SubCategory != null ? materialModel.Category.SubCategory : "", normal_font); table_budget.AddCell(cell_budget_left); cell_budget_left.Phrase = new Phrase(materialModel.Material.Name != null ? materialModel.Material.Name : "", normal_font); table_budget.AddCell(cell_budget_left); cell_budget_left.Phrase = new Phrase(materialModel.Description != null ? materialModel.Description : "", normal_font); table_budget.AddCell(cell_budget_left); cell_budget_left.Phrase = new Phrase(materialModel.Quantity != null ? String.Format("{0} " + materialModel.UOMQuantity.Name, materialModel.Quantity) : "0", normal_font); table_budget.AddCell(cell_budget_left); cell_budget_left.Phrase = new Phrase(materialModel.Information != null ? materialModel.Information : "", normal_font); table_budget.AddCell(cell_budget_left); ongIndex++; } } if (ongIndex != 0) { table_budget.WriteSelectedRows(0, -1, 10, rowYBudget, cb); table_ong_top.WriteSelectedRows(0, -1, 10, rowYTittleOng, cb); } #endregion #region 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); float rowYTittleBreakDown = rowYBudget - table_budget.TotalHeight - 10; float allowedRow2HeightBreakdown = rowYTittleBreakDown - printedOnHeight - margin; table_breakdown_top.WriteSelectedRows(0, -1, 10, rowYTittleBreakDown, cb); #endregion #region == Table Size Breakdown == var tableBreakdownColumn = 3; 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 }; float rowYbreakDown = rowYTittleBreakDown - table_breakdown_top.TotalHeight - 5; float allowedRow2HeightBreakDown = rowYbreakDown - printedOnHeight - margin; var remainingRowToHeightBrekdown = rowYbreakDown - 5 - printedOnHeight - margin; List <String> breakdownSizes = new List <string>(); foreach (var size in viewModel.RO_Retail_SizeBreakdowns) { var sizes = size.SizeQuantity.Keys; foreach (var values in sizes) { if (!breakdownSizes.Contains(values)) { breakdownSizes.Add(values); tableBreakdownColumn++; } } } PdfPTable table_breakDown = new PdfPTable(tableBreakdownColumn); table_breakDown.TotalWidth = 570f; cell_breakDown_center.Phrase = new Phrase("STORE CODE", bold_font); table_breakDown.AddCell(cell_breakDown_center); cell_breakDown_center.Phrase = new Phrase("STORE", bold_font); table_breakDown.AddCell(cell_breakDown_center); foreach (var size in breakdownSizes) { cell_breakDown_center.Phrase = new Phrase(size, bold_font); table_breakDown.AddCell(cell_breakDown_center); } cell_breakDown_center.Phrase = new Phrase("TOTAL", bold_font); table_breakDown.AddCell(cell_breakDown_center); foreach (var productRetail in viewModel.RO_Retail_SizeBreakdowns) { if (productRetail.Total != 0) { cell_breakDown_left.Phrase = new Phrase(productRetail.Store.code != null ? productRetail.Store.code : "", normal_font); table_breakDown.AddCell(cell_breakDown_left); cell_breakDown_left.Phrase = new Phrase(productRetail.Store.name != null ? productRetail.Store.name : "", normal_font); table_breakDown.AddCell(cell_breakDown_left); foreach (var size in productRetail.SizeQuantity) { foreach (var sizeHeader in breakdownSizes) { if (size.Key == sizeHeader) { cell_breakDown_left.Phrase = new Phrase(size.Value.ToString() != null ? size.Value.ToString() : "0", normal_font); table_breakDown.AddCell(cell_breakDown_left); } } } cell_breakDown_left.Phrase = new Phrase(productRetail.Total.ToString() != null ? productRetail.Total.ToString() : "0", normal_font); table_breakDown.AddCell(cell_breakDown_left); } var tableBreakdownCurrentHeight = table_breakDown.TotalHeight; if (tableBreakdownCurrentHeight / remainingRowToHeightBrekdown > 1) { if (tableBreakdownCurrentHeight / allowedRow2HeightBreakDown > 1) { PdfPRow headerRow = table_breakDown.GetRow(0); PdfPRow lastRow = table_breakDown.GetRow(table_breakDown.Rows.Count - 1); table_breakDown.DeleteLastRow(); table_breakDown.WriteSelectedRows(0, -1, 10, rowYbreakDown, cb); table_breakDown.DeleteBodyRows(); this.DrawPrintedOn(now, bf, cb); document.NewPage(); table_breakDown.Rows.Add(headerRow); table_breakDown.Rows.Add(lastRow); table_breakDown.CalculateHeights(); rowYbreakDown = startY; remainingRowToHeightBrekdown = rowYbreakDown - 5 - printedOnHeight - margin; allowedRow2HeightBreakDown = remainingRowToHeightBrekdown - printedOnHeight - margin; } } } cell_breakDown_total.Phrase = new Phrase(" ", bold_font); table_breakDown.AddCell(cell_breakDown_total); cell_breakDown_total_2.Phrase = new Phrase("TOTAL", bold_font); table_breakDown.AddCell(cell_breakDown_total_2); foreach (var sizeTotal in viewModel.SizeQuantityTotal) { cell_breakDown_left.Phrase = new Phrase(sizeTotal.Value.ToString() != null ? sizeTotal.Value.ToString() : "0", normal_font); table_breakDown.AddCell(cell_breakDown_left); } cell_breakDown_left.Phrase = new Phrase(viewModel.Total.ToString() != null ? viewModel.Total.ToString() : "0", normal_font); table_breakDown.AddCell(cell_breakDown_left); table_breakDown.WriteSelectedRows(0, -1, 10, rowYbreakDown, cb); #endregion #region Table Instruksi 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); float rowYInstruction = rowYbreakDown - table_breakDown.TotalHeight - 5; float allowedRow2HeightInstruction = rowYInstruction - printedOnHeight - margin; var remainingRowToHeightInstruction = rowYInstruction - 5 - printedOnHeight - margin; var tableInstructionCurrentHeight = table_instruction.TotalHeight; if (remainingRowToHeightInstruction < 0) { remainingRowToHeightInstruction = remainingRowToHeightInstruction * -1; } if (allowedRow2HeightInstruction < 0) { allowedRow2HeightInstruction = allowedRow2HeightInstruction * -1; } if (tableInstructionCurrentHeight / remainingRowToHeightInstruction > 1) { if (tableInstructionCurrentHeight / allowedRow2HeightInstruction > 1) { PdfPRow headerRow = table_instruction.GetRow(0); PdfPRow lastRow = table_instruction.GetRow(table_instruction.Rows.Count - 1); table_instruction.DeleteLastRow(); table_instruction.WriteSelectedRows(0, -1, 10, rowYInstruction, cb); table_instruction.DeleteBodyRows(); this.DrawPrintedOn(now, bf, cb); document.NewPage(); table_instruction.Rows.Add(headerRow); table_instruction.Rows.Add(lastRow); table_instruction.CalculateHeights(); rowYInstruction = startY; remainingRowToHeightInstruction = rowYInstruction - 5 - printedOnHeight - margin; allowedRow2HeightInstruction = remainingRowToHeightInstruction - printedOnHeight - margin; } } table_instruction.WriteSelectedRows(0, -1, 10, rowYInstruction, cb); #endregion #region RO Image var countImageRo = 0; byte[] roImage; foreach (var index in viewModel.ImagesFile) { countImageRo++; } 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; float rowYRoImage = rowYInstruction - table_instruction.TotalHeight - 5; 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"); } 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.WriteSelectedRows(0, -1, 10, rowYRoImage, cb); #endregion #region Signature (Bottom, Column 1.2) PdfPTable table_signature = new PdfPTable(6); table_signature.TotalWidth = 570f; float[] signature_widths = new float[] { 1f, 1f, 1f, 1f, 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("Dibuat", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Kasie Merchandiser", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("R & D", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Ka Produksi", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Mengetahui", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Menyetujui", 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); 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); cell_signature_noted.Phrase = new Phrase("(Haenis Gunarto)", normal_font); table_signature.AddCell(cell_signature_noted); cell_signature_noted.Phrase = new Phrase("(Michelle Tjokrosaputro)", normal_font); table_signature.AddCell(cell_signature_noted); float table_signatureY = rowYRoImage - table_ro_image.TotalHeight - 5; table_signature.WriteSelectedRows(0, -1, 10, table_signatureY, cb); #endregion this.DrawPrintedOn(now, bf, cb); document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
protected void Page_Load(object sender, EventArgs e) { if (this.Request["seedkey"] != null) { seedkey = this.Request["seedkey"].ToInt(); } if (this.Request["from"] != null) { FromDate = DateTime.ParseExact(this.Request["from"], "d/M/yyyy", CultureInfo.InvariantCulture); } if (this.Request["to"] != null) { ToDate = DateTime.ParseExact(this.Request["to"], "d/M/yyyy", CultureInfo.InvariantCulture); } int memberID = HttpContext.Current.Session["MemberID"].ToInt(); if (memberID != 0) { string NameSeed = ""; TNLibrary.Book.Member_Info minfo = new TNLibrary.Book.Member_Info(memberID); MemoryStream ms = new MemoryStream(); Document document = new Document(iTextSharp.text.PageSize.A4.Rotate(), 66, 36, 54, 54); PdfWriter writer = PdfWriter.GetInstance(document, ms); BaseFont bfTimes = BaseFont.CreateFont("c:\\windows\\fonts\\times.ttf", BaseFont.IDENTITY_H, false); Font fontHeader = new Font(bfTimes, 12, Font.BOLD); Font fontNormal = new Font(bfTimes, 11); Font fontozel = new Font(bfTimes, 12, Font.NORMAL); writer.PageEvent = new PDFFooter(); document.Open(); if (seedkey.ToInt() == 0) { Paragraph header = new Paragraph(@"BÁO CÁO CHI PHÍ TỔNG HỢP", new Font(bfTimes, 40, Font.BOLD)); header.Alignment = Element.ALIGN_CENTER; header.SpacingAfter = 20; document.Add(header); Paragraph Text3 = new Paragraph(@"Từ " + this.Request["from"] + " đến " + this.Request["to"], new Font(bfTimes, 25, Font.NORMAL)); Text3.Alignment = Element.ALIGN_CENTER; Text3.SpacingAfter = 150; document.Add(Text3); } else { Paragraph header = new Paragraph(@"BÁO CÁO CHI PHÍ", new Font(bfTimes, 40, Font.BOLD)); header.Alignment = Element.ALIGN_CENTER; header.SpacingAfter = 20; document.Add(header); Paragraph Text3 = new Paragraph(@"Từ " + this.Request["from"] + " đến " + this.Request["to"], new Font(bfTimes, 25, Font.NORMAL)); Text3.Alignment = Element.ALIGN_CENTER; Text3.SpacingAfter = 20; document.Add(Text3); Seed_Info sinfo = new Seed_Info(seedkey.ToInt()); Paragraph headerseed = new Paragraph(sinfo.SeedsName, new Font(bfTimes, 40, Font.BOLD)); headerseed.Alignment = Element.ALIGN_CENTER; headerseed.SpacingAfter = 90; document.Add(headerseed); } document.Add(new Paragraph(@"NÔNG HỘ: " + minfo.Name, new Font(bfTimes, 20, Font.BOLD))); document.Add(new Paragraph(@"MÃ SỐ: " + minfo.MemID, new Font(bfTimes, 20, Font.BOLD))); document.NewPage(); if (seedkey.ToInt() == 0) { NameSeed = "_Tatca"; if (1 == 1) { DataTable mTable = Report_Data.SumMoneyReport(memberID, seedkey, FromDate, ToDate); Paragraph headerTH = new Paragraph(@"Bảng tổng hợp thu chi", new Font(bfTimes, 30, Font.BOLD)); headerTH.Alignment = Element.ALIGN_CENTER; headerTH.SpacingAfter = 20; document.Add(headerTH); PdfPTable THTable = new PdfPTable(2); THTable.WidthPercentage = 100; THTable.SetWidths(new int[] { 50, 50 }); THTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng chi", fontHeader), 1)); THTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng thu", fontHeader), 1)); THTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", mTable.Compute("Sum(TotalBuy)", "").ToString() == "" ? "0" : mTable.Compute("Sum(TotalBuy)", "")), fontHeader), 1)); THTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", mTable.Compute("Sum(TotalSale)", "").ToString() == "" ? "0" : mTable.Compute("Sum(TotalSale)", "")), fontHeader), 1)); document.Add(THTable); document.Add(new Paragraph("Ghi chú: Tổng chi = Tổng chi giống + Tổng chi phân bón + Tổng chi Thuốc(hóa chất) ", new Font(bfTimes, 15, Font.NORMAL))); document.Add(new Paragraph("Tổng thu = Tổng thu hoạch xuất bán ", new Font(bfTimes, 15, Font.NORMAL))); document.NewPage(); Paragraph headerTP = new Paragraph(@"Thống kê theo thành phần", new Font(bfTimes, 30, Font.BOLD)); headerTP.Alignment = Element.ALIGN_CENTER; headerTP.SpacingAfter = 20; document.Add(headerTP); document.Add(new Paragraph("1. Thống kê theo giống ", new Font(bfTimes, 13, Font.BOLD))); PdfPTable SeedTable = new PdfPTable(2); SeedTable.SpacingBefore = 10; SeedTable.WidthPercentage = 100; SeedTable.SetWidths(new int[] { 50, 50 }); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tên giống", fontHeader), 1)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng chi", fontHeader), 1)); double TotalSeedProcess = 0; for (int i = 0; i < mTable.Rows.Count; i++) { if (mTable.Rows[i]["Type"].ToString() == "Mua giống") { SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(mTable.Rows[i]["Name"].ToString(), fontozel), 0)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", mTable.Rows[i]["TotalBuy"]), fontozel), 2)); TotalSeedProcess += String.Format("{0:#,0}", mTable.Rows[i]["TotalBuy"]).ToDouble(); } } SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng chi giống : ", fontHeader), 2)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", TotalSeedProcess), fontozel), 2)); document.Add(SeedTable); SeedTable.DeleteBodyRows(); document.Add(new Paragraph("2. Thống kê theo phần bón ", new Font(bfTimes, 13, Font.BOLD))); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tên phân bón", fontHeader), 1)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng chi", fontHeader), 1)); double TotalFertilizers = 0; for (int i = 0; i < mTable.Rows.Count; i++) { if (mTable.Rows[i]["Type"].ToString() == "Mua phân bón") { SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(mTable.Rows[i]["Name"].ToString(), fontozel), 0)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", mTable.Rows[i]["TotalBuy"]), fontozel), 2)); TotalFertilizers += String.Format("{0:#,0}", mTable.Rows[i]["TotalBuy"]).ToDouble(); } } SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng chi phân bón : ", fontHeader), 2)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", TotalFertilizers), fontozel), 2)); document.Add(SeedTable); SeedTable.DeleteBodyRows(); document.Add(new Paragraph("3. Thống kê theo Thuốc(hóa chất) ", new Font(bfTimes, 13, Font.BOLD))); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tên thuốc", fontHeader), 1)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng chi", fontHeader), 1)); double TotalPesticides = 0; for (int i = 0; i < mTable.Rows.Count; i++) { if (mTable.Rows[i]["Type"].ToString() == "Mua thuốc BVTV") { SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(mTable.Rows[i]["Name"].ToString(), fontozel), 0)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", mTable.Rows[i]["TotalBuy"]), fontozel), 2)); TotalPesticides += String.Format("{0:#,0}", mTable.Rows[i]["TotalBuy"]).ToDouble(); } } SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng chi Thuốc(hóa chất) : ", fontHeader), 2)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", TotalPesticides), fontozel), 2)); document.Add(SeedTable); SeedTable.DeleteBodyRows(); document.Add(new Paragraph("4. Thống kê theo thu hoạch xuất bán ", new Font(bfTimes, 13, Font.BOLD))); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tên giống", fontHeader), 1)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng thu", fontHeader), 1)); double TotalHarvestedForSale = 0; for (int i = 0; i < mTable.Rows.Count; i++) { if (mTable.Rows[i]["Type"].ToString() == "Thu hoạch xuất bán") { SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(mTable.Rows[i]["Name"].ToString(), fontozel), 0)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", mTable.Rows[i]["TotalSale"]), fontozel), 2)); TotalHarvestedForSale += String.Format("{0:#,0}", mTable.Rows[i]["TotalSale"]).ToDouble(); } } SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng thu hoạch xuất bán : ", fontHeader), 2)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", TotalHarvestedForSale), fontozel), 2)); document.Add(SeedTable); SeedTable.DeleteBodyRows(); document.NewPage(); DataTable nTable = Report_Data.MoneyReport(memberID, seedkey, FromDate, ToDate); if (nTable != null) { Paragraph headerDate = new Paragraph(@"Bảng tổng hợp thu chi theo ngày", new Font(bfTimes, 30, Font.BOLD)); headerDate.Alignment = Element.ALIGN_CENTER; headerDate.SpacingAfter = 20; document.Add(headerDate); PdfPTable mainTable = new PdfPTable(8); mainTable.WidthPercentage = 100; mainTable.SetWidths(new int[] { 5, 10, 20, 20, 10, 10, 10, 15 }); double TotalSale = 0, TotalBuy = 0; mainTable.AddCell(GetCellForBorderlessTable(new Phrase("STT", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("Ngày", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("Loại thu chi", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("Tên Hàng", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("Số lượng", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng Chi", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng Thu", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("Cung Cấp", fontHeader), 1)); for (int i = 0; i < nTable.Rows.Count; i++) { mainTable.AddCell(GetCellForBorderlessTable(new Phrase((i + 1).ToString(), fontozel), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase(Utils.DateTostring((DateTime)nTable.Rows[i]["DateTime"]), fontozel), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase(nTable.Rows[i]["Type"].ToString(), fontozel), 0)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase(nTable.Rows[i]["Name"].ToString(), fontozel), 0)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase(nTable.Rows[i]["Quantity"].ToString() + " " + nTable.Rows[i]["Unit"].ToString(), fontozel), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", nTable.Rows[i]["TotalBuy"]), fontozel), 2)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", nTable.Rows[i]["TotalSale"]), fontozel), 2)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase(nTable.Rows[i]["Address"].ToString(), fontozel), 0)); TotalSale += nTable.Rows[i]["TotalSale"].ToDouble(); TotalBuy += nTable.Rows[i]["TotalBuy"].ToDouble(); } mainTable.AddCell(GetCellForBorderlessTable(new Phrase("", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", TotalBuy), fontHeader), 2)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", TotalSale), fontHeader), 2)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("", fontHeader), 1)); document.Add(mainTable); } } } else { Seed_Info sinfo = new Seed_Info(seedkey.ToInt()); NameSeed = "_" + sinfo.SeedsName; if (1 == 1) { DataTable mTable = Report_Data.SumMoneyReport(memberID, seedkey, FromDate, ToDate); Paragraph headerTH = new Paragraph(@"Bảng tổng hợp thu chi", new Font(bfTimes, 30, Font.BOLD)); headerTH.Alignment = Element.ALIGN_CENTER; headerTH.SpacingAfter = 20; document.Add(headerTH); PdfPTable THTable = new PdfPTable(2); THTable.WidthPercentage = 100; THTable.SetWidths(new int[] { 50, 50 }); THTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng chi", fontHeader), 1)); THTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng thu", fontHeader), 1)); THTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", mTable.Compute("Sum(TotalBuy)", "").ToString() == "" ? "0" : mTable.Compute("Sum(TotalBuy)", "")), fontHeader), 1)); THTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", mTable.Compute("Sum(TotalSale)", "").ToString() == "" ? "0" : mTable.Compute("Sum(TotalSale)", "")), fontHeader), 1)); document.Add(THTable); document.Add(new Paragraph("Ghi chú: Tổng chi = Tổng chi giống + Tổng chi phân bón + Tổng chi Thuốc(hóa chất) ", new Font(bfTimes, 15, Font.NORMAL))); document.Add(new Paragraph("Tổng thu = Tổng thu hoạch xuất bán ", new Font(bfTimes, 15, Font.NORMAL))); document.NewPage(); document.Add(new Paragraph("Thống kê theo thành phần ", new Font(bfTimes, 15, Font.BOLD))); document.Add(new Paragraph("1. Thống kê theo giống ", new Font(bfTimes, 13, Font.BOLD))); PdfPTable SeedTable = new PdfPTable(2); SeedTable.SpacingBefore = 10; SeedTable.WidthPercentage = 100; SeedTable.SetWidths(new int[] { 50, 50 }); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tên giống", fontHeader), 1)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng chi", fontHeader), 1)); double TotalSeedProcess = 0; for (int i = 0; i < mTable.Rows.Count; i++) { if (mTable.Rows[i]["Type"].ToString() == "Mua giống") { SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(mTable.Rows[i]["Name"].ToString(), fontozel), 0)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", mTable.Rows[i]["TotalBuy"]), fontozel), 2)); TotalSeedProcess += String.Format("{0:#,0}", mTable.Rows[i]["TotalBuy"]).ToDouble(); } } SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng chi giống : ", fontHeader), 2)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", TotalSeedProcess), fontozel), 2)); document.Add(SeedTable); SeedTable.DeleteBodyRows(); document.Add(new Paragraph("2. Thống kê theo phần bón ", new Font(bfTimes, 13, Font.BOLD))); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tên phân bón", fontHeader), 1)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng chi", fontHeader), 1)); double TotalFertilizers = 0; for (int i = 0; i < mTable.Rows.Count; i++) { if (mTable.Rows[i]["Type"].ToString() == "Mua phân bón") { SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(mTable.Rows[i]["Name"].ToString(), fontozel), 0)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", mTable.Rows[i]["TotalBuy"]), fontozel), 2)); TotalFertilizers += String.Format("{0:#,0}", mTable.Rows[i]["TotalBuy"]).ToDouble(); } } SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng chi phân bón : ", fontHeader), 2)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", TotalFertilizers), fontozel), 2)); document.Add(SeedTable); SeedTable.DeleteBodyRows(); document.Add(new Paragraph("3. Thống kê theo Thuốc(hóa chất) ", new Font(bfTimes, 13, Font.BOLD))); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tên thuốc", fontHeader), 1)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng chi", fontHeader), 1)); double TotalPesticides = 0; for (int i = 0; i < mTable.Rows.Count; i++) { if (mTable.Rows[i]["Type"].ToString() == "Mua thuốc BVTV") { SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(mTable.Rows[i]["Name"].ToString(), fontozel), 0)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", mTable.Rows[i]["TotalBuy"]), fontozel), 2)); TotalPesticides += String.Format("{0:#,0}", mTable.Rows[i]["TotalBuy"]).ToDouble(); } } SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng chi Thuốc(hóa chất) : ", fontHeader), 2)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", TotalPesticides), fontozel), 2)); document.Add(SeedTable); SeedTable.DeleteBodyRows(); document.Add(new Paragraph("4. Thống kê theo thu hoạch xuất bán ", new Font(bfTimes, 13, Font.BOLD))); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tên giống", fontHeader), 1)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng thu", fontHeader), 1)); double TotalHarvestedForSale = 0; for (int i = 0; i < mTable.Rows.Count; i++) { if (mTable.Rows[i]["Type"].ToString() == "Thu hoạch xuất bán") { SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(mTable.Rows[i]["Name"].ToString(), fontozel), 0)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", mTable.Rows[i]["TotalSale"]), fontozel), 2)); TotalHarvestedForSale += String.Format("{0:#,0}", mTable.Rows[i]["TotalSale"]).ToDouble(); } } SeedTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng thu hoạch xuất bán : ", fontHeader), 2)); SeedTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", TotalHarvestedForSale), fontozel), 2)); document.Add(SeedTable); SeedTable.DeleteBodyRows(); document.NewPage(); DataTable nTable = Report_Data.MoneyReport(memberID, seedkey, FromDate, ToDate); if (nTable != null) { Paragraph headerDate = new Paragraph(@"Bảng tổng hợp thu chi theo ngày", new Font(bfTimes, 30, Font.BOLD)); headerDate.Alignment = Element.ALIGN_CENTER; headerDate.SpacingAfter = 20; document.Add(headerDate); PdfPTable mainTable = new PdfPTable(8); mainTable.WidthPercentage = 100; mainTable.SetWidths(new int[] { 5, 10, 20, 20, 10, 10, 10, 15 }); double TotalSale = 0, TotalBuy = 0; mainTable.AddCell(GetCellForBorderlessTable(new Phrase("STT", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("Ngày", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("Loại thu chi", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("Tên Hàng", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("Số lượng", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng Chi", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng Thu", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("Cung Cấp", fontHeader), 1)); for (int i = 0; i < nTable.Rows.Count; i++) { mainTable.AddCell(GetCellForBorderlessTable(new Phrase((i + 1).ToString(), fontozel), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase(Utils.DateTostring((DateTime)nTable.Rows[i]["DateTime"]), fontozel), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase(nTable.Rows[i]["Type"].ToString(), fontozel), 0)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase(nTable.Rows[i]["Name"].ToString(), fontozel), 0)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase(nTable.Rows[i]["Quantity"].ToString() + " " + nTable.Rows[i]["Unit"].ToString(), fontozel), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", nTable.Rows[i]["TotalBuy"]), fontozel), 2)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", nTable.Rows[i]["TotalSale"]), fontozel), 2)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase(nTable.Rows[i]["Address"].ToString(), fontozel), 0)); TotalSale += nTable.Rows[i]["TotalSale"].ToDouble(); TotalBuy += nTable.Rows[i]["TotalBuy"].ToDouble(); } mainTable.AddCell(GetCellForBorderlessTable(new Phrase("", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("Tổng", fontHeader), 1)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", TotalBuy), fontHeader), 2)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase(String.Format("{0:#,0}", TotalSale), fontHeader), 2)); mainTable.AddCell(GetCellForBorderlessTable(new Phrase("", fontHeader), 1)); document.Add(mainTable); } } } document.Close(); writer.Close(); Response.ContentType = "application/pdf;"; Response.AddHeader("Content-Disposition", "attachment; filename=BaoCaoChiPhi_" + TNLibrary.Book.Utils.RemoveUnicode(minfo.Name.Replace(" ", "")) + TNLibrary.Book.Utils.RemoveUnicode(NameSeed.Replace(" ", "")) + "_" + DateTime.Now.ToString("dd.MM.yyyy_HH.mm") + ".pdf"); byte[] pdf = ms.ToArray(); Response.OutputStream.Write(pdf, 0, pdf.Length); } }
public MemoryStream GeneratePdfTemplate(CostCalculationGarmentViewModel viewModel, int timeoffset) { BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED); BaseFont bf_bold = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED); 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); DateTime now = DateTime.Now; Document document = new Document(PageSize.A4, 10, 10, 10, 10); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); writer.CloseStream = false; document.Open(); PdfContentByte cb = writer.DirectContent; float margin = 10; float printedOnHeight = 10; float startY = 840 - margin; PdfPCell cell_colon = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Phrase = new Phrase(":", normal_font) }; #region Header cb.BeginText(); cb.SetFontAndSize(bf, 10); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "PT. DAN LIRIS", 10, 820, 0); cb.SetFontAndSize(bf_bold, 12); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "BUDGET EXPORT GARMENT", 10, 805, 0); cb.EndText(); #endregion #region Detail 1 (Top) PdfPTable table_detail1 = new PdfPTable(9); table_detail1.TotalWidth = 570f; float[] detail1_widths = new float[] { 1f, 0.1f, 2f, 1f, 0.1f, 2f, 1.5f, 0.1f, 2f }; table_detail1.SetWidths(detail1_widths); PdfPCell cell_detail1 = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 1, PaddingBottom = 2, PaddingTop = 2 }; cell_detail1.Phrase = new Phrase("RO", normal_font); table_detail1.AddCell(cell_detail1); table_detail1.AddCell(cell_colon); cell_detail1.Phrase = new Phrase($"{viewModel.RO_Number}", normal_font); table_detail1.AddCell(cell_detail1); cell_detail1.Phrase = new Phrase("SECTION", normal_font); table_detail1.AddCell(cell_detail1); table_detail1.AddCell(cell_colon); cell_detail1.Phrase = new Phrase($"{viewModel.Section}", normal_font); table_detail1.AddCell(cell_detail1); cell_detail1.Phrase = new Phrase("CONFIRM ORDER", normal_font); table_detail1.AddCell(cell_detail1); table_detail1.AddCell(cell_colon); cell_detail1.Phrase = new Phrase($"{viewModel.ConfirmDate.AddHours(timeoffset).ToString("dd/MM/yyyy")}", normal_font); table_detail1.AddCell(cell_detail1); #endregion #region Draw Detail 1 float row1Y = 800; table_detail1.WriteSelectedRows(0, -1, 10, row1Y, cb); #endregion bool isDollar = viewModel.Rate.Id != 0; #region Detail 2 (Bottom, Column 1) PdfPTable table_detail2 = new PdfPTable(2); table_detail2.TotalWidth = 230f; float[] detail2_widths = new float[] { 2f, 5f }; table_detail2.SetWidths(detail2_widths); PdfPCell cell_detail2 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7 }; cell_detail2.Phrase = new Phrase("BUYER", normal_font); table_detail2.AddCell(cell_detail2); cell_detail2.Phrase = new Phrase($"{viewModel.Buyer.name}", normal_font); table_detail2.AddCell(cell_detail2); cell_detail2.Phrase = new Phrase("ARTICLE", normal_font); table_detail2.AddCell(cell_detail2); cell_detail2.Phrase = new Phrase($"{viewModel.Article}", normal_font); table_detail2.AddCell(cell_detail2); cell_detail2.Phrase = new Phrase("DESCRIPTION", normal_font); table_detail2.AddCell(cell_detail2); cell_detail2.Phrase = new Phrase($"{viewModel.CommodityDescription}", normal_font); table_detail2.AddCell(cell_detail2); cell_detail2.Phrase = new Phrase("QTY", normal_font); table_detail2.AddCell(cell_detail2); cell_detail2.Phrase = new Phrase($"{viewModel.Quantity} PCS", normal_font); table_detail2.AddCell(cell_detail2); cell_detail2.Phrase = new Phrase("DELIVERY", normal_font); table_detail2.AddCell(cell_detail2); cell_detail2.Phrase = new Phrase($"{viewModel.DeliveryDate.AddHours(timeoffset).ToString("dd/MM/yyyy")}", normal_font); table_detail2.AddCell(cell_detail2); #endregion #region Detail 3 (Bottom, Column 2) PdfPTable table_detail3 = new PdfPTable(8); table_detail3.TotalWidth = 330f; float[] detail3_widths = new float[] { 3.25f, 4.75f, 1.9f, 0.2f, 1.9f, 1.9f, 0.2f, 1.9f }; table_detail3.SetWidths(detail3_widths); double budgetCost = isDollar ? viewModel.ConfirmPrice * viewModel.Rate.Value ?? 0 : viewModel.ConfirmPrice ?? 0; double totalBudget = budgetCost * viewModel.Quantity ?? 0; PdfPCell cell_detail3 = new PdfPCell() { HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7 }; PdfPCell cell_detail3_right = new PdfPCell() { HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7 }; PdfPCell cell_detail3_colspan6 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7, Colspan = 6 }; PdfPCell cell_detail3_colspan8 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7, Colspan = 8 }; cell_detail3.Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER; cell_detail3.Phrase = new Phrase("TOTAL BUDGET", normal_font); table_detail3.AddCell(cell_detail3); cell_detail3.Border = Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER; cell_detail3.Phrase = new Phrase($"{Number.ToRupiah(totalBudget)}", normal_font); table_detail3.AddCell(cell_detail3); cell_detail3_colspan6.Phrase = new Phrase("STANDARD HOURS", normal_font); table_detail3.AddCell(cell_detail3_colspan6); double freightCost = 0; foreach (CostCalculationGarment_MaterialViewModel item in viewModel.CostCalculationGarment_Materials) { freightCost += item.TotalShippingFee; } cell_detail3.Border = Rectangle.LEFT_BORDER; cell_detail3.Phrase = new Phrase("BEA ANGKUT", normal_font); table_detail3.AddCell(cell_detail3); cell_detail3.Border = Rectangle.RIGHT_BORDER; cell_detail3.Phrase = new Phrase($"{Number.ToRupiah(freightCost)}", normal_font); table_detail3.AddCell(cell_detail3); cell_detail3.Border = Rectangle.LEFT_BORDER; cell_detail3.Phrase = new Phrase("SMV. CUT", normal_font); table_detail3.AddCell(cell_detail3); table_detail3.AddCell(cell_colon); cell_detail3.Border = Rectangle.NO_BORDER; cell_detail3.Phrase = new Phrase($"{viewModel.SMV_Cutting}", normal_font); table_detail3.AddCell(cell_detail3); cell_detail3.Border = Rectangle.NO_BORDER; cell_detail3.Phrase = new Phrase("SMV. SEW", normal_font); table_detail3.AddCell(cell_detail3); table_detail3.AddCell(cell_colon); cell_detail3.Border = Rectangle.RIGHT_BORDER; cell_detail3.Phrase = new Phrase($"{viewModel.SMV_Sewing}", normal_font); table_detail3.AddCell(cell_detail3); cell_detail3.Border = Rectangle.BOTTOM_BORDER | Rectangle.LEFT_BORDER; cell_detail3.Phrase = new Phrase("", normal_font); table_detail3.AddCell(cell_detail3); cell_detail3.Border = Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER; cell_detail3.Phrase = new Phrase("", normal_font); table_detail3.AddCell(cell_detail3); cell_detail3.Border = Rectangle.BOTTOM_BORDER | Rectangle.LEFT_BORDER; cell_detail3.Phrase = new Phrase("SMV. FIN", normal_font); table_detail3.AddCell(cell_detail3); table_detail3.AddCell(cell_colon); cell_detail3.Border = Rectangle.BOTTOM_BORDER; cell_detail3.Phrase = new Phrase($"{viewModel.SMV_Finishing}", normal_font); table_detail3.AddCell(cell_detail3); cell_detail3.Border = Rectangle.BOTTOM_BORDER; cell_detail3.Phrase = new Phrase("SMV. TOT", normal_font); table_detail3.AddCell(cell_detail3); table_detail3.AddCell(cell_colon); cell_detail3.Border = Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER; cell_detail3.Phrase = new Phrase($"{viewModel.SMV_Total}", normal_font); table_detail3.AddCell(cell_detail3); cell_detail3_colspan8.Phrase = new Phrase("BUDGET COST / PCS" + "".PadRight(5) + $"{Number.ToRupiah(budgetCost)}", normal_font); table_detail3.AddCell(cell_detail3_colspan8); cell_detail3_colspan8.Phrase = isDollar ? new Phrase($"US$ 1 = {Number.ToRupiah(viewModel.Rate.Value)}" + "".PadRight(10) + $"CONFIRM PRICE : {Number.ToDollar(viewModel.ConfirmPrice)} / PCS", normal_font) : new Phrase($"CONFIRM PRICE : {Number.ToRupiah(viewModel.ConfirmPrice)} / PCS", normal_font); table_detail3.AddCell(cell_detail3_colspan8); cell_detail3_colspan8.Border = Rectangle.NO_BORDER; cell_detail3_colspan8.HorizontalAlignment = Element.ALIGN_CENTER; cell_detail3_colspan8.Phrase = new Phrase($"ALLOWANCE >> FABRIC = {viewModel.FabricAllowance}%, ACC = {viewModel.AccessoriesAllowance}%", normal_font); table_detail3.AddCell(cell_detail3_colspan8); #endregion #region Signature PdfPTable table_signature = new PdfPTable(5); table_signature.TotalWidth = 570f; float[] signature_widths = new float[] { 1f, 1f, 1f, 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 }; cell_signature.Phrase = new Phrase("", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("", normal_font); table_signature.AddCell(cell_signature); string signatureArea = string.Empty; for (int i = 0; i < 5; i++) { signatureArea += Environment.NewLine; } cell_signature.Phrase = new Phrase(signatureArea, normal_font); table_signature.AddCell(cell_signature); table_signature.AddCell(cell_signature); table_signature.AddCell(cell_signature); table_signature.AddCell(cell_signature); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("(................)", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("(................)", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("(................)", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("(................)", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("(................)", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Penjualan", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Ka. Sie/Ka. Bag Penjualan", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Ka. Bag Pembelian", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Ka. Div Produksi Garment", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Ka. Div Penjualan", normal_font); table_signature.AddCell(cell_signature); #endregion #region Cost Calculation Material PdfPTable table_ccm = new PdfPTable(10); table_ccm.TotalWidth = 570f; float[] ccm_widths = new float[] { 1f, 3f, 3f, 6f, 2f, 3f, 3f, 2f, 3f, 3f }; table_ccm.SetWidths(ccm_widths); PdfPCell cell_ccm = 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 }; cell_ccm.Phrase = new Phrase("NO", bold_font); table_ccm.AddCell(cell_ccm); cell_ccm.Phrase = new Phrase("CATEGORIES", bold_font); table_ccm.AddCell(cell_ccm); cell_ccm.Phrase = new Phrase("KODE PRODUK", bold_font); table_ccm.AddCell(cell_ccm); cell_ccm.Phrase = new Phrase("DESCRIPTION", bold_font); table_ccm.AddCell(cell_ccm); cell_ccm.Phrase = new Phrase("USAGE", bold_font); table_ccm.AddCell(cell_ccm); cell_ccm.Phrase = new Phrase("PRICE", bold_font); table_ccm.AddCell(cell_ccm); cell_ccm.Phrase = new Phrase("QUANTITY", bold_font); table_ccm.AddCell(cell_ccm); cell_ccm.Phrase = new Phrase("UNIT", bold_font); table_ccm.AddCell(cell_ccm); cell_ccm.Phrase = new Phrase("AMOUNT", bold_font); table_ccm.AddCell(cell_ccm); cell_ccm.Phrase = new Phrase("PO NUMBER", bold_font); table_ccm.AddCell(cell_ccm); float row2Y = row1Y - table_detail1.TotalHeight - 10; float row3Height = table_detail2.TotalHeight > table_detail3.TotalHeight ? table_detail2.TotalHeight : table_detail3.TotalHeight; float row2RemainingHeight = row2Y - 10 - row3Height - printedOnHeight - margin; float row2AllowedHeight = row2Y - printedOnHeight - margin; for (int i = 0; i < viewModel.CostCalculationGarment_Materials.Count; i++) { //NO cell_ccm.Phrase = new Phrase((i + 1).ToString(), normal_font); table_ccm.AddCell(cell_ccm); cell_ccm.HorizontalAlignment = Element.ALIGN_LEFT; //CATEGORY cell_ccm.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].Category.name, normal_font); table_ccm.AddCell(cell_ccm); //KODE PRODUK cell_ccm.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].Product.code, normal_font); table_ccm.AddCell(cell_ccm); //DESCRIPTION cell_ccm.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].Description, normal_font); table_ccm.AddCell(cell_ccm); cell_ccm.HorizontalAlignment = Element.ALIGN_RIGHT; double usage = viewModel.CostCalculationGarment_Materials[i].Quantity ?? 0; cell_ccm.Phrase = new Phrase(usage.ToString(), normal_font); table_ccm.AddCell(cell_ccm); double price = viewModel.CostCalculationGarment_Materials[i].Price ?? 0; cell_ccm.Phrase = new Phrase(String.Format("{0}/{1}", Number.ToRupiahWithoutSymbol(price), viewModel.CostCalculationGarment_Materials[i].UOMPrice.unit), normal_font); table_ccm.AddCell(cell_ccm); double factor; if (viewModel.CostCalculationGarment_Materials[i].Category.name == "FABRIC") { factor = viewModel.FabricAllowance ?? 0; } else { factor = viewModel.AccessoriesAllowance ?? 0; } double totalQuantity = viewModel.Quantity ?? 0; double quantity = (100 + factor) / 100 * usage * totalQuantity; cell_ccm.Phrase = new Phrase(quantity.ToString(), normal_font); table_ccm.AddCell(cell_ccm); cell_ccm.HorizontalAlignment = Element.ALIGN_CENTER; cell_ccm.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].UOMQuantity.unit, normal_font); table_ccm.AddCell(cell_ccm); cell_ccm.HorizontalAlignment = Element.ALIGN_RIGHT; double amount = quantity * price; cell_ccm.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(amount), normal_font); table_ccm.AddCell(cell_ccm); cell_ccm.HorizontalAlignment = Element.ALIGN_CENTER; cell_ccm.Phrase = new Phrase(viewModel.CostCalculationGarment_Materials[i].PO_SerialNumber, normal_font); table_ccm.AddCell(cell_ccm); float currentHeight = table_ccm.TotalHeight; if (currentHeight / row2RemainingHeight > 1) { if (currentHeight / row2AllowedHeight > 1) { PdfPRow headerRow = table_ccm.GetRow(0); PdfPRow lastRow = table_ccm.GetRow(table_ccm.Rows.Count - 1); table_ccm.DeleteLastRow(); table_ccm.WriteSelectedRows(0, -1, 10, row2Y, cb); table_ccm.DeleteBodyRows(); this.DrawPrintedOn(now, bf, cb); document.NewPage(); table_ccm.Rows.Add(headerRow); table_ccm.Rows.Add(lastRow); table_ccm.CalculateHeights(); row2Y = startY; row2RemainingHeight = row2Y - 10 - row3Height - printedOnHeight - margin; row2AllowedHeight = row2Y - printedOnHeight - margin; } } } #endregion #region Draw Others table_ccm.WriteSelectedRows(0, -1, 10, row2Y, cb); float row3Y = row2Y - table_ccm.TotalHeight - 10; float row3RemainigHeight = row3Y - printedOnHeight - margin; if (row3RemainigHeight < row3Height) { this.DrawPrintedOn(now, bf, cb); row3Y = startY; document.NewPage(); } table_detail2.WriteSelectedRows(0, -1, margin, row3Y, cb); table_detail3.WriteSelectedRows(0, -1, margin + table_detail2.TotalWidth + 10, row3Y, cb); float signatureY = row3Y - row3Height - 10; float signatureRemainingHeight = signatureY - printedOnHeight - margin; if (signatureRemainingHeight < table_signature.TotalHeight) { this.DrawPrintedOn(now, bf, cb); signatureY = startY; document.NewPage(); } table_signature.WriteSelectedRows(0, -1, margin, signatureY, cb); this.DrawPrintedOn(now, bf, cb); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
private void PrintReportDetail() { int row = 1; int page = 1; PdfPTable table = new PdfPTable(8); foreach (TransferItemVO vo in _mdseTransfer) { if (row / page >= 30 || row == 1) { //Not the first page so have it go to a new page. if (row != 1) { _document.Add(table); table.DeleteBodyRows(); _document.NewPage(); table = new PdfPTable(8); page++; } //ADD HEADER FOR EACH TABLE PdfPCell cell; cell = new PdfPCell(new Paragraph("Number", _reportFont)); //cell.Border = Rectangle.NO_BORDER; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); if (_catcoTransferType == "Scrap") { cell = new PdfPCell(new Paragraph("ICN", _reportFont)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_TOP; cell.Colspan = 1; table.AddCell(cell); cell = new PdfPCell(new Paragraph("Merchandise Description", _reportFont)); //cell.Border = Rectangle.NO_BORDER; cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_TOP; cell.Colspan = 3; table.AddCell(cell); } else if (_catcoTransferType == "Refurb") { cell = new PdfPCell(new Paragraph("Refurb #", _reportFont)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); cell = new PdfPCell(new Paragraph("ICN", _reportFont)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_TOP; cell.Colspan = 1; table.AddCell(cell); cell = new PdfPCell(new Paragraph("Merchandise Description", _reportFont)); //cell.Border = Rectangle.NO_BORDER; cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_TOP; cell.Colspan = 3; table.AddCell(cell); } else { cell = new PdfPCell(new Paragraph("ICN", _reportFont)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_TOP; cell.Colspan = 2; table.AddCell(cell); cell = new PdfPCell(new Paragraph("Merchandise Description", _reportFont)); //cell.Border = Rectangle.NO_BORDER; cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_TOP; cell.Colspan = 2; table.AddCell(cell); } //cell.Border = Rectangle.NO_BORDER; if (_catcoTransferType != "Refurb") { cell = new PdfPCell(new Paragraph("Quantity", _reportFont)); //cell.Border = Rectangle.NO_BORDER; cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); } cell = new PdfPCell(new Paragraph("Cost", _reportFont)); //cell.Border = Rectangle.NO_BORDER; cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); cell = new PdfPCell(new Paragraph("Total Cost", _reportFont)); //cell.Border = Rectangle.NO_BORDER; cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); } PrintDetailRow(vo, table, row); row++; } //Add the last table to the document. _document.Add(table); }
public bool Print() { ReportTitle = RptObject.ReportTitle; if (RptObject.ReportParms != null && RptObject.ReportParms.Count > 0) { if (RptObject.ReportParms[0].ToString() == "Open" || RptObject.ReportParms[0].ToString() == "Closed") { FillUpPages = true; } } rptLargeFont = FontFactory.GetFont("Microsoft Sans Serif", 10, iTextSharp.text.Font.BOLD); try { document = new Document(PageSize.LEGAL.Rotate()); //Set Font for the report rptFont = rptFont = FontFactory.GetFont("Microsoft Sans Serif", 6, iTextSharp.text.Font.NORMAL); string rptFileName = RptObject.ReportTempFileFullName; if (!string.IsNullOrEmpty(rptFileName)) { document.AddTitle(RptObject.ReportTitle); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(rptFileName, FileMode.Create)); PdfPTable table = new PdfPTable(31); document.SetPageSize(PageSize.LEGAL.Rotate()); document.SetMargins(-100, -100, 10, 50); GunBookEvents eventdata = new GunBookEvents(); writer.PageEvent = eventdata; eventdata.PageNumber = new List <int>(); table.TotalWidth = 1500f; //Insert the report header InsertReportHeader(table); //Create Column headers InsertColumnHeaders(table); //Set number of header rows table.HeaderRows = 6; //Insert report data document.Open(); bool firstRow = true; foreach (DataRow dr in GunBookData.Rows) { gunPageNumber = Utilities.GetIntegerValue(Utilities.GetStringValue(dr["GUN_PAGE"], "")); if (!FillUpPages) { if (firstRow) { eventdata.PageNumber.Add(gunPageNumber); pageNum = gunPageNumber; firstRow = false; } else { if (gunPageNumber != pageNum) { eventdata.PageNumber.Add(gunPageNumber); document.Add(table); table.DeleteBodyRows(); document.NewPage(); pageNum = gunPageNumber; } } } PdfPCell pCell = new PdfPCell(); pCell.Colspan = 1; pCell.HorizontalAlignment = Element.ALIGN_JUSTIFIED; pCell.Border = Rectangle.BOX; pCell.Phrase = new Phrase(Utilities.GetStringValue(dr["GUN_NUMBER"]), rptFont); table.AddCell(pCell); //----- string manufr = Utilities.GetStringValue(dr["MANUFACTURER"]); string importr = Utilities.GetStringValue(dr["IMPORTER"]); PdfPTable man_import = new PdfPTable(1); if (!string.IsNullOrEmpty(manufr)) { man_import.AddCell(new Phrase(manufr, rptFont)); } if (!string.IsNullOrEmpty(importr)) { man_import.AddCell(new Phrase(importr, rptFont)); } PdfPCell pcell0 = new PdfPCell(man_import); pcell0.Colspan = 2; table.AddCell(pcell0); //---- pCell.Phrase = new Phrase(Utilities.GetStringValue(dr["MODEL"]), rptFont); pCell.Colspan = 2; pCell.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(pCell); pCell.Phrase = new Phrase(Utilities.GetStringValue(dr["SERIAL_NUMBER"]), rptFont); pCell.NoWrap = false; pCell.Colspan = 2; table.AddCell(pCell); pCell.Phrase = new Phrase(Utilities.GetStringValue(dr["CALIBER"]), rptFont); pCell.Colspan = 2; table.AddCell(pCell); pCell.Phrase = new Phrase(Utilities.GetStringValue(dr["GUN_TYPE"]), rptFont); pCell.HorizontalAlignment = Element.ALIGN_LEFT; pCell.Colspan = 2; table.AddCell(pCell); //Acquire data string transType = Utilities.GetStringValue(dr["ACQUIRE_TRANSACTION_TYPE"], ""); string transNumber = Utilities.GetStringValue(dr["ACQUIRE_DOCUMENT_NUMBER"], ""); pCell.Phrase = new Phrase(transType + " " + transNumber, rptFont); pCell.NoWrap = true; pCell.Colspan = 2; table.AddCell(pCell); string tmpAcqDate = Utilities.GetStringValue(dr["ACQUIRE_DATE"], ""); if (string.IsNullOrEmpty(tmpAcqDate)) { tmpAcqDate = ""; } else { tmpAcqDate = Utilities.GetDateTimeValue(tmpAcqDate).ToShortDateString(); } pCell.Phrase = new Phrase(tmpAcqDate, rptFont); pCell.Colspan = 2; table.AddCell(pCell); string acqFirstName = Utilities.GetStringValue(dr["ACQUIRE_FIRST_NAME"], ""); string acqLastName = Utilities.GetStringValue(dr["ACQUIRE_LAST_NAME"], ""); string acqIdType = Utilities.GetStringValue(dr["ACQUIRE_ID_TYPE"], ""); string acqIdNumber = Utilities.GetStringValue(dr["ACQUIRE_ID_NUMBER"], ""); string acqIdAgency = Utilities.GetStringValue(dr["ACQUIRE_ID_AGENCY"], ""); PdfPTable nameID = new PdfPTable(1); if (!string.IsNullOrEmpty(acqFirstName) || !string.IsNullOrEmpty(acqLastName)) { nameID.AddCell(new Phrase(acqFirstName + " " + Utilities.GetStringValue(dr["ACQUIRE_MIDDLE_INITIAL"], "") + " " + acqLastName, rptFont)); } if (!string.IsNullOrEmpty(acqIdType) || !string.IsNullOrEmpty(acqIdNumber)) { nameID.AddCell(new Phrase(acqIdType + " " + acqIdAgency + acqIdNumber, rptFont)); } PdfPCell pcell1 = new PdfPCell(nameID); pcell1.Colspan = 3; table.AddCell(pcell1); string acqAddress = Utilities.GetStringValue(dr["ACQUIRE_ADDRESS"], ""); string acqCity = Utilities.GetStringValue(dr["ACQUIRE_CITY"], ""); string acqState = Utilities.GetStringValue(dr["ACQUIRE_STATE"], ""); string acqPostalCode = Utilities.GetStringValue(dr["ACQUIRE_POSTAL_CODE"], ""); PdfPTable address = new PdfPTable(1); if (!string.IsNullOrEmpty(acqAddress)) { address.AddCell(new Phrase(acqAddress, rptFont)); } if (!string.IsNullOrEmpty(acqCity) || !string.IsNullOrEmpty(acqState) || !string.IsNullOrEmpty(acqPostalCode)) { address.AddCell(new Phrase(acqCity + " " + acqState + " " + acqPostalCode, rptFont)); } PdfPCell pcell = new PdfPCell(address); pcell.Colspan = 3; table.AddCell(pcell); //Disposition Data string dispTransType = Utilities.GetStringValue(dr["DISPOSITION_TRANSACTION_TYPE"], ""); string dispTransNumber = Utilities.GetStringValue(dr["DISPOSITION_DOCUMENT_NUMBER"], ""); dispTransNumber = dispTransNumber == "0" ? "" : dispTransNumber; pCell.Phrase = new Phrase(dispTransType + " " + dispTransNumber, rptFont); pCell.Colspan = 2; pCell.NoWrap = true; table.AddCell(pCell); // Disp Trans Date string tmpDispDate = Utilities.GetStringValue(dr["DISPOSITION_DATE"], ""); if (string.IsNullOrEmpty(tmpDispDate)) { tmpDispDate = ""; } else { tmpDispDate = Utilities.GetDateTimeValue(tmpDispDate).ToShortDateString(); } pCell.Phrase = new Phrase(tmpDispDate, rptFont); pcell.Colspan = 2; table.AddCell(pCell); // Disp Name and ID string dispFirstName = Utilities.GetStringValue(dr["DISPOSITION_FIRST_NAME"], ""); string dispLastName = Utilities.GetStringValue(dr["DISPOSITION_LAST_NAME"], ""); string dispIdType = Utilities.GetStringValue(dr["DISPOSITION_ID_TYPE"], ""); string dispIdAgency = Utilities.GetStringValue(dr["DISPOSITION_ID_AGENCY"], ""); string dispIdNumber = Utilities.GetStringValue(dr["DISPOSITION_ID_NUMBER"], ""); PdfPTable dispNameID = new PdfPTable(1); if (!string.IsNullOrEmpty(dispFirstName) || !string.IsNullOrEmpty(dispLastName)) { dispNameID.AddCell(new Phrase(dispFirstName + " " + Utilities.GetStringValue(dr["DISPOSITION_MIDDLE_INITIAL"], "") + " " + dispLastName, rptFont)); } if (!string.IsNullOrEmpty(dispIdType) || !string.IsNullOrEmpty(dispIdNumber)) { dispNameID.AddCell(new Phrase(dispIdType + " " + dispIdAgency + dispIdNumber, rptFont)); } //here add FFL PdfPCell pcell2 = new PdfPCell(dispNameID); pcell2.Colspan = 3; table.AddCell(pcell2); // Disp Address string dispAddress = Utilities.GetStringValue(dr["DISPOSITION_ADDRESS"], ""); string dispCity = Utilities.GetStringValue(dr["DISPOSITION_CITY"], ""); string dispState = Utilities.GetStringValue(dr["DISPOSITION_STATE"], ""); string dispPostalCode = Utilities.GetStringValue(dr["DISPOSITION_POSTAL_CODE"], ""); PdfPTable dispAddressTable = new PdfPTable(1); if (!string.IsNullOrEmpty(dispAddress)) { dispAddressTable.AddCell(new Phrase(dispAddress, rptFont)); } if (!string.IsNullOrEmpty(dispCity) || !string.IsNullOrEmpty(dispState) || !string.IsNullOrEmpty(dispPostalCode)) { dispAddressTable.AddCell(new Phrase(dispCity + " " + dispState + " " + dispPostalCode, rptFont)); } PdfPCell pcell3 = new PdfPCell(dispAddressTable); pcell3.Colspan = 3; table.AddCell(pcell3); } document.Add(table); document.Close(); //OpenFile(rptFileName); //Print(); return(true); } FileLogger.Instance.logMessage(LogLevel.ERROR, this, "Gun Book printing failed since file name is not set"); return(false); } catch (Exception de) { FileLogger.Instance.logMessage(LogLevel.ERROR, this, "Gun Book printing" + de.Message); return(false); } }
public void miseEnForm(string typeDoc) { string cheminDocFinaux = ConfigurationManager.AppSettings["CheminDocFinaux"].ToString(); string cheminRessources = ConfigurationManager.AppSettings["CheminRessources"].ToString(); string chemin = cheminDocFinaux + "\\DocFinaux\\DEVIS\\DEVIS_" + nomDoc + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"; Document nouveauDocument = new Document(PageSize.A4, 20, 20, 12, 20); PdfWriter.GetInstance(nouveauDocument, new FileStream(chemin, FileMode.Create)); //Stockage du document nouveauDocument.Open(); Image image4 = Image.GetInstance(ConfigurationManager.AppSettings["CheminPatternTot"]); image4.Alignment = Image.UNDERLYING; image4.SetAbsolutePosition(385, 70); //----------------------------------------------------------------------------------------------------Filligrane----------------------------------------------- Image image5 = Image.GetInstance(ConfigurationManager.AppSettings["CheminFilligraneDevis"]); image5.Alignment = Image.UNDERLYING; image5.SetAbsolutePosition(200, 250); nouveauDocument.Add(image5); //---------------------------------------- //Constitution document PDF //---------------------------------------- PdfPTable tableau = new PdfPTable(2); tableau.TotalWidth = 550; tableau.LockedWidth = true; Image image6 = Image.GetInstance(ConfigurationManager.AppSettings["CheminLogoABCRDevis"]); image6.ScaleAbsolute(PageSize.A4); image6.ScaleToFit(175, 180); image6.SetAbsolutePosition(13, 715); nouveauDocument.Add(image6); Paragraph pLogo = new Paragraph(); //Image image = Image.GetInstance(ConfigurationManager.AppSettings["CheminLogoABCRDevis"]); // pLogo.Add(image); //Encadré photo pLogo.Add(new Phrase("")); PdfPCell celulleHauteGauche = new PdfPCell(pLogo); celulleHauteGauche.Border = PdfPCell.NO_BORDER; tableau.AddCell(celulleHauteGauche); //Encadré info devis Paragraph pDoc = new Paragraph(); Image image2 = Image.GetInstance(ConfigurationManager.AppSettings["CheminPatternHautDroiteDevis"]); image2.Alignment = Image.UNDERLYING; image2.SetAbsolutePosition(335, 740); nouveauDocument.Add(image2); pDoc.Alignment = Element.ALIGN_RIGHT; pDoc.Add(new Phrase("Devis n° " + donneeBody["Bon_numero1"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); pDoc.Add(new Phrase("Date : " + donneeBody["Bon_datrcl1"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8))); pDoc.Add(new Phrase("Référence client : " + donneeBody["Bon_rcl1"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, BaseColor.RED))); pDoc.Add(new Phrase("Code client: " + donneEntete["Client_code"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8))); pDoc.Add(new Phrase(donneEntete["Tiers_tel"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8))); pDoc.Add(new Phrase(donneEntete["Tiers_fax"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8))); pDoc.Add(new Phrase(donneEntete["Tiers_adf5"], FontFactory.GetFont(FontFactory.HELVETICA, 8))); PdfPCell celulleHauteDroite = new PdfPCell(pDoc); celulleHauteDroite.Border = PdfPCell.NO_BORDER; celulleHauteDroite.HorizontalAlignment = Element.ALIGN_CENTER; tableau.AddCell(celulleHauteDroite); //Encadré "ABCR" Paragraph p = new Paragraph(); p.Add(new Phrase(donneEntete["Adresse_interne_2"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); p.Add(new Phrase(donneEntete["Adresse_interne_3"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); p.Add(new Phrase(donneEntete["Adresse_interne_4"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 7, Font.BOLD))); p.Add(new Phrase(donneEntete["Adresse_interne_5"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 7, Font.BOLD))); p.Add(new Phrase(donneEntete["Adresse_interne_6"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 7, Font.BOLD))); p.Add(new Phrase(donneEntete["Adresse_interne_7"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); p.Add(new Phrase(donneEntete["Adresse_interne_8"] + "\n" + "\n" + "\n" + "\n" + "\n ", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); PdfPCell celluleBasGauche = new PdfPCell(p); celluleBasGauche.Border = PdfPCell.NO_BORDER; tableau.AddCell(celluleBasGauche); //Encadré client Paragraph pClient = new Paragraph(); if (donneEntete["Tiers_adl1"] == "") { pClient.Add(new Phrase("\n" + "\n" + donneEntete["Tiers_adf1"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); pClient.Add(new Phrase(donneEntete["Tiers_adf2"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); pClient.Add(new Phrase(donneEntete["Tiers_adf3"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); pClient.Add(new Phrase(donneEntete["Tiers_adf4"] + "\n" + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); pClient.Add(new Phrase(donneEntete["Tiers_adfcp"] + " " + donneEntete["Tiers_adf6"], FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); } else { pClient.Add(new Phrase("\n" /*+"\n"*/ + donneEntete["Tiers_adl1"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); pClient.Add(new Phrase(donneEntete["Tiers_adl2"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); pClient.Add(new Phrase(donneEntete["Tiers_adl3"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); pClient.Add(new Phrase(donneEntete["Tiers_adl4"] + "\n" + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); pClient.Add(new Phrase(donneEntete["Tiers_adlcp"] + " " + donneEntete["Tiers_adl6"], FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); } PdfPCell celluleBasDroite = new PdfPCell(pClient); celluleBasDroite.Border = PdfPCell.NO_BORDER; tableau.AddCell(celluleBasDroite); nouveauDocument.Add(tableau); //Dessus tableau Paragraph pRécap = new Paragraph(); Chunk contact = null; contact = new Chunk("Votre contact : " + donneEntete["Bon_vendeur_lib"] + "\n " + donneEntete["Duplicata"], FontFactory.GetFont(FontFactory.HELVETICA, 7, Font.ITALIC));//FontFactory pour changer la police Chunk delai = new Chunk("Livraison : " + donneEntete["Tiers_adf1"] + " - " + donneEntete["Tiers_adf2"] + " - " + donneEntete["Tiers_adfcp"] + " " + donneEntete["Tiers_adf6"] + "\n" + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 7, Font.ITALIC)).SetUnderline(2, 2); Chunk ligneEspace = new Chunk("\n", FontFactory.GetFont(FontFactory.HELVETICA, 1, Font.ITALIC)); pRécap.Add(contact); pRécap.Add(delai); pRécap.Add(ligneEspace); nouveauDocument.Add(pRécap); CurseurTemplate ct = new CurseurTemplate(); valeurTemplate = ct.chercher("Devis"); float[] largeurs = { int.Parse(valeurTemplate["Dimension1"]), int.Parse(valeurTemplate["Dimension2"]), int.Parse(valeurTemplate["Dimension3"]), int.Parse(valeurTemplate["Dimension4"]), int.Parse(valeurTemplate["Dimension5"]), int.Parse(valeurTemplate["Dimension6"]), int.Parse(valeurTemplate["Dimension7"]), int.Parse(valeurTemplate["Dimension8"]), int.Parse(valeurTemplate["Dimension9"]) }; // Dimension tableau body PdfPTable table = new PdfPTable(largeurs); table.TotalWidth = 555; //Chaque colonne crée ci dessus doit être rempli table.LockedWidth = true; PdfPCell cellET1 = new PdfPCell(new Phrase("Article", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET1.Border = PdfPCell.NO_BORDER; //cellET1.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET1); PdfPCell cellET2 = new PdfPCell(new Phrase("Désignation", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET2.Border = PdfPCell.NO_BORDER; //cellET2.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET2); PdfPCell cellET3 = new PdfPCell(new Phrase("UV", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET3.Border = PdfPCell.NO_BORDER; //cellET3.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET3); PdfPCell cellET4 = new PdfPCell(new Phrase("Quantité", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET4.Border = PdfPCell.NO_BORDER; //cellET4.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET4); PdfPCell cellET5 = new PdfPCell(new Phrase("Prix remisé", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET5.Border = PdfPCell.NO_BORDER; //cellET5.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET5); PdfPCell cellET6 = new PdfPCell(new Phrase("Remise", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET6.Border = PdfPCell.NO_BORDER; //cellET6.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET6); PdfPCell cellET7 = new PdfPCell(new Phrase("Prix net", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET7.Border = PdfPCell.NO_BORDER; //cellET7.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET7); PdfPCell cellET8 = new PdfPCell(new Phrase("Montant HT", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET8.Border = PdfPCell.NO_BORDER; //cellET8.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET8); PdfPCell cellET9 = new PdfPCell(new Phrase("TVA", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET9.Border = PdfPCell.NO_BORDER; //cellET9.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET9); Image image3 = Image.GetInstance(ConfigurationManager.AppSettings["CheminPatternTableau"]); image3.Alignment = Image.UNDERLYING; image3.SetAbsolutePosition(20, 567); nouveauDocument.Add(image3); int i; int nbLigne = 0; float resultat = 0; float dimTab = 0; int décrement = 0; int numPage = 0; //Constitution du tableau d'article bool okDési = false; bool okStart = false; for (i = 1; i <= iBody; i++) { //Condition ARTICLE---------------------------------------------------------------------------------------------------------------------- if (donneeBody["Ligne_type" + i] == "ART") { nbLigne++; string sPattern = "libelle" + i + "bis"; PdfPCell cell1 = new PdfPCell(new Phrase(donneeBody["Art_code" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell1.Border = PdfPCell.NO_BORDER; cell1.Border += PdfPCell.RIGHT_BORDER; cell1.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell1); Paragraph pCell2 = new Paragraph(); PdfPCell cell2 = new PdfPCell(pCell2); cell2.Border = PdfPCell.NO_BORDER; cell2.Border += PdfPCell.RIGHT_BORDER; cell2.Border += PdfPCell.LEFT_BORDER; foreach (KeyValuePair <string, string> entry in donneeBody) { if (System.Text.RegularExpressions.Regex.IsMatch(entry.Key, sPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { if (okStart == false) { pCell2.Add(new Phrase(donneeBody["Libelle" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); string clé = entry.Key; pCell2.Add(new Phrase(donneeBody[clé] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); okStart = true; } else { string clé = entry.Key; pCell2.Add(new Phrase(donneeBody[clé] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); } okDési = true; } } if (okDési == false) { PdfPCell cell3 = new PdfPCell(new Phrase(donneeBody["Libelle" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell3.Border = PdfPCell.NO_BORDER; cell3.Border += PdfPCell.RIGHT_BORDER; cell3.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell3); } else { table.AddCell(cell2); } PdfPCell cell4 = new PdfPCell(new Phrase(donneeBody["Art_unite" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell4.Border = PdfPCell.NO_BORDER; cell4.Border += PdfPCell.RIGHT_BORDER; cell4.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell4); PdfPCell cell5 = new PdfPCell(new Phrase(donneeBody["Art_qte" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell5.Border = PdfPCell.NO_BORDER; cell5.Border += PdfPCell.RIGHT_BORDER; cell5.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell5); PdfPCell cell6 = new PdfPCell(new Phrase(donneeBody["Art_remise2" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell6.Border = PdfPCell.NO_BORDER; cell6.Border += PdfPCell.RIGHT_BORDER; cell6.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell6); PdfPCell cell7 = new PdfPCell(new Phrase(donneeBody["Art_remise1" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell7.Border = PdfPCell.NO_BORDER; cell7.Border += PdfPCell.RIGHT_BORDER; cell7.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell7); if (donneeBody["Art_prinet" + i] != "") { PdfPCell cell8 = new PdfPCell(new Phrase(double.Parse(donneeBody["Art_prinet" + i]).ToString("N2") + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell8.Border = PdfPCell.NO_BORDER; cell8.Border += PdfPCell.RIGHT_BORDER; cell8.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell8); } else { PdfPCell cell8 = new PdfPCell(new Phrase(donneeBody["Art_prinet" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell8.Border = PdfPCell.NO_BORDER; cell8.Border += PdfPCell.RIGHT_BORDER; cell8.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell8); } PdfPCell cell9 = new PdfPCell(new Phrase(donneeBody["Art_monht" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell9.Border = PdfPCell.NO_BORDER; cell9.Border += PdfPCell.RIGHT_BORDER; cell9.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell9); PdfPCell cell10 = new PdfPCell(new Phrase("0" + donneeBody["Art_tva_code" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell10.Border = PdfPCell.NO_BORDER; cell10.Border += PdfPCell.RIGHT_BORDER; cell10.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell10); okDési = false; okStart = false; } //Condition ARTICLE GRATUIT----------------------------------------------------------------------------------------------------------------------------- if (donneeBody["Ligne_type" + i] == "GRA") { nbLigne++; string sPattern = "libelle" + i + "bis"; PdfPCell cell1 = new PdfPCell(new Phrase(donneeBody["Art_code" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell1.Border = PdfPCell.NO_BORDER; cell1.Border += PdfPCell.RIGHT_BORDER; cell1.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell1); foreach (KeyValuePair <string, string> entry in donneeBody) { if (System.Text.RegularExpressions.Regex.IsMatch(entry.Key, sPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { PdfPCell cell2 = new PdfPCell(new Phrase(donneeBody["Libelle" + i] + "\n" + donneeBody["Libelle" + i + "bis"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell2.Border = PdfPCell.NO_BORDER; cell2.Border += PdfPCell.RIGHT_BORDER; cell2.Border += PdfPCell.LEFT_BORDER; okDési = true; table.AddCell(cell2); } } if (okDési == false) { PdfPCell cell3 = new PdfPCell(new Phrase(donneeBody["Libelle" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell3.Border = PdfPCell.NO_BORDER; cell3.Border += PdfPCell.RIGHT_BORDER; cell3.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell3); } PdfPCell cell4 = new PdfPCell(new Phrase(donneeBody["Art_unite" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell4.Border = PdfPCell.NO_BORDER; cell4.Border += PdfPCell.RIGHT_BORDER; cell4.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell4); PdfPCell cell5 = new PdfPCell(new Phrase(donneeBody["Art_qte" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell5.Border = PdfPCell.NO_BORDER; cell5.Border += PdfPCell.RIGHT_BORDER; cell5.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell5); PdfPCell cell6 = new PdfPCell(new Phrase("" + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell6.Border = PdfPCell.NO_BORDER; cell6.Border += PdfPCell.RIGHT_BORDER; cell6.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell6); table.AddCell(cell6); table.AddCell(cell6); PdfPCell cell7 = new PdfPCell((new Phrase(donneeBody["Lib_rempl_mt" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD)))); cell7.Border = PdfPCell.NO_BORDER; cell7.Border += PdfPCell.RIGHT_BORDER; cell7.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell7); PdfPCell cell8 = new PdfPCell(new Phrase("" + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell8.Border = PdfPCell.NO_BORDER; cell8.Border += PdfPCell.LEFT_BORDER; cell8.Border += PdfPCell.RIGHT_BORDER; table.AddCell(cell8); } //Condition COMMENTAIRE-------------------------------------------------------------------------------------------------------------------------------- if (donneeBody["Ligne_type" + i] == "COM") { nbLigne++; PdfPCell cellVide = new PdfPCell(new Phrase("" + "\n")); PdfPCell cell = new PdfPCell(new Phrase(donneeBody["Libelle" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); PdfPCell cellFin = new PdfPCell(); cellVide.Border = PdfPCell.NO_BORDER; cellVide.Border += PdfPCell.RIGHT_BORDER; cellVide.Border += PdfPCell.LEFT_BORDER; cell.Border = PdfPCell.NO_BORDER; cell.Border += PdfPCell.RIGHT_BORDER; cell.Border += PdfPCell.LEFT_BORDER; cellFin.Border = PdfPCell.NO_BORDER; cellFin.Border += PdfPCell.LEFT_BORDER; cellFin.Border += PdfPCell.RIGHT_BORDER; table.AddCell(cellVide); table.AddCell(cell); table.AddCell(cellVide); table.AddCell(cellVide); table.AddCell(cellVide); table.AddCell(cellVide); table.AddCell(cellVide); table.AddCell(cellVide); table.AddCell(cellFin); } PdfPCell cellEcartDroite = new PdfPCell(new Phrase(" " + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 2, Font.BOLD))); PdfPCell cellEcart = new PdfPCell(new Phrase(" " + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 2, Font.BOLD))); cellEcart.Border = PdfPCell.NO_BORDER; cellEcart.Border += PdfPCell.LEFT_BORDER; cellEcart.Border += PdfPCell.RIGHT_BORDER; cellEcartDroite.Border = PdfPCell.NO_BORDER; cellEcartDroite.Border += PdfPCell.RIGHT_BORDER; cellEcartDroite.Border += PdfPCell.LEFT_BORDER; table.AddCell(cellEcartDroite); table.AddCell(cellEcart); table.AddCell(cellEcart); table.AddCell(cellEcart); table.AddCell(cellEcart); table.AddCell(cellEcart); table.AddCell(cellEcart); table.AddCell(cellEcart); table.AddCell(cellEcart); //--------------------------------------------GESTION DU SAUT DE PAGE------------------------------------------------------------------------------------------- //float temp = table.GetRowHeight(i-1-décrement); float temp = table.TotalHeight; dimTab = temp; if (dimTab >= 410 && i < iBody) { //Saut de page numPage++; PdfPCell cellFin = new PdfPCell(new Phrase(" ")); PdfPCell cellBlanche = new PdfPCell(new Phrase(" ")); PdfPCell cellBlancheD = new PdfPCell(new Phrase(" ")); cellFin.Colspan = 9; cellBlanche.FixedHeight = (450 - dimTab); cellBlanche.Border = PdfPCell.NO_BORDER; cellBlanche.Border += PdfPCell.RIGHT_BORDER; cellBlanche.Border += PdfPCell.LEFT_BORDER; cellBlancheD.FixedHeight = (450 - dimTab); cellBlancheD.Border = PdfPCell.NO_BORDER; cellBlancheD.Border += PdfPCell.LEFT_BORDER; cellBlancheD.Border += PdfPCell.RIGHT_BORDER; cellFin.Border = PdfPCell.NO_BORDER; cellFin.Border += PdfPCell.TOP_BORDER; table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlancheD); table.AddCell(cellFin); nouveauDocument.Add(table);//----------------------------------------------------------------------------Repère ligne en dessous-------------------------------------------------- Phrase pReport = new Phrase(" A REPORTER\n\n\n\n\n Page n° " + numPage, FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD)); nouveauDocument.Add(pReport); table.DeleteBodyRows(); nouveauDocument.Add(Chunk.NEXTPAGE); nouveauDocument.Add(tableau); nouveauDocument.Add(pRécap); nouveauDocument.Add(image2); nouveauDocument.Add(image3); nouveauDocument.Add(image5); table.AddCell(cellET1); table.AddCell(cellET2); table.AddCell(cellET3); table.AddCell(cellET4); table.AddCell(cellET5); table.AddCell(cellET6); table.AddCell(cellET7); table.AddCell(cellET8); table.AddCell(cellET9); dimTab = 0; décrement = (i - 1); } //---------------------------------------------------------------------------------------------------------------------------------------------------------------------- } int b; //---------------------------------------------------------------- for (b = 0; b <= i; b++) // { // Compteur dimension du tableau float temp = table.TotalHeight; // resultat = temp; // } //------------------------------------------------------------------- if (i > iBody) { PdfPCell cellFin = new PdfPCell(new Phrase(" ")); PdfPCell cellBlanche = new PdfPCell(new Phrase(" ")); PdfPCell cellBlancheD = new PdfPCell(new Phrase(" ")); cellFin.Colspan = 9; resultat = 450 - resultat; //<<----------450 correspond au nombre de point de la longueur du tableau, c'est la valeur à modifier pour modifier la taille du tableau cellBlanche.FixedHeight = resultat; cellBlanche.Border = PdfPCell.NO_BORDER; cellBlanche.Border += PdfPCell.RIGHT_BORDER; cellBlanche.Border += PdfPCell.LEFT_BORDER; cellBlancheD.FixedHeight = resultat; cellBlancheD.Border = PdfPCell.NO_BORDER; cellBlancheD.Border += PdfPCell.LEFT_BORDER; cellBlancheD.Border += PdfPCell.RIGHT_BORDER; cellFin.Border = PdfPCell.NO_BORDER; cellFin.Border += PdfPCell.TOP_BORDER; table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlancheD); table.AddCell(cellFin); } nouveauDocument.Add(table); // Constitution tableau pied de page PdfPTable tableauPied = new PdfPTable(3); tableauPied.TotalWidth = 555; tableauPied.LockedWidth = true; Paragraph pTVA = new Paragraph(); pTVA.Add(new Phrase("Offre de prix valable jusqu'au : " + donneEntete["Date_val"], FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD, BaseColor.RED))); int iF = 0; foreach (KeyValuePair <string, string> entry in donneeFoot) { if (System.Text.RegularExpressions.Regex.IsMatch(entry.Value, "TVA", System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { pTVA.Add(new Phrase("\nTVA " + donneeFoot.ElementAt(iF - 1).Value + " = " + entry.Value, FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); } iF++; } PdfPCell cellulePied = new PdfPCell(pTVA); cellulePied.Colspan = 2; cellulePied.Border = PdfPCell.NO_BORDER; tableauPied.AddCell(cellulePied); nouveauDocument.Add(image4); PdfPTable tableauTot = new PdfPTable(1); PdfPCell cellTTot = new PdfPCell(new Phrase("Total HT : " + donneeFoot["Base_tva_mht"] + " €", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellTTot.Border = PdfPCell.NO_BORDER; cellTTot.Border = PdfPCell.BOTTOM_BORDER; tableauTot.AddCell(cellTTot); PdfPCell cellTVA = new PdfPCell(new Phrase("Total TVA : " + donneeFoot["Base_tva_mtva"] + " €", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellTVA.Border = PdfPCell.NO_BORDER; cellTVA.Border = PdfPCell.BOTTOM_BORDER; tableauTot.AddCell(cellTVA); PdfPCell cellTTC = new PdfPCell(new Phrase("Total TTC : " + donneeFoot["Base_tva_mttc"] + " €", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellTTC.Border = PdfPCell.NO_BORDER; tableauTot.AddCell(cellTTC); PdfPCell cellTot = new PdfPCell(tableauTot); cellTot.Border = PdfPCell.NO_BORDER; tableauPied.AddCell(cellTot); nouveauDocument.Add(tableauPied); Phrase maPhrase = new Phrase(); maPhrase.Add(new Chunk("\nBon pour accord ", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); maPhrase.Add(new Chunk("\n Fait à: le: Signature", FontFactory.GetFont(FontFactory.HELVETICA, 8))); nouveauDocument.Add(maPhrase); if (numPage > 0) { Phrase PageFinal = new Phrase(" Page n° " + (1 + numPage), FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD)); nouveauDocument.Add(PageFinal); } nouveauDocument.Close(); //Copie Doc dans GED try { String connectionString = ConfigurationManager.AppSettings["ChaineDeConnexionBase"]; OdbcConnection conn = new OdbcConnection(connectionString); conn.Open(); string requete = "select T1.NOCLI c1 , T1.NOMCL c2 from B00C0ACR.AMAGESTCOM.ACLIENL1 T1 where T1.NOCLI = '" + donneEntete["Client_code"] + "'"; OdbcCommand act = new OdbcCommand(requete, conn); OdbcDataReader act0 = act.ExecuteReader(); string nomADH = ""; while (act0.Read()) { nomADH = (act0.GetString(1)); } conn.Close(); if (!System.IO.Directory.Exists(ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneEntete["Client_code"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM") + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Devis\\")) { System.IO.Directory.CreateDirectory(ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneEntete["Client_code"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Devis\\"); System.IO.File.Copy(chemin, ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneEntete["Client_code"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Devis\\" + "\\DEVIS_" + nomDoc + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"); } else { System.IO.File.Copy(chemin, ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneEntete["Client_code"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Devis\\" + "\\DEVIS_" + nomDoc + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"); } } catch { } //--------------------------------------------------------FIN COPIE---------------------------------------------------------------------------------------------------------- int nbImp = 0; int nbImpOK = 0; string[] printer = new string[20]; // tableau qui contient les imprimantes du profil d'impression ProfilImprimante profil = new ProfilImprimante(); profil.chargementXML("Dev"); // chargement selon le type de doc string vendeur = unProfil.Substring(2, 3); vendeur = vendeur.TrimEnd(); var listeProfil = profil.getDonneeProfil(); try { foreach (string v in listeProfil[vendeur]) //lecture des imprimantes liée à un profil { printer[nbImp] = v.ToString(); nbImp++; //on incrémente le nombre d'impression à executer } } catch { printer[nbImp] = ConfigurationManager.AppSettings["ImpDef"]; //Imprimante par defaut (essai) nbImp++; } nbImp = nbImp - 1; while (nbImpOK <= nbImp) // boucle tant que le nombre d'impression fait n'à pas atteint le nombre d'impression demander { string printerName = printer[nbImpOK]; string inputFile = String.Format(@"{0}", chemin); try { using (GhostscriptProcessor processor = new GhostscriptProcessor()) { List <string> switches = new List <string>(); switches.Add("-empty"); switches.Add("-dPrinted"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOSAFER"); switches.Add("-dNumCopies=" + ConfigurationManager.AppSettings["NbCopieGC"]); switches.Add("-sDEVICE=" + ConfigurationManager.AppSettings["PiloteImpressionGC"]); switches.Add("-sOutputFile=%printer%" + printerName); switches.Add("-f"); switches.Add(inputFile); processor.StartProcessing(switches.ToArray(), null); } nbImpOK++; } catch (Exception e) { LogHelper.WriteToFile(e.Message, "ParseurBP" + donneEntete["Document_numero"].Trim()); } } /*Mail m = new Mail(); * m.remplirDictionnaire(); * m.comparerDocument(donneEntete["Client_code"]);*/ }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["lstGuardarCargaCaja"] != null) { string strFont = stFont.Value; string strFont1 = stFont1.Value; string strFont2 = stFont2.Value; string strFont3 = stFont3.Value; DateTime d = DateTime.Now; string s = d.ToString("yyyyMMddHHmmss"); string nombreArchivo = "CodigosCarga" + s; string direccion = Server.MapPath(".") + "/Reportes/" + nombreArchivo; string dir = direccion; Document document = new Document(); PdfWriter.GetInstance(document, new FileStream(dir + ".pdf", FileMode.OpenOrCreate)); document.Open(); PdfPTable tblCargaCaja = new PdfPTable(1); tblCargaCaja.WidthPercentage = 100; tblCargaCaja.DefaultCell.Padding = 50; iTextSharp.text.Font _standardFont = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, Convert.ToInt32(strFont), iTextSharp.text.Font.BOLD, BaseColor.BLACK); iTextSharp.text.Font _standardFont1 = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, Convert.ToInt32(strFont1), iTextSharp.text.Font.BOLD, BaseColor.WHITE); iTextSharp.text.Font _standardFont2 = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, Convert.ToInt32(strFont2), iTextSharp.text.Font.BOLD, BaseColor.WHITE); iTextSharp.text.Font _standardFont3 = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, Convert.ToInt32(strFont3), iTextSharp.text.Font.BOLD, BaseColor.BLACK); List <SistemaDeArchivoCargaCajaINS> lstGuardarCargaCaja = new List <SistemaDeArchivoCargaCajaINS>(); lstGuardarCargaCaja = (List <SistemaDeArchivoCargaCajaINS>)Session["lstGuardarCargaCaja"]; PdfPCell clCarac = new PdfPCell(new Phrase("ADMI100", _standardFont)); int conta = 1; clCarac = new PdfPCell(new Phrase("...", _standardFont2)); clCarac.BorderWidth = 0; clCarac.HorizontalAlignment = 1; tblCargaCaja.AddCell(clCarac); for (int i = 0; i < lstGuardarCargaCaja.Count(); i++) { clCarac = new PdfPCell(new Phrase((lstGuardarCargaCaja[i].AreaCodigo.ToString() + lstGuardarCargaCaja[i].CajaCodigo.ToString()), _standardFont)); clCarac.BorderWidth = 0; clCarac.HorizontalAlignment = 1; tblCargaCaja.AddCell(clCarac); clCarac = new PdfPCell(new Phrase((lstGuardarCargaCaja[i].Observacion.ToString()), _standardFont3)); clCarac.BorderWidth = 0; clCarac.HorizontalAlignment = 1; tblCargaCaja.AddCell(clCarac); if (conta == 5) { document.Add(tblCargaCaja); document.NewPage(); tblCargaCaja.DeleteBodyRows(); conta = 1; } else { clCarac = new PdfPCell(new Phrase("...", _standardFont1)); clCarac.BorderWidth = 0; clCarac.HorizontalAlignment = 1; tblCargaCaja.AddCell(clCarac); conta = conta + 1; } } document.Add(tblCargaCaja); /////////////////////////////////////////// document.NewPage(); PdfPTable tblCargaCaja1 = new PdfPTable(1); tblCargaCaja1.WidthPercentage = 100; tblCargaCaja1.DefaultCell.Padding = 50; clCarac = new PdfPCell(new Phrase("...", _standardFont2)); clCarac.BorderWidth = 0; clCarac.HorizontalAlignment = 1; tblCargaCaja1.AddCell(clCarac); conta = 1; for (int i = 0; i < lstGuardarCargaCaja.Count(); i++) { clCarac = new PdfPCell(new Phrase((lstGuardarCargaCaja[i].AreaCodigo.ToString() + lstGuardarCargaCaja[i].CajaCodigo.ToString()), _standardFont)); clCarac.BorderWidth = 0; clCarac.HorizontalAlignment = 1; tblCargaCaja1.AddCell(clCarac); clCarac = new PdfPCell(new Phrase((lstGuardarCargaCaja[i].Observacion.ToString()), _standardFont3)); clCarac.BorderWidth = 0; clCarac.HorizontalAlignment = 1; tblCargaCaja1.AddCell(clCarac); if (conta == 5) { document.Add(tblCargaCaja1); document.NewPage(); tblCargaCaja1.DeleteBodyRows(); conta = 1; } else { clCarac = new PdfPCell(new Phrase("...", _standardFont1)); clCarac.BorderWidth = 0; clCarac.HorizontalAlignment = 1; tblCargaCaja1.AddCell(clCarac); conta = conta + 1; } } document.Add(tblCargaCaja1); document.Close(); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = "application/pdf"; HttpContext.Current.Response.AddHeader("Content-disposition", "inline; filename=" + nombreArchivo + ".pdf"); HttpContext.Current.Response.TransmitFile(dir + ".pdf"); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.SuppressContent = true; HttpContext.Current.ApplicationInstance.CompleteRequest(); } else if (Session["lstSistemaDeArchivoReimpresion"] != null) { string strFont = stFont.Value; string strFont1 = stFont1.Value; string strFont2 = stFont2.Value; string strFont3 = stFont3.Value; DateTime d = DateTime.Now; string s = d.ToString("yyyyMMddHHmmss"); string nombreArchivo = "CodigosCarga" + s; string direccion = Server.MapPath(".") + "/Reportes/" + nombreArchivo; string dir = direccion; Document document = new Document(); PdfWriter.GetInstance(document, new FileStream(dir + ".pdf", FileMode.OpenOrCreate)); document.Open(); PdfPTable tblCargaCaja = new PdfPTable(1); tblCargaCaja.WidthPercentage = 100; tblCargaCaja.DefaultCell.Padding = 50; iTextSharp.text.Font _standardFont = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, Convert.ToInt32(strFont), iTextSharp.text.Font.BOLD, BaseColor.BLACK); iTextSharp.text.Font _standardFont1 = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, Convert.ToInt32(strFont1), iTextSharp.text.Font.BOLD, BaseColor.WHITE); iTextSharp.text.Font _standardFont2 = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, Convert.ToInt32(strFont2), iTextSharp.text.Font.BOLD, BaseColor.WHITE); iTextSharp.text.Font _standardFont3 = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, Convert.ToInt32(strFont3), iTextSharp.text.Font.BOLD, BaseColor.BLACK); //List<SistemaDeArchivoCargaCajaINS> lstGuardarCargaCaja = new List<SistemaDeArchivoCargaCajaINS>(); List <SistemaDeArchivoReimpresion> lstSistemaDeArchivoReimpresion = new List <SistemaDeArchivoReimpresion>(); //lstGuardarCargaCaja = (List<SistemaDeArchivoCargaCajaINS>)Session["lstGuardarCargaCaja"]; lstSistemaDeArchivoReimpresion = (List <SistemaDeArchivoReimpresion>)Session["lstSistemaDeArchivoReimpresion"]; PdfPCell clCarac = new PdfPCell(new Phrase("ADMI100", _standardFont)); int conta = 1; clCarac = new PdfPCell(new Phrase("...", _standardFont2)); clCarac.BorderWidth = 0; clCarac.HorizontalAlignment = 1; tblCargaCaja.AddCell(clCarac); for (int i = 0; i < lstSistemaDeArchivoReimpresion.Count(); i++) { clCarac = new PdfPCell(new Phrase((lstSistemaDeArchivoReimpresion[i].CajaCodigo.ToString()), _standardFont)); clCarac.BorderWidth = 0; clCarac.HorizontalAlignment = 1; tblCargaCaja.AddCell(clCarac); clCarac = new PdfPCell(new Phrase((lstSistemaDeArchivoReimpresion[i].Observacion.ToString()), _standardFont3)); clCarac.BorderWidth = 0; clCarac.HorizontalAlignment = 1; tblCargaCaja.AddCell(clCarac); if (conta == 5) { document.Add(tblCargaCaja); document.NewPage(); tblCargaCaja.DeleteBodyRows(); conta = 1; } else { clCarac = new PdfPCell(new Phrase("...", _standardFont1)); clCarac.BorderWidth = 0; clCarac.HorizontalAlignment = 1; tblCargaCaja.AddCell(clCarac); conta = conta + 1; } } document.Add(tblCargaCaja); document.Close(); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = "application/pdf"; HttpContext.Current.Response.AddHeader("Content-disposition", "inline; filename=" + nombreArchivo + ".pdf"); HttpContext.Current.Response.TransmitFile(dir + ".pdf"); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.SuppressContent = true; HttpContext.Current.ApplicationInstance.CompleteRequest(); } } }
private void setPrescriptionPageHeader(Document document) { try { //Set Header Font var smallHeaderFont = FontFactory.GetFont("verdana", Convert.ToInt32(ConfigurationManager.AppSettings["smallHeaderFont"]), iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK); var headerFont = FontFactory.GetFont("verdana", Convert.ToInt32(ConfigurationManager.AppSettings["headerFont"]), iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK); PdfPTable table = new PdfPTable(1); table.DeleteBodyRows(); table.WidthPercentage = 100; table.HorizontalAlignment = 0; table.SpacingBefore = 5; table.SpacingAfter = 5; newCell(table, "\n", 1, 0); newCell(table, "PARAMASHETTI", headerFont, 1, 0); newCell(table, "MULTI SPECIALITY HOSPITAL", headerFont, 1, 0); newCell(table, "Vishwas Estate, Miraj - Sangli Road, Miraj.", smallHeaderFont, 1, 0); newCell(table, "Phone : 0233 - 2212430, 2212431", smallHeaderFont, 1, 0); document.Add(table); table = new PdfPTable(2); table.DeleteBodyRows(); table.WidthPercentage = 100; table.HorizontalAlignment = 0; table.SpacingBefore = 5; table.SpacingAfter = 5; List <string> lststring = new List <string>(); lststring.Add("Dr. V. S. Paramshetti"); lststring.Add("Dr. Mrs R. V. Paramshetti"); lststring.Add("M.D. (Med)"); lststring.Add("M.B.B.S; D.C.H"); lststring.Add("Consultant Physician"); lststring.Add("Consultant Paediatrician"); lststring.Add("Reg No. 63054"); lststring.Add("Reg No. 33414"); int index = 0; foreach (string item in lststring) { int alignment = -1; Font font = index < 2 ? headerFont : smallHeaderFont; if (index == 3) { alignment = 2; } else { alignment = index % 2 != 0 ? 2 : 0; } newCell(table, item, font, alignment, 0); index++; } newCell(table, "\n", 1, 2); document.Add(table); } catch (Exception ex) { throw ex; } }
private void PrintDetailRecord(DataRow dr, PdfPTable table) { numberOfRows++; var cell = new PdfPCell(new Paragraph(Utilities.GetStringValue(dr["userID"]), ReportFont)) { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_TOP }; table.AddCell(cell); cell = new PdfPCell(new Paragraph(Utilities.GetStringValue(dr["icn_doc"]), ReportFont)) { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_TOP }; table.AddCell(cell); cell = new PdfPCell(new Paragraph(Utilities.GetStringValue(dr["md_desc"]), ReportFont)) { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_TOP }; table.AddCell(cell); cell = new PdfPCell(new Paragraph(Utilities.GetStringValue(dr["loc_aisle"]), ReportFont)) { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_TOP }; table.AddCell(cell); cell = new PdfPCell(new Paragraph(Utilities.GetStringValue(dr["loc_shelf"]), ReportFont)) { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_TOP }; table.AddCell(cell); cell = new PdfPCell(new Paragraph(Utilities.GetStringValue(dr["location"]), ReportFont)) { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_TOP }; table.AddCell(cell); var sGunNumber = Utilities.GetStringValue(dr["gun_number"], string.Empty); sGunNumber = sGunNumber == "0" ? string.Empty : sGunNumber; cell = new PdfPCell(new Paragraph(sGunNumber, ReportFont)) { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_TOP, PaddingLeft = -10 }; table.AddCell(cell); var tableHeight = table.Rows.Cast <object>().Select((t, i) => table.GetRowHeight(i)).Sum(); if (tableHeight <= PageSize.LETTER.Height - 72) { return; } rowNumbers.Add(numberOfRows); document.Add(table); numberOfRows = 0; table.DeleteBodyRows(); document.NewPage(); }
public string PrintVisitNote(gbmodel.patient.Patient p_oPatient, gbmodel.user.User p_oUser) { specialtyNote.SrvPatient oSrvPatient = new specialtyNote.SrvPatient(); List <gbmodel.patient.SpecialtyNote> oList = new List <gbmodel.patient.SpecialtyNote>(); oList = oSrvPatient.SelectSpecialtyNote(p_oPatient); string OpenPdfFilepath = ""; DataSet ds = new DataSet(); ds = GetVisitInfo(p_oPatient.CaseID, p_oPatient.Account.ID); string szfirstname = ""; if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["PatientName"].ToString() != "") { szfirstname = ds.Tables[0].Rows[0]["PatientName"].ToString(); szfirstname = szfirstname.Replace(" ", string.Empty); szfirstname = szfirstname.Replace(".", string.Empty); szfirstname = szfirstname.Replace(",", string.Empty); } } if (ds != null && ds.Tables[1] != null) { string path = getApplicationSetting("PatientInfoSaveFilePath"); string OpenFilepath = getApplicationSetting("PatientInfoOpenFilePath"); path = path + "PatientDeskNotes/"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string newPdfFilename = szfirstname.Trim() + "_Visit_Information_" + DateTime.Now.ToString("MM_dd_yyyyhhmm") + ".pdf"; string pdfPath = path + newPdfFilename; MemoryStream m = new MemoryStream(); iTextSharp.text.Document document = new iTextSharp.text.Document(PageSize.A4, 36, 36, 20, 20); float[] wBase = { 4f }; PdfPTable tblBase = new PdfPTable(wBase); tblBase.DefaultCell.Border = Rectangle.NO_BORDER; tblBase.WidthPercentage = 100; PdfWriter writer = PdfWriter.GetInstance(document, m); document.Open(); #region "for printed by" float[] width = { 4f, 4f }; PdfPTable tblprintby = new PdfPTable(width); tblprintby.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; tblprintby.DefaultCell.Border = Rectangle.NO_BORDER; tblprintby.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_LEFT; tblprintby.DefaultCell.VerticalAlignment = iTextSharp.text.Element.ALIGN_TOP; tblprintby.AddCell(new Phrase("Printed By : " + p_oUser.UserName, iTextSharp.text.FontFactory.GetFont("Arial", 8, iTextSharp.text.Color.BLACK))); tblprintby.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT; tblprintby.AddCell(new Phrase("Printed on : " + DateTime.Now.ToString("MM/dd/yyyy"), iTextSharp.text.FontFactory.GetFont("Arial", 8, iTextSharp.text.Color.BLACK))); tblBase.AddCell(tblprintby); #endregion tblBase.AddCell(" "); #region "for patient information" float[] wdh = { 4f }; PdfPTable tblheading = new PdfPTable(wdh); tblheading.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; tblheading.DefaultCell.Border = Rectangle.NO_BORDER; tblheading.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER; tblheading.DefaultCell.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE; tblBase.AddCell(tblheading); #endregion #region for Personal Information float[] w11 = { 3f, 3f, 3f, 3f }; PdfPTable table = new PdfPTable(w11); table.WidthPercentage = 100; table.DefaultCell.BorderColor = Color.BLACK; PdfPCell cell1 = new PdfPCell(new Phrase("Personal Information", iTextSharp.text.FontFactory.GetFont("Arial", 11, iTextSharp.text.Color.BLACK))); cell1.Colspan = 4; cell1.BackgroundColor = Color.LIGHT_GRAY; cell1.BorderColor = Color.BLACK; table.AddCell(cell1); table.AddCell(new Phrase("Patient Name", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK))); if (ds.Tables[0].Rows[0]["PatientName"].ToString() != "") { table.AddCell(new Phrase(Convert.ToString(ds.Tables[0].Rows[0]["PatientName"]), iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } else { table.AddCell(new Phrase("-", iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } table.AddCell(new Phrase("Case #", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK))); if (ds.Tables[0].Rows[0]["CaseNo"].ToString() != "") { table.AddCell(new Phrase(Convert.ToString(ds.Tables[0].Rows[0]["CaseNo"]), iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } else { table.AddCell(new Phrase("-", iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } table.AddCell(new Phrase("Insurance Name", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK))); if (ds.Tables[0].Rows[0]["SZ_INSURANCE_NAME"].ToString() != "") { table.AddCell(new Phrase(Convert.ToString(ds.Tables[0].Rows[0]["SZ_INSURANCE_NAME"]), iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } else { table.AddCell(new Phrase("-", iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } PdfPCell cell2 = new PdfPCell(new Phrase("")); cell2.Colspan = 2; cell2.BorderColor = Color.BLACK; table.AddCell(cell2); tblBase.AddCell(table); #endregion document.Add(tblBase); DataTable dt = ds.Tables[1]; string[] columns = { "SpecialtyID" }; DataTable dataTable = GetDistinctRecords(dt, columns); DataSet dsFiltered = new DataSet(); dsFiltered.Tables.Add(dataTable); #region for Visit Information float[] wd1 = { 3f, 1.5f, 1.5f, 1.5f, 1.5f, 6f, 1.5f, 3f }; PdfPTable tblVisit = new PdfPTable(wd1); tblVisit.WidthPercentage = 100; tblVisit.DefaultCell.BorderColor = Color.BLACK; tblVisit = GetTableHeader(wd1); float[] wdBlank = { 4f }; PdfPTable tblBlank = new PdfPTable(wdBlank); tblBlank.WidthPercentage = 100; tblBlank.DefaultCell.Border = Rectangle.NO_BORDER; tblBlank.AddCell(""); tblBlank.DefaultCell.Border = Rectangle.NO_BORDER; float[] wdNotes = { .5f, 3.5f }; PdfPTable tblNotes = new PdfPTable(wdNotes); tblNotes.WidthPercentage = 100; string text = ""; for (int i = 0; i < dsFiltered.Tables[0].Rows.Count; i++) { DataRow[] result = ds.Tables[1].Select("SpecialtyID = '" + dsFiltered.Tables[0].Rows[i]["SpecialtyID"].ToString() + "'"); for (int j = 0; j < result.Length; j++) { float fPosition = writer.GetVerticalPosition(true); if (result[j]["DctorName"].ToString() != "") { tblVisit.AddCell(new Phrase(Convert.ToString(result[j]["DctorName"].ToString()), iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } else { tblVisit.AddCell(new Phrase("-", iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } if (result[j]["DT_EVENT_DATE"].ToString() != "") { tblVisit.AddCell(new Phrase(Convert.ToString(result[j]["DT_EVENT_DATE"]), iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } else { tblVisit.AddCell(new Phrase("-", iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } if (result[j]["Specialty"].ToString() != "") { tblVisit.AddCell(new Phrase(Convert.ToString(result[j]["Specialty"]), iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } else { tblVisit.AddCell(new Phrase("-", iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } if (result[j]["STATUS"].ToString() != "") { tblVisit.AddCell(new Phrase(Convert.ToString(result[j]["STATUS"]), iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } else { tblVisit.AddCell(new Phrase("-", iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } if (result[j]["VisitType"].ToString() != "") { tblVisit.AddCell(new Phrase(Convert.ToString(result[j]["VisitType"]), iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } else { tblVisit.AddCell(new Phrase("-", iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } if (result[j]["ProcedureCode"].ToString() != "") { tblVisit.AddCell(new Phrase(Convert.ToString(result[j]["ProcedureCode"]), iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } else { tblVisit.AddCell(new Phrase("-", iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } if (result[j]["BillStatus"].ToString() != "") { tblVisit.AddCell(new Phrase(Convert.ToString(result[j]["BillStatus"]), iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } else { tblVisit.AddCell(new Phrase("-", iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } if (result[j]["Provider"].ToString() != "") { tblVisit.AddCell(new Phrase(Convert.ToString(result[j]["Provider"]), iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } else { tblVisit.AddCell(new Phrase("-", iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); } } for (int k = 0; k < oList.Count; k++) { if (dsFiltered.Tables[0].Rows[i]["SpecialtyID"].ToString() == oList[k].Speciality.ID.ToString()) { text = oList[k].Text.ToString(); tblNotes.FlushContent(); tblNotes.AddCell(new Phrase("NOTE:", iTextSharp.text.FontFactory.GetFont("Arial", 8, Font.BOLD, iTextSharp.text.Color.BLACK))); tblNotes.AddCell(new Phrase(text, iTextSharp.text.FontFactory.GetFont("Arial", 7, iTextSharp.text.Color.BLACK))); document.Add(tblBlank); if (text != "") { document.Add(tblNotes); } break; } } document.Add(tblVisit); document.Add(tblBlank); document.Add(tblBlank); tblVisit.DeleteBodyRows(); tblVisit = GetTableHeader(wd1); } #endregion document.Close(); System.IO.File.WriteAllBytes(pdfPath, m.GetBuffer()); OpenPdfFilepath = OpenFilepath + "PatientDeskNotes/" + newPdfFilename; } return(OpenPdfFilepath); }
private void setBillPageBody(iTextSharp.text.Document document, OPDHistoryModel model) { try { var boldTableFont = FontFactory.GetFont("verdana", Convert.ToInt32(ConfigurationManager.AppSettings["bodyboldTable11"]), iTextSharp.text.Font.BOLD); var bodyFontNormal = FontFactory.GetFont("verdana", Convert.ToInt32(ConfigurationManager.AppSettings["bodyboldTable12"]), iTextSharp.text.Font.NORMAL); var headerFont = FontFactory.GetFont("verdana", Convert.ToInt32(ConfigurationManager.AppSettings["headerFont"]), iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK); setBillPageHeader(document); //Patient Details PdfPTable table = new PdfPTable(2); table.DeleteBodyRows(); table.WidthPercentage = 100; table.HorizontalAlignment = 0; table.SpacingBefore = 5; table.SpacingAfter = 10; newCell(table, "Name : " + model.PatientDetails.FullName, boldTableFont, 0, 0); newCell(table, "Date. : " + model.InTime.Value.ToShortDateString(), boldTableFont, 2, 0); newCell(table, "O.P.D No. : " + model.CasePaperNumber, boldTableFont, 0, 0); newCell(table, "Receipt No. : " + new BillHistory().GetByOPDId(model.Id.Value).ReceiptNumber.ToString(), boldTableFont, 2, 0); document.Add(table); // Bill Details table = new PdfPTable(3); table.DeleteBodyRows(); table.WidthPercentage = 100; table.HorizontalAlignment = 0; table.SpacingBefore = 5; table.SpacingAfter = 10; newCell(table, "Received for ", boldTableFont, -1, -1, 2); newCell(table, "Rs", boldTableFont, 1, -1); int srNo = 1; newCell(table, srNo.ToString(), bodyFontNormal, 1, 4); newCell(table, "Conc. FEE. :", bodyFontNormal, 0, 8); PdfPCell cell = new PdfPCell(new Phrase(model.Amount.ToString(), bodyFontNormal)); cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.Border = PdfCell.LEFT_BORDER; cell.Border = PdfCell.RIGHT_BORDER; table.AddCell(cell); if (model.LabTestingAmount.HasValue && model.LabTestingAmount.Value != Convert.ToDecimal(0.00)) { srNo++; newCell(table, srNo.ToString(), bodyFontNormal, 1, 4); newCell(table, "Labarotry. FEE. ", bodyFontNormal, 0, 8); newCell(table, model.LabTestingAmount.ToString(), bodyFontNormal, 1, 8); } newCell(table, "Total", boldTableFont, 2, -1, 2); newCell(table, model.TotalAmount.ToString(), boldTableFont, 1, -1, 2); for (int i = 0; i < 5; i++) { blankCell(table, 3); } newCell(table, "Signature", boldTableFont, 2, 0, 3); table.SetWidths(new int[] { 1, 12, 6 }); document.Add(table); } catch (Exception ex) { throw ex; } }
private void PrintDetailRow(DataRow dataRow, PdfPTable table) { PdfPCell cell; numberOfRows++; if (dataRow.Table.Columns.Contains("colRefurb")) { cell = new PdfPCell(new Paragraph(Utilities.GetStringValue(dataRow["colRefurb"], ""), _reportFont)); cell.Border = Rectangle.NO_BORDER; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); } string pAssignmentType; try { pAssignmentType = dataRow["colAssignmentType"] != null?Utilities.GetStringValue(dataRow["colAssignmentType"], "") : ""; } catch (Exception) { pAssignmentType = ""; } cell = new PdfPCell(new Paragraph(Commons.GetPfiAssignmentAbbreviation(pAssignmentType), _reportFont)); cell.Border = Rectangle.NO_BORDER; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); cell = new PdfPCell(new Paragraph(Utilities.GetStringValue(dataRow["colNumber"], ""), _reportFont)); cell.Border = Rectangle.NO_BORDER; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); cell = new PdfPCell(new Paragraph(Utilities.GetStringValue(dataRow["colDescription"], ""), _reportFont)); cell.Border = Rectangle.NO_BORDER; cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.Colspan = 2;//10.7 NAM: Added this line of code was added to cater for BZ 1313 cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); //10.7 NAM: chunk of code below was commented out to cater for BZ 1313 /* * cell = new PdfPCell(new Paragraph(PawnUtilities.Utilities.GetStringValue(dataRow["colTags"], ""), _reportFont)); * cell.Border = Rectangle.NO_BORDER; * cell.HorizontalAlignment = Element.ALIGN_CENTER; * cell.VerticalAlignment = Element.ALIGN_TOP; * table.AddCell(cell);*/ cell = new PdfPCell(new Paragraph(Utilities.GetStringValue(dataRow["colCost"], ""), _reportFont)); cell.Border = Rectangle.NO_BORDER; cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); cell = new PdfPCell(new Paragraph(Utilities.GetStringValue(dataRow["colRetail"], ""), _reportFont)); cell.Border = Rectangle.NO_BORDER; cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); cell = new PdfPCell(new Paragraph(Utilities.GetStringValue(dataRow["colReason"], ""), _reportFont)); cell.Border = Rectangle.NO_BORDER; cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); float tableHeight = 0.0f; for (int i = 0; i < table.Rows.Count; i++) { tableHeight += table.GetRowHeight(i); } if (tableHeight > PageSize.LETTER.Height - 72) { rowNumbers.Add(numberOfRows); document.Add(table); numberOfRows = 0; table.DeleteBodyRows(); document.NewPage(); } }
private void PrintReportDetail() { int row = 1; int page = 1; PdfPTable table = new PdfPTable(9); foreach (TransferVO vo in _transferList) { if (row / page >= 30 || row == 1) { //Not the first page so have it go to a new page. if (row != 1) { _document.Add(table); table.DeleteBodyRows(); _document.NewPage(); //For Adding space on new page PdfPTable headerTable1 = new PdfPTable(9); PdfPCell containerCell1 = new PdfPCell(); AddTwoBlankRows(headerTable1, containerCell1, 4); _document.Add(headerTable1); table = new PdfPTable(9); page++; } //ADD HEADER FOR EACH TABLE PdfPCell cell; cell = new PdfPCell(new Paragraph("Number", _reportFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); cell = new PdfPCell(new Paragraph("Shop", _reportFont)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); cell = new PdfPCell(new Paragraph("Transfer Type", _reportFont)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); cell = new PdfPCell(new Paragraph("Status", _reportFont)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); cell = new PdfPCell(new Paragraph("Reject Transfers", _reportFont)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); cell = new PdfPCell(new Paragraph("Transfer Number", _reportFont)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); cell = new PdfPCell(new Paragraph("Date", _reportFont)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); cell = new PdfPCell(new Paragraph("Total#Items", _reportFont)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); cell = new PdfPCell(new Paragraph("Total Cost", _reportFont)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.VerticalAlignment = Element.ALIGN_TOP; table.AddCell(cell); } PrintDetailRow(vo, table, row); row++; } //Add the last table to the document. _document.Add(table); PdfPTable headerTable = new PdfPTable(9); /* containerCell = new PdfPCell(new Paragraph("BOLD = Transfer Items Over 14 days", _reportFontBold)); * containerCell.Border = Rectangle.NO_BORDER; * containerCell.Colspan = 9; * headerTable.AddCell(containerCell);*/ _document.Add(headerTable); }
public void miseEnForm(string typeDoc) { int incCopie = 0; int nbCopie = int.Parse(donneEntete["Nombre_copies"]); string cheminDocFinaux = ConfigurationManager.AppSettings["CheminDocFinaux"].ToString(); string cheminRessources = ConfigurationManager.AppSettings["CheminRessources"].ToString(); while (incCopie < nbCopie) { bool drapReliquat = false; string chemin = cheminDocFinaux + "\\DocFinaux\\BP\\BP_" + nomDoc + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"; Document nouveauDocument = new Document(PageSize.A4, 20, 20, 12, 20); PdfWriter.GetInstance(nouveauDocument, new FileStream(chemin, FileMode.Create)); //Stockage du document //---------------------------------------- //Constitution document PDF //---------------------------------------- nouveauDocument.Open(); PdfPTable tableau = new PdfPTable(2); tableau.TotalWidth = 550; tableau.LockedWidth = true; //-----------------Ajout Pattern/Image-------------------------------------------------------- Image image2 = Image.GetInstance(ConfigurationManager.AppSettings["CheminPatternHautDroiteBp"]); image2.Alignment = Image.UNDERLYING; image2.SetAbsolutePosition(325, 755); nouveauDocument.Add(image2); Image image5 = Image.GetInstance(ConfigurationManager.AppSettings["CheminFilligraneBp"]); image5.Alignment = Image.UNDERLYING; image5.SetAbsolutePosition(180, 270); nouveauDocument.Add(image5); //------------------------------------------------------------------------------------------------------ Paragraph pLogo = new Paragraph(); Image image = Image.GetInstance(ConfigurationManager.AppSettings["CheminLogoABCR"]); pLogo.Add(image); //Encadré photo PdfPCell celulleHauteGauche = new PdfPCell(image); celulleHauteGauche.Border = PdfPCell.NO_BORDER; tableau.AddCell(celulleHauteGauche); //Celulle de droite contenant l'adresse de livraison Paragraph pAdl = new Paragraph(); pAdl.Add(new Phrase("Adresse de livraison\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD))); if (donneEntete["Bon_typvte"] == "EMPORTEE") { pAdl.Add(new Phrase("EMPORTEE\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); /*pAdl.Add(new Phrase(donneEntete["Tiers_adl3"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); * pAdl.Add(new Phrase(donneEntete["Tiers_adl4"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); * pAdl.Add(new Phrase(donneEntete["Tiers_adl5"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); * pAdl.Add(new Phrase(donneEntete["Tiers_adlcp"] + " " + donneEntete["Tiers_adl6"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD)));*/ } else { if (donneEntete["Tiers_adl1"] == "") { pAdl.Add(new Phrase(donneEntete["Tiers_adf1"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase(donneEntete["Tiers_adf2"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase(donneEntete["Tiers_adf3"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase(donneEntete["Tiers_adf4"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); //pAdl.Add(new Phrase(donneEntete["Tiers_adf6"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase(donneEntete["Tiers_adfcp"] + " " + donneEntete["Tiers_adl6"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); } else { pAdl.Add(new Phrase(donneEntete["Tiers_adl1"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase(donneEntete["Tiers_adl2"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase(donneEntete["Tiers_adl3"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase(donneEntete["Tiers_adl4"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); //pAdl.Add(new Phrase(donneEntete["Tiers_adl5"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase(donneEntete["Tiers_adlcp"] + " " + donneEntete["Tiers_adl6"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); } } PdfPCell celulleFinDroite = new PdfPCell(pAdl); celulleFinDroite.Rowspan = 2; celulleFinDroite.Border = PdfPCell.NO_BORDER; celulleFinDroite.PaddingLeft = 35; tableau.AddCell(celulleFinDroite); //Adresse ABCR string tel = donneEntete["Adresse_interne_7"]; string fax = donneEntete["Adresse_interne_8"]; tel = tel.Substring(3, 15); fax = fax.Substring(3, 15); Paragraph p = new Paragraph(); p.Add(new Phrase(donneEntete["Adresse_interne_2"] + " Tél " + tel + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); p.Add(new Phrase(donneEntete["Adresse_interne_3"] + " Fax " + fax + "\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); PdfPCell celulleMilieuGauche = new PdfPCell(p); celulleMilieuGauche.Border = PdfPCell.NO_BORDER; tableau.AddCell(celulleMilieuGauche); //Tableau dans celulle bas gauche du tableau d'entete PdfPTable tabCell = new PdfPTable(3); tabCell.TotalWidth = 230; tabCell.LockedWidth = true; tabCell.AddCell(new Phrase("Client", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD))); tabCell.AddCell(new Phrase("Date", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD))); tabCell.AddCell(new Phrase("N° CDE", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD))); tabCell.AddCell(new Phrase(donneEntete["Client_code"], FontFactory.GetFont(FontFactory.HELVETICA, 9))); tabCell.AddCell(new Phrase(donneEntete["Document_date"], FontFactory.GetFont(FontFactory.HELVETICA, 9))); tabCell.AddCell(new Phrase(donneEntete["Document_numero"], FontFactory.GetFont(FontFactory.HELVETICA, 9))); tabCell.HorizontalAlignment = PdfPCell.ALIGN_LEFT; PdfPCell celulleBasGauche = new PdfPCell(tabCell); celulleBasGauche.Border = PdfPCell.NO_BORDER; tableau.AddCell(celulleBasGauche); //Adresse de facturation Paragraph pAdf = new Paragraph(); pAdf.Add(new Phrase("Adresse de facturation\n" + donneEntete["Tiers_adf1"], FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); PdfPCell celulleHauteDroite = new PdfPCell(pAdf); celulleHauteDroite.Border = PdfPCell.NO_BORDER; celulleHauteDroite.HorizontalAlignment = Element.ALIGN_LEFT; celulleHauteDroite.PaddingLeft = 35; tableau.AddCell(celulleHauteDroite); nouveauDocument.Add(tableau); //Récap ref client et numéro de téléphone Paragraph refCli = new Paragraph(); refCli.Add(new Phrase("Référence client " + donneeBody["Bon_rcl1"] + " du " + donneeBody["Bon_datrcl1"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); nouveauDocument.Add(refCli); //Recap dessus tableau //Condition de fonctionnement si dictionnaire contient clé commentaire ou non Chunk c; if (donneEntete.ContainsKey("Commentaire_texteentete")) { c = new Chunk("Vous avez été servi par : " + donneEntete["Bon_vendeur_lib"] + " Livrée le " + donneeBody["Bon_datliv1"] + " " + donneEntete["Commentaire_texteentete"] + "\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.ITALIC)); nouveauDocument.Add(c); Phrase pPage1; if (donneEntete.ContainsKey("Commentaire_texteentete0")) { pPage1 = new Phrase(donneEntete["Commentaire_texteentete0"] + " Page n° 1\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD)); } else { pPage1 = new Phrase(" " + donneEntete["Document_type"] + " " + donneEntete["Duplicata"] + " Page n° 1 \n\n", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD)); } nouveauDocument.Add(pPage1); } else { c = new Chunk("Vous avez été servi par : " + donneEntete["Bon_vendeur_lib"] + " Livrée le " + donneeBody["Bon_datliv1"] + "\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.ITALIC)); nouveauDocument.Add(c); Phrase pPage1; pPage1 = new Phrase(" " + donneEntete["Document_type"] + " " + donneEntete["Duplicata"] + " Page n° 1 \n\n", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD)); nouveauDocument.Add(pPage1); } //-------------------------------------------------------------------------------------------------------- // TABLEAU //--------------------------------------------------------------------------------------------------------- CurseurTemplate ct = new CurseurTemplate(); valeurTemplate = ct.chercher("BP"); float[] largeurs = { int.Parse(valeurTemplate["Dimension1"]), int.Parse(valeurTemplate["Dimension2"]), int.Parse(valeurTemplate["Dimension3"]), int.Parse(valeurTemplate["Dimension4"]), int.Parse(valeurTemplate["Dimension5"]) }; PdfPTable table = new PdfPTable(largeurs); table.TotalWidth = 555; //Chaque colonne crée ci dessus doit être rempli table.LockedWidth = true; PdfPCell cellET1 = new PdfPCell(new Phrase("Article", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET1.Border = PdfPCell.NO_BORDER; //cellET1.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET1); PdfPCell cellET2 = new PdfPCell(new Phrase("Désignation", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET2.Border = PdfPCell.NO_BORDER; //cellET2.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET2); PdfPCell cellET3 = new PdfPCell(new Phrase("UV", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET3.Border = PdfPCell.NO_BORDER; //cellET3.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET3); PdfPCell cellET4 = new PdfPCell(new Phrase("Quantité", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET4.Border = PdfPCell.NO_BORDER; //cellET4.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET4); PdfPCell cellET5 = new PdfPCell(new Phrase("Localisation", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET5.Border = PdfPCell.NO_BORDER; //cellET5.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET5); PdfPCell cellvideDebut = new PdfPCell(new Phrase(" ", FontFactory.GetFont(FontFactory.HELVETICA, 6, Font.BOLD))); cellvideDebut.Colspan = 5; cellvideDebut.Border = PdfPCell.NO_BORDER; table.AddCell(cellvideDebut); Image image3 = Image.GetInstance(ConfigurationManager.AppSettings["CheminPatternTableau"]); image3.Alignment = Image.UNDERLYING; image3.SetAbsolutePosition(20, 597); nouveauDocument.Add(image3); List <string> locPrecedent = new List <string>(); //Liste qui récupère les anciennes clés de localisation afin de ne pas les réintégrer au doc int i; int nbLigne = 0; float resultat = 0; float dimTab = 0; int décrement = 0; int numPage = 0; //Constitution du tableau d'article bool okDési = false; bool okStart = false; for (i = 1; i <= iBody; i++) { //Condition ARTICLE---------------------------------------------------------------------------------------------------------------------- if (donneeBody["Ligne_type" + i] == "ART") { nbLigne++; string sPattern = "libelle" + i + "bis"; PdfPCell cell1 = new PdfPCell(new Phrase(donneeBody["Art_code" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell1.Border = PdfPCell.NO_BORDER; cell1.Border += PdfPCell.RIGHT_BORDER; cell1.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell1); Paragraph pCell2 = new Paragraph(); PdfPCell cell2 = new PdfPCell(pCell2); cell2.Border = PdfPCell.NO_BORDER; cell2.Border += PdfPCell.RIGHT_BORDER; cell2.Border += PdfPCell.LEFT_BORDER; foreach (KeyValuePair <string, string> entry in donneeBody) { if (System.Text.RegularExpressions.Regex.IsMatch(entry.Key, sPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { if (System.Text.RegularExpressions.Regex.IsMatch(entry.Value, "Localisations secondaires", System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { } //Empeche de faire apparaitre la localisation secondaire dans la désignation else { if (okStart == false) { pCell2.Add(new Phrase(donneeBody["Libelle" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); string clé = entry.Key; if (donneeBody.ContainsKey("Art_lot" + i)) { pCell2.Add(new Phrase("Numéro de lot : " + donneeBody["Art_lot" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); } pCell2.Add(new Phrase(donneeBody[clé] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 7.5F, Font.BOLDITALIC))); okStart = true; } else { string clé = entry.Key; pCell2.Add(new Phrase(donneeBody[clé] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 7.5F, Font.BOLDITALIC))); } okDési = true; } } } if (okDési == false) { PdfPCell cell3 = new PdfPCell(new Phrase(donneeBody["Libelle" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell3.Border = PdfPCell.NO_BORDER; cell3.Border += PdfPCell.RIGHT_BORDER; cell3.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell3); } else { table.AddCell(cell2); } PdfPCell cell4 = new PdfPCell(new Phrase(donneeBody["Art_unite" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell4.Border = PdfPCell.NO_BORDER; cell4.Border += PdfPCell.RIGHT_BORDER; cell4.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell4); PdfPCell cell5 = new PdfPCell(new Phrase(donneeBody["Art_qte" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell5.Border = PdfPCell.NO_BORDER; cell5.Border += PdfPCell.RIGHT_BORDER; cell5.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell5); bool drapLoc = false; string reliquat = ""; foreach (KeyValuePair <string, string> entry in donneeBody) { //string patternReliquat = "Art_reliquat"; if (donneeBody.ContainsKey("Art_reliquat" + i)) { reliquat = "Reliquat"; drapReliquat = true; } //Condition si l'article à une loca secondaire if (drapLoc == false && locPrecedent.Contains(entry.Key) == false && System.Text.RegularExpressions.Regex.IsMatch(entry.Value, "Localisations secondaires", System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { string rackSub = donneeBody[entry.Key]; rackSub = rackSub.Substring(27, 2); string etagereSub = donneeBody[entry.Key]; etagereSub = etagereSub.Substring(29, 2); PdfPCell cell6 = new PdfPCell(new Phrase("Zone : " + donneeBody["Art_localisation" + i] + " Rack : " + rackSub + " Etagère : " + etagereSub + " /n" + reliquat, FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell6.Border = PdfPCell.NO_BORDER; cell6.Border += PdfPCell.LEFT_BORDER; cell6.Border += PdfPCell.RIGHT_BORDER; table.AddCell(cell6); okStart = true; drapLoc = true; reliquat = ""; locPrecedent.Add(entry.Key); } //Si il n'en a pas, afficher uniquement la zone if (drapLoc == false && locPrecedent.Contains(entry.Key) == false && donneeBody["Art_type_cde" + i] != "S" && donneeBody["Art_type_cde" + i] != "D") { PdfPCell cell6 = new PdfPCell(new Phrase("Zone : " + donneeBody["Art_localisation" + i] + " " + reliquat, FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell6.Border = PdfPCell.NO_BORDER; cell6.Border += PdfPCell.LEFT_BORDER; cell6.Border += PdfPCell.RIGHT_BORDER; table.AddCell(cell6); okStart = true; drapLoc = true; reliquat = ""; locPrecedent.Add(entry.Key); } //Condition si article est spécial, pas de localisation if (drapLoc == false && locPrecedent.Contains(entry.Key) == false && donneeBody["Art_type_cde" + i] == "S") { PdfPCell cell6 = new PdfPCell(new Phrase("Spécial" + " " + reliquat, FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell6.Border = PdfPCell.NO_BORDER; cell6.Border += PdfPCell.LEFT_BORDER; cell6.Border += PdfPCell.RIGHT_BORDER; table.AddCell(cell6); okStart = true; drapLoc = true; reliquat = ""; locPrecedent.Add(entry.Key); } //Condition si article est direct, pas de localisation if (drapLoc == false && locPrecedent.Contains(entry.Key) == false && donneeBody["Art_type_cde" + i] == "D") { PdfPCell cell6 = new PdfPCell(new Phrase("Direct" + " " + reliquat, FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell6.Border = PdfPCell.NO_BORDER; cell6.Border += PdfPCell.LEFT_BORDER; cell6.Border += PdfPCell.RIGHT_BORDER; table.AddCell(cell6); okStart = true; drapLoc = true; reliquat = ""; locPrecedent.Add(entry.Key); } } if (drapLoc == false) { PdfPCell cell7 = new PdfPCell(new Phrase(" ", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell7.Border = PdfPCell.NO_BORDER; cell7.Border += PdfPCell.LEFT_BORDER; cell7.Border += PdfPCell.RIGHT_BORDER; table.AddCell(cell7); } okDési = false; okStart = false; drapLoc = false; } //Condition COMMENTAIRE-------------------------------------------------------------------------------------------------------------------------------- if (donneeBody["Ligne_type" + i] == "COM") { nbLigne++; PdfPCell cellVide = new PdfPCell(new Phrase("" + "\n")); PdfPCell cell = new PdfPCell(new Phrase(donneeBody["Libelle" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); PdfPCell cellFin = new PdfPCell(); cellVide.Border = PdfPCell.NO_BORDER; cellVide.Border += PdfPCell.RIGHT_BORDER; cellVide.Border += PdfPCell.LEFT_BORDER; cell.Border = PdfPCell.NO_BORDER; cell.Border += PdfPCell.RIGHT_BORDER; cell.Border += PdfPCell.LEFT_BORDER; cellFin.Border = PdfPCell.NO_BORDER; cellFin.Border += PdfPCell.LEFT_BORDER; cellFin.Border += PdfPCell.RIGHT_BORDER; table.AddCell(cellVide); table.AddCell(cell); table.AddCell(cellVide); table.AddCell(cellVide); table.AddCell(cellFin); } // PdfPCell cellEcartDroite = new PdfPCell(new Phrase(" " + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 2, Font.BOLD))); PdfPCell cellEcart = new PdfPCell(new Phrase(" " + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 2, Font.BOLD))); cellEcart.Border = PdfPCell.NO_BORDER; cellEcart.Border += PdfPCell.LEFT_BORDER; cellEcart.Border += PdfPCell.RIGHT_BORDER; cellEcartDroite.Border = PdfPCell.NO_BORDER; cellEcartDroite.Border += PdfPCell.RIGHT_BORDER; cellEcartDroite.Border += PdfPCell.LEFT_BORDER; table.AddCell(cellEcartDroite); table.AddCell(cellEcart); table.AddCell(cellEcart); table.AddCell(cellEcart); table.AddCell(cellEcart); //--------------------------------------------GESTION DU SAUT DE PAGE------------------------------------------------------------------------------------------- float temp = table.TotalHeight; dimTab = temp; if (dimTab >= 410 && i < iBody) { //Saut de page numPage++; PdfPCell cellFin = new PdfPCell(new Phrase(" ")); PdfPCell cellBlanche = new PdfPCell(new Phrase(" ")); PdfPCell cellBlancheD = new PdfPCell(new Phrase(" ")); cellFin.Colspan = 5; cellBlanche.FixedHeight = (450 - dimTab); cellBlanche.Border = PdfPCell.NO_BORDER; cellBlanche.Border += PdfPCell.RIGHT_BORDER; cellBlanche.Border += PdfPCell.LEFT_BORDER; cellBlancheD.FixedHeight = (450 - dimTab); cellBlancheD.Border = PdfPCell.NO_BORDER; cellBlancheD.Border += PdfPCell.LEFT_BORDER; cellBlancheD.Border += PdfPCell.RIGHT_BORDER; cellFin.Border = PdfPCell.NO_BORDER; cellFin.Border += PdfPCell.TOP_BORDER; table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlancheD); table.AddCell(cellFin); nouveauDocument.Add(table);//----------------------------------------------------------------------------Repère ligne en dessous-------------------------------------------------- Phrase pReport = new Phrase(" A REPORTER\n\n\n\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD)); Phrase pPage; if (donneEntete.ContainsKey("Commentaire_texteentete0")) { pPage = new Phrase(donneEntete["Commentaire_texteentete0"] + " Page n° " + (numPage + 1) + "\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD)); } else { pPage = new Phrase(" Page n° " + (numPage + 1) + "\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD)); } nouveauDocument.Add(pReport); table.DeleteBodyRows(); nouveauDocument.Add(Chunk.NEXTPAGE); nouveauDocument.Add(tableau); //nouveauDocument.Add(p); nouveauDocument.Add(refCli); nouveauDocument.Add(c); nouveauDocument.Add(pPage); nouveauDocument.Add(image2); nouveauDocument.Add(image3); nouveauDocument.Add(image5); table.AddCell(cellET1); table.AddCell(cellET2); table.AddCell(cellET3); table.AddCell(cellET4); table.AddCell(cellET5); table.AddCell(cellvideDebut); dimTab = 0; décrement = (i - 1); } } //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //------------------------------------------------------------------- if (i > iBody) { PdfPCell cellFin = new PdfPCell(new Phrase(" ")); PdfPCell cellBlanche = new PdfPCell(new Phrase(" ")); PdfPCell cellBlancheD = new PdfPCell(new Phrase(" ")); cellFin.Colspan = 5; resultat = 450 - dimTab; //<<----------450 correspond au nombre de point de la longueur du tableau, c'est la valeur à modifier pour modifier la taille du tableau cellBlanche.FixedHeight = resultat; cellBlanche.Border = PdfPCell.NO_BORDER; cellBlanche.Border += PdfPCell.RIGHT_BORDER; cellBlanche.Border += PdfPCell.LEFT_BORDER; cellBlancheD.FixedHeight = resultat; cellBlancheD.Border = PdfPCell.NO_BORDER; cellBlancheD.Border += PdfPCell.LEFT_BORDER; cellBlancheD.Border += PdfPCell.RIGHT_BORDER; cellFin.Border = PdfPCell.NO_BORDER; cellFin.Border += PdfPCell.TOP_BORDER; table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlancheD); table.AddCell(cellFin); } nouveauDocument.Add(table); //----------------------------------------Gestion des commentaires de bon------------------------------------- if (donneEntete.ContainsKey("Commentaire_texte")) { Paragraph pComBon = new Paragraph(new Phrase(" " + donneEntete["Commentaire_texte"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); nouveauDocument.Add(pComBon); } nouveauDocument.Close(); incCopie++; //Copie Doc dans GED try { String connectionString = ConfigurationManager.AppSettings["ChaineDeConnexionBase"]; OdbcConnection conn = new OdbcConnection(connectionString); conn.Open(); string requete = "select T1.NOCLI c1 , T1.NOMCL c2 from B00C0ACR.AMAGESTCOM.ACLIENL1 T1 where T1.NOCLI = '" + donneEntete["Client_code"] + "'"; OdbcCommand act = new OdbcCommand(requete, conn); OdbcDataReader act0 = act.ExecuteReader(); string nomADH = ""; while (act0.Read()) { nomADH = (act0.GetString(1)); } conn.Close(); if (!System.IO.Directory.Exists(ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneEntete["Client_code"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM") + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\BP\\")) { System.IO.Directory.CreateDirectory(ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneEntete["Client_code"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\BP\\"); System.IO.File.Copy(chemin, ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneEntete["Client_code"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\BP\\" + "\\BP_" + nomDoc + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"); } else { System.IO.File.Copy(chemin, ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneEntete["Client_code"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\BP\\" + "\\BP_" + nomDoc + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"); } } catch (Exception e) { LogHelper.WriteToFile(e.Message, "ENVOI GED BP"); } //--------------------------------------------------------FIN COPIE------------------------------------------------------ #region ImpressionOld /*myPrinters.SetDefaultPrinter("Imp204"); * Process proc = new Process(); * proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; * proc.StartInfo.Verb = "print"; * * //Define location of adobe reader/command line * //switches to launch adobe in "print" mode * proc.StartInfo.FileName = * @"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe"; * proc.StartInfo.Arguments = String.Format(@"/p /h {0}", chemin); * proc.StartInfo.UseShellExecute = false; * proc.StartInfo.CreateNoWindow = true; * * proc.Start(); * proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; * if (proc.HasExited == false) * { * proc.WaitForExit(10000); * } * * proc.EnableRaisingEvents = true; * * proc.Close(); * foreach (Process clsProcess in Process.GetProcesses().Where( * clsProcess => clsProcess.ProcessName.StartsWith("AcroRd32"))) * { * clsProcess.Kill(); * }*/ #endregion //Solution d'impression fonctionnel, API payante---------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------------------------- //----------------Expérimentation, ATTENTION FRAMEWORK EN 4.5--------------------------- int nbImp = 0; int nbImpOK = 0; string[] printer = new string[20]; // tableau qui contient les imprimantes du profil d'impression ProfilImprimante profil = new ProfilImprimante(); profil.chargementXML("BP"); // chargement selon le type de doc string vendeur = ""; try { vendeur = unProfil.Substring(2, 3); } catch { vendeur = unProfil.Substring(2, 2); } vendeur = vendeur.TrimEnd(); var listeProfil = profil.getDonneeProfil(); try { if (drapReliquat) { printer[nbImp] = ConfigurationManager.AppSettings["ImpDefBL"]; nbImp++; } else { foreach (string v in listeProfil[vendeur]) //lecture des imprimantes liée à un profil { printer[nbImp] = v.ToString(); nbImp++; //on incrémente le nombre d'impression à executer } } } catch (Exception e) { LogHelper.WriteToFile(e.Message, "Erreur attribution imprimante par profil " + unProfil.ToString()); printer[nbImp] = "Imp211"; //Imprimante par defaut (essai) nbImp++; } nbImp = nbImp - 1; while (nbImpOK <= nbImp) // boucle tant que le nombre d'impression fait n'à pas atteint le nombre d'impression demander { string printerName = printer[nbImpOK]; string inputFile = String.Format(@"{0}", chemin); try { //Envoi de l'ordre d'impression vers l'imprimante, les "switches" sont des arguments de la ligne de script "processor" de type GhostscriptProcessor using (GhostscriptProcessor processor = new GhostscriptProcessor()) { List <string> switches = new List <string>(); switches.Add("-empty"); switches.Add("-dPrinted"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOSAFER"); switches.Add("-dNumCopies=1"); switches.Add("-sDEVICE=ljet4"); switches.Add("-sOutputFile=%printer%" + printerName); switches.Add("-f"); switches.Add(inputFile); processor.StartProcessing(switches.ToArray(), null); } nbImpOK++; } catch (Exception e) { LogHelper.WriteToFile(e.Message, "ParseurBP" + donneEntete["Document_numero"].Trim()); } // incrément à chaque impression terminée } } }
public void Create(Bestelbon bestelbon, User CurrentnUser, FileStream fs) { Document document = new Document(PageSize.A4, 25, 25, 30, 30); // Margin Left, Margin Right, Margin Top , Margin Bottom PdfWriter writer = PdfWriter.GetInstance(document, fs); writer.PageEvent = new Footer(); document.Open(); PageFillLevel = 0.0f; FontFactory.Register("c:/windows/fonts/SegoeUI.ttf", "SegoeUI"); Font Segoe08 = FontFactory.GetFont("SegoeUI", 8F); Font Segoe10 = FontFactory.GetFont("SegoeUI", 10F); Font Segoe12 = FontFactory.GetFont("SegoeUI", 12F); Font Segoe14 = FontFactory.GetFont("SegoeUI", 14F); Font Segoe16 = FontFactory.GetFont("SegoeUI", 16F); Font Segoe18 = FontFactory.GetFont("SegoeUI", 18F); Font Segoe20 = FontFactory.GetFont("SegoeUI", 20F); Font Segoe24 = FontFactory.GetFont("SegoeUI", 24F); BaseColor LightGray = new BaseColor(192, 192, 192, 64); #region FIRST LAYER Image img = Image.GetInstance("D:/Desktop/Bestelbons/LOGOORANGE.png"); img.ScaleToFit(150, 150); img.SetAbsolutePosition(70.0f, 680.0f); document.Add(img); #endregion #region SECOND LAYER // ADRESS REGION ASTRATEC PdfPTable Adresstable = new PdfPTable(5); Adresstable.DefaultCell.Border = PdfPCell.RIGHT_BORDER; Adresstable.SetWidths(new float[] { 1.5f, 1f, 1f, 1f, 1.7f }); Adresstable.WidthPercentage = 100; Adresstable.HorizontalAlignment = Element.ALIGN_LEFT; Paragraph pEmpty = new Paragraph("", Segoe14); PdfPCell cellEmpty = new PdfPCell(pEmpty); cellEmpty.Border = PdfPCell.NO_BORDER; Paragraph pFirma = new Paragraph(" ASTRA-TEC BVBA", Segoe24); PdfPCell cellFirma = new PdfPCell(pFirma); cellFirma.Colspan = 3; cellFirma.Border = PdfPCell.NO_BORDER; Adresstable.AddCell(cellFirma); Adresstable.AddCell(cellEmpty); Paragraph pDatum = new Paragraph(DateTime.Now.ToString(), Segoe10); PdfPCell datumCell = new PdfPCell(pDatum); datumCell.Border = PdfPCell.NO_BORDER; datumCell.HorizontalAlignment = Element.ALIGN_RIGHT; datumCell.VerticalAlignment = Element.ALIGN_BOTTOM; Adresstable.AddCell(datumCell); Paragraph pStraat = new Paragraph("Industrielaan", Segoe12); PdfPCell cellStraat = new PdfPCell(pStraat); cellStraat.Border = PdfPCell.NO_BORDER; cellStraat.HorizontalAlignment = Element.ALIGN_LEFT; Adresstable.AddCell(cellStraat); Paragraph pNummer = new Paragraph("19", Segoe12); PdfPCell cellNummer = new PdfPCell(pNummer); cellNummer.Border = PdfPCell.NO_BORDER; cellNummer.HorizontalAlignment = Element.ALIGN_RIGHT; Adresstable.AddCell(cellNummer); Adresstable.AddCell(cellEmpty); Adresstable.AddCell(cellEmpty); Adresstable.AddCell(cellEmpty); Paragraph pPostCode = new Paragraph("8810", Segoe12); PdfPCell cellPostCode = new PdfPCell(pPostCode); cellPostCode.Border = PdfPCell.NO_BORDER; cellPostCode.HorizontalAlignment = Element.ALIGN_LEFT; Adresstable.AddCell(cellPostCode); Paragraph pStad = new Paragraph("Lichtervelde", Segoe12); PdfPCell cellStad = new PdfPCell(pStad); cellStad.Border = PdfPCell.NO_BORDER; cellStad.HorizontalAlignment = Element.ALIGN_RIGHT; Adresstable.AddCell(cellStad); Adresstable.AddCell(cellEmpty); Adresstable.AddCell(cellEmpty); Adresstable.AddCell(cellEmpty); Paragraph pBTWnr = new Paragraph("BE 0455.138.549", Segoe12); PdfPCell cellBTWnr = new PdfPCell(pBTWnr); cellBTWnr.Border = PdfPCell.NO_BORDER; cellBTWnr.HorizontalAlignment = Element.ALIGN_LEFT; Adresstable.AddCell(cellBTWnr); Adresstable.AddCell(cellEmpty); Adresstable.AddCell(cellEmpty); Adresstable.AddCell(cellEmpty); Paragraph pContact = new Paragraph("Contact : ", Segoe12); PdfPCell contactCell = new PdfPCell(pContact); contactCell.Border = PdfPCell.NO_BORDER; contactCell.HorizontalAlignment = Element.ALIGN_RIGHT; Adresstable.AddCell(contactCell); Paragraph pTEL = new Paragraph("+32 (0) 51 72 24 46", Segoe12); PdfPCell cellTEL = new PdfPCell(pTEL); cellTEL.Border = PdfPCell.NO_BORDER; cellTEL.HorizontalAlignment = Element.ALIGN_LEFT; Adresstable.AddCell(cellTEL); Adresstable.AddCell(cellEmpty); Adresstable.AddCell(cellEmpty); Adresstable.AddCell(cellEmpty); Paragraph pUser = new Paragraph(CurrentnUser.Email, Segoe12); PdfPCell userCell = new PdfPCell(pUser); userCell.Border = PdfPCell.NO_BORDER; userCell.Colspan = 2; userCell.HorizontalAlignment = Element.ALIGN_RIGHT; Adresstable.AddCell(userCell); Chunk chunkWWW = new Chunk("www.astratec.be"); chunkWWW.SetAnchor("http://www.astratec.be"); Paragraph pWWW = new Paragraph(); pWWW.Add(chunkWWW); PdfPCell cellWWW = new PdfPCell(pWWW); cellWWW.Colspan = 2; cellWWW.Border = PdfPCell.NO_BORDER; cellWWW.HorizontalAlignment = Element.ALIGN_LEFT; Adresstable.AddCell(cellWWW); Adresstable.AddCell(cellEmpty); Adresstable.AddCell(cellEmpty); Paragraph pUsertel = new Paragraph(CurrentnUser.Tel, Segoe12); PdfPCell usertelCell = new PdfPCell(pUsertel); usertelCell.Border = PdfPCell.NO_BORDER; usertelCell.HorizontalAlignment = Element.ALIGN_RIGHT; Adresstable.AddCell(usertelCell); PageFillLevel += CalculatePdfPTableHeight(Adresstable); Adresstable.SpacingBefore = 15f; Adresstable.SpacingAfter = 30f; PageFillLevel += 45; // 15 + 30 as the previous set SpacingBefore and SpacingAfter document.Add(Adresstable); Paragraph pBESTELBON = new Paragraph(" BESTELBON", Segoe24); pBESTELBON.SpacingAfter = 10f; PageFillLevel += 10; // 15 + 30 as the previous set SpacingAfter document.Add(pBESTELBON); document.Add(new Paragraph("Leverancier : " + bestelbon.Leverancier.Name.ToString(), Segoe12)); float[] widthstable = { 1.5f, 1f, 15f, 2f, 2f }; PdfPTable table = new PdfPTable(widthstable); table.DefaultCell.Border = PdfPCell.NO_BORDER; table.WidthPercentage = 100; int j = 0; bool grayfill = false; foreach (Bestelbonregel regel in bestelbon.Bestelbonregels) { if (j % 2 == 0) { grayfill = true; } else { grayfill = false; } Paragraph pAantal = new Paragraph(regel.Aantal.ToString(), Segoe12); PdfPCell cellAantal = new PdfPCell(pAantal); cellAantal.Border = PdfPCell.NO_BORDER; cellAantal.FixedHeight = 16f; if (grayfill) { cellAantal.BackgroundColor = LightGray; } table.AddCell(cellAantal); Paragraph pEenheid = new Paragraph(regel.Eenheid.ToString(), Segoe08); PdfPCell cellEenheid = new PdfPCell(pEenheid); cellEenheid.Border = PdfPCell.NO_BORDER; cellEenheid.PaddingTop = 7f; cellEenheid.VerticalAlignment = Element.ALIGN_TOP; if (grayfill) { cellEenheid.BackgroundColor = LightGray; } table.AddCell(cellEenheid); Paragraph pBestelregel = new Paragraph(regel.Bestelregel.ToString(), Segoe12); PdfPCell cellBestelregel = new PdfPCell(pBestelregel); cellBestelregel.Border = PdfPCell.NO_BORDER; if (grayfill) { cellBestelregel.BackgroundColor = LightGray; } table.AddCell(cellBestelregel); Paragraph pPrice = new Paragraph(regel.Prijs.ToString("0000.00").TrimStart('0'), Segoe12); PdfPCell cellPrice = new PdfPCell(pPrice); cellPrice.HorizontalAlignment = Element.ALIGN_RIGHT; cellPrice.Border = PdfPCell.NO_BORDER; if (grayfill) { cellPrice.BackgroundColor = LightGray; } table.AddCell(cellPrice); Paragraph pTotalPrice = new Paragraph(regel.TotalePrijs.ToString("0000.00").TrimStart('0'), Segoe12); PdfPCell cellTotalPrice = new PdfPCell(pTotalPrice); cellTotalPrice.HorizontalAlignment = Element.ALIGN_RIGHT; cellTotalPrice.Border = PdfPCell.NO_BORDER; if (grayfill) { cellTotalPrice.BackgroundColor = LightGray; } table.AddCell(cellTotalPrice); j++; PageFillLevel += 16; // cellAantal.FixedHeight = 16f; if (PageFillLevel >= 872 - 225 - 60 - 60) // 2e 60 is Top and bottom margin of Page !! { table.SpacingBefore = 30f; document.Add(table); document.NewPage(); // Opmerkingen en Handtekening tabellen zijn 225 hoog + A4 size is 872 !! + 60 spacing after en before ! PageFillLevel = 0; table.DeleteBodyRows(); } } table.SpacingBefore = 30f; PageFillLevel += 30; table.SpacingAfter = 30f; PageFillLevel += 30; document.Add(table); Paragraph pTotaal = new Paragraph(" TOTAAL : " + bestelbon.TotalPrice.ToString("0000.00").TrimStart('0'), Segoe14); pTotaal.SpacingAfter = 20f; PageFillLevel += 34; // 20 as the previous set SpacingAfter + 14 for the TOTAAL string document.Add(pTotaal); // TABLE MET OPMERKINGEN PdfPTable Opmerkingentable = new PdfPTable(2); Opmerkingentable.DefaultCell.Border = PdfPCell.NO_BORDER; Opmerkingentable.SetWidths(new float[] { 30.0f, 0.5f }); Opmerkingentable.WidthPercentage = 100; Opmerkingentable.HorizontalAlignment = Element.ALIGN_CENTER; Paragraph pOpmerkingText = new Paragraph("Opmerking", Segoe12); PdfPCell celllev1 = new PdfPCell(pOpmerkingText); celllev1.FixedHeight = 20f; celllev1.HorizontalAlignment = Element.ALIGN_LEFT; celllev1.Border = PdfPCell.NO_BORDER; Opmerkingentable.AddCell(celllev1); Opmerkingentable.AddCell(cellEmpty); Paragraph pOpmerking = new Paragraph(bestelbon.Opmerking, Segoe08); PdfPCell celllev2 = new PdfPCell(pOpmerking); celllev2.FixedHeight = 20f; celllev2.HorizontalAlignment = Element.ALIGN_LEFT; celllev2.Border = PdfPCell.NO_BORDER; Opmerkingentable.AddCell(celllev2); Opmerkingentable.AddCell(cellEmpty); Opmerkingentable.SpacingAfter = 10f; PageFillLevel += 10; // 10 as the previous set SpacingAfter document.Add(Opmerkingentable); PageFillLevel += CalculatePdfPTableHeight(Opmerkingentable); if (PageFillLevel >= 872 - 115 - 60) // 60 is Top and bottom margin of Page !! { document.NewPage(); // 115 = height of handtekeningenTABLE !! PageFillLevel = 0; } // TABLE MET LEVERINGSVOORWAARDEN EN HANDTEKENING PdfPTable Leveringsvwdntable = new PdfPTable(3); Leveringsvwdntable.DefaultCell.Border = PdfPCell.NO_BORDER; Leveringsvwdntable.SetWidths(new float[] { 3.0f, 0.5f, 0.5f }); Leveringsvwdntable.WidthPercentage = 100; Leveringsvwdntable.HorizontalAlignment = Element.ALIGN_CENTER; Paragraph pLeveringsvoorwaardenText = new Paragraph("Leveringsvoorwaarden", Segoe12); PdfPCell cell1 = new PdfPCell(pLeveringsvoorwaardenText); cell1.Border = PdfPCell.NO_BORDER; cell1.FixedHeight = 20f; cell1.HorizontalAlignment = Element.ALIGN_LEFT; Leveringsvwdntable.AddCell(cell1); Paragraph pVoorAkkoordText = new Paragraph("Voor Akkoord", Segoe12); PdfPCell cell2 = new PdfPCell(pVoorAkkoordText); cell2.Colspan = 2; cell2.Border = PdfPCell.NO_BORDER; cell2.FixedHeight = 20f; cell2.HorizontalAlignment = Element.ALIGN_CENTER; Leveringsvwdntable.AddCell(cell2); Paragraph pLeveeringsvoorwaarden = new Paragraph(bestelbon.Leveringsvoorwaarden, Segoe08); PdfPCell cell3 = new PdfPCell(pLeveeringsvoorwaarden); cell3.Rowspan = 2; cell3.Border = PdfPCell.NO_BORDER; cell3.HorizontalAlignment = Element.ALIGN_LEFT; Leveringsvwdntable.AddCell(cell3); Paragraph pLastName = new Paragraph(CurrentnUser.LastName, Segoe10); PdfPCell cell4 = new PdfPCell(pLastName); cell4.Border = PdfPCell.NO_BORDER; cell4.HorizontalAlignment = Element.ALIGN_CENTER; cell4.FixedHeight = 20f; Leveringsvwdntable.AddCell(cell4); Paragraph pFirstName = new Paragraph(CurrentnUser.FirstName, Segoe10); PdfPCell cell5 = new PdfPCell(pFirstName); cell5.Border = PdfPCell.NO_BORDER; cell5.HorizontalAlignment = Element.ALIGN_CENTER; cell5.FixedHeight = 20f; Leveringsvwdntable.AddCell(cell5); Image sigimage = Image.GetInstance(CurrentnUser.Handtekening); sigimage.ScaleToFit(75.0f, 75.0f); PdfPCell sig = new PdfPCell(sigimage); sig.Border = PdfPCell.NO_BORDER; sig.Colspan = 2; sig.HorizontalAlignment = Element.ALIGN_CENTER; Leveringsvwdntable.AddCell(sig); document.Add(Leveringsvwdntable); PageFillLevel += CalculatePdfPTableHeight(Leveringsvwdntable); int NumberOfPages = writer.PageNumber; #endregion document.Close(); writer.Close(); }
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.CloseStream = false; document.Open(); PdfContentByte cb = writer.DirectContent; //set content configuration BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED); BaseFont bf_bold = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED); 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); Font bold_font_8 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font font_9 = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9); DateTime now = DateTime.Now; float margin = 10; float printedOnHeight = 10; float startY = 840 - margin; #region Header cb.BeginText(); cb.SetFontAndSize(bf, 10); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "PT. DANLIRIS", 10, 820, 0); cb.SetFontAndSize(bf_bold, 12); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "RO EKSPOR GARMENT", 10, 805, 0); cb.EndText(); #endregion #region Top 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("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("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.AddHours(offset).ToString("dd MMMM yyyy")}", 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.Description}", 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); byte[] imageByte; try { imageByte = Convert.FromBase64String(Base64.GetBase64File(viewModel.CostCalculationGarment.ImageFile)); } catch (Exception) { var webClient = new WebClient(); imageByte = webClient.DownloadData("http://babakunyho.eu/img/default-no-image.png"); } 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; image.SetAbsolutePosition(520, imageY); cb.AddImage(image, inlineImage: true); table_top.WriteSelectedRows(0, -1, 10, row1Y, cb); #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); float row1Height = image.ScaledHeight > table_top.TotalHeight ? image.ScaledHeight : table_top.TotalHeight; float rowYTittleFab = row1Y - row1Height - 10; float allowedRow2Height = rowYTittleFab - printedOnHeight - margin; table_fabric_top.WriteSelectedRows(0, -1, 10, rowYTittleFab, cb); //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 }; float rowYFab = rowYTittleFab - table_fabric_top.TotalHeight - 5; float allowedRow2HeightFab = rowYFab - printedOnHeight - margin; //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.WriteSelectedRows(0, -1, 10, rowYFab, cb); #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); float rowYTittleAcc = rowYFab - table_fabric.TotalHeight - 10; float allowedRow2HeightTopAcc = rowYTittleFab - printedOnHeight - margin; table_acc_top.WriteSelectedRows(0, -1, 10, rowYTittleAcc, cb); //Main Accessories Table PdfPTable table_accessories = new PdfPTable(8); table_accessories.TotalWidth = 570f; float[] accessories_widths = new float[] { 5f, 5f, 5f, 5f, 5f, 5f, 5f, 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 }; float rowYAcc = rowYTittleAcc - table_fabric_top.TotalHeight - 5; float allowedRow2HeightAcc = rowYAcc - printedOnHeight - margin; //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_fabric_center.Phrase = new Phrase("COMPOSITION", bold_font); table_accessories.AddCell(cell_fabric_center); cell_fabric_center.Phrase = new Phrase("CONSTRUCTION", bold_font); table_accessories.AddCell(cell_fabric_center); cell_fabric_center.Phrase = new Phrase("YARN", bold_font); table_accessories.AddCell(cell_fabric_center); cell_fabric_center.Phrase = new Phrase("WIDTH", 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.Product.Composition, normal_font); table_accessories.AddCell(cell_acc_left); cell_acc_left.Phrase = new Phrase(materialModel.Product.Const, normal_font); table_accessories.AddCell(cell_acc_left); cell_acc_left.Phrase = new Phrase(materialModel.Product.Yarn, normal_font); table_accessories.AddCell(cell_acc_left); cell_acc_left.Phrase = new Phrase(materialModel.Product.Width, 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.WriteSelectedRows(0, -1, 10, rowYAcc, cb); #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); float rowYTittleBreakDown = rowYAcc - table_accessories.TotalHeight - 10; float allowedRow2HeightBreakdown = rowYTittleBreakDown - printedOnHeight - margin; table_breakdown_top.WriteSelectedRows(0, -1, 10, rowYTittleBreakDown, cb); //Main Table Size Breakdown PdfPTable table_breakDown = new PdfPTable(2); table_breakDown.TotalWidth = 570f; float[] breakDown_widths = new float[] { 5f, 10f }; 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 }; float rowYbreakDown = rowYTittleBreakDown - table_breakdown_top.TotalHeight - 5; float allowedRow2HeightBreakDown = rowYbreakDown - printedOnHeight - margin; var remainingRowToHeightBrekdown = rowYbreakDown - 5 - printedOnHeight - margin; 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[] { 5f, 5f, 5f }; 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_child.WriteSelectedRows(0, -1, 10, 0, cb); table_breakDown.AddCell(table_breakDown_child); } var tableBreakdownCurrentHeight = table_breakDown.TotalHeight; if (tableBreakdownCurrentHeight / remainingRowToHeightBrekdown > 1) { if (tableBreakdownCurrentHeight / allowedRow2HeightBreakDown > 1) { PdfPRow headerRow = table_breakDown.GetRow(0); PdfPRow lastRow = table_breakDown.GetRow(table_breakDown.Rows.Count - 1); table_breakDown.DeleteLastRow(); table_breakDown.WriteSelectedRows(0, -1, 10, rowYbreakDown, cb); table_breakDown.DeleteBodyRows(); this.DrawPrintedOn(now, bf, cb); document.NewPage(); table_breakDown.Rows.Add(headerRow); table_breakDown.Rows.Add(lastRow); table_breakDown.CalculateHeights(true); rowYbreakDown = startY; remainingRowToHeightBrekdown = rowYbreakDown - 5 - printedOnHeight - margin; allowedRow2HeightBreakDown = remainingRowToHeightBrekdown - printedOnHeight - margin; } } } 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.WriteSelectedRows(0, -1, 10, rowYbreakDown, cb); #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); float rowYInstruction = rowYbreakDown - table_breakDown.TotalHeight - 10; float allowedRow2HeightInstruction = rowYInstruction - printedOnHeight - margin; table_instruction.WriteSelectedRows(0, -1, 10, rowYInstruction, cb); #endregion #region RO Image var countImageRo = 0; byte[] roImage; foreach (var index in viewModel.ImagesFile) { countImageRo++; } float rowYRoImage = rowYInstruction - table_instruction.TotalHeight - 10; float imageRoHeight; 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"); } 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); } imageRoHeight = table_ro_image.TotalHeight; table_ro_image.WriteSelectedRows(0, -1, 10, rowYRoImage, cb); } else { imageRoHeight = 0; } #endregion #region Signature PdfPTable table_signature = new PdfPTable(6); table_signature.TotalWidth = 570f; float[] signature_widths = new float[] { 1f, 1f, 1f, 1f, 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("Dibuat", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Kasie Merchandiser", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("R & D", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Ka Produksi", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Mengetahui", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Menyetujui", 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); 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); cell_signature_noted.Phrase = new Phrase("( )", normal_font); table_signature.AddCell(cell_signature_noted); cell_signature_noted.Phrase = new Phrase("(Michelle Tjokrosaputro)", normal_font); table_signature.AddCell(cell_signature_noted); float table_signatureY = rowYRoImage - imageRoHeight - 10; table_signature.WriteSelectedRows(0, -1, 10, table_signatureY, cb); #endregion this.DrawPrintedOn(now, bf, cb); document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public MemoryStream GeneratePdfTemplate(CostCalculationRetailViewModel 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); 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); DateTime now = DateTime.Now; Document document = new Document(PageSize.A4, 10, 10, 10, 10); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); writer.CloseStream = false; document.Open(); PdfContentByte cb = writer.DirectContent; float margin = 10; float printedOnHeight = 10; float startY = 840 - margin; PdfPCell cell_colon = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, Phrase = new Phrase(":", normal_font) }; #region Header cb.BeginText(); cb.SetFontAndSize(bf, 10); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "PT. EFRATA RETAILINDO", 10, 820, 0); cb.SetFontAndSize(bf_bold, 12); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "BUDGET PRODUCTION", 10, 805, 0); cb.EndText(); #endregion #region Detail 1 (Top) PdfPTable table_detail1 = new PdfPTable(8); table_detail1.TotalWidth = 570f; float[] detail1_widths = new float[] { 1f, 0.1f, 2f, 3f, 1f, 0.1f, 2f, 3f }; table_detail1.SetWidths(detail1_widths); PdfPCell cell_detail1 = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 1, PaddingBottom = 2, PaddingTop = 2 }; cell_detail1.Phrase = new Phrase("RO", normal_font); table_detail1.AddCell(cell_detail1); table_detail1.AddCell(cell_colon); cell_detail1.Phrase = new Phrase($"{viewModel.RO}", normal_font); table_detail1.AddCell(cell_detail1); cell_detail1.Phrase = new Phrase("", normal_font); table_detail1.AddCell(cell_detail1); cell_detail1.Phrase = new Phrase("SEASON", normal_font); table_detail1.AddCell(cell_detail1); table_detail1.AddCell(cell_colon); cell_detail1.Phrase = new Phrase($"{viewModel.Season.name}", normal_font); table_detail1.AddCell(cell_detail1); cell_detail1.Phrase = new Phrase("", normal_font); table_detail1.AddCell(cell_detail1); #endregion #region Draw Detail 1 float row1Y = 800; table_detail1.WriteSelectedRows(0, -1, 10, row1Y, cb); #endregion #region Detail 2 (Bottom, Column 1) PdfPTable table_detail2 = new PdfPTable(2); table_detail2.TotalWidth = 230f; float[] detail2_widths = new float[] { 2f, 5f }; table_detail2.SetWidths(detail2_widths); PdfPCell cell_detail2 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7 }; cell_detail2.Phrase = new Phrase("BUYER", normal_font); table_detail2.AddCell(cell_detail2); cell_detail2.Phrase = new Phrase($"{viewModel.Buyer.Name}", normal_font); table_detail2.AddCell(cell_detail2); cell_detail2.Phrase = new Phrase("ARTICLE", normal_font); table_detail2.AddCell(cell_detail2); cell_detail2.Phrase = new Phrase($"{viewModel.Article}", normal_font); table_detail2.AddCell(cell_detail2); cell_detail2.Phrase = new Phrase("DESCRIPTION", normal_font); table_detail2.AddCell(cell_detail2); cell_detail2.Phrase = new Phrase($"{viewModel.Description}", normal_font); table_detail2.AddCell(cell_detail2); cell_detail2.Phrase = new Phrase("QTY", normal_font); table_detail2.AddCell(cell_detail2); cell_detail2.Phrase = new Phrase($"{viewModel.Quantity} PCS", normal_font); table_detail2.AddCell(cell_detail2); cell_detail2.Phrase = new Phrase("DELIVERY", normal_font); table_detail2.AddCell(cell_detail2); cell_detail2.Phrase = new Phrase($"{viewModel.DeliveryDate.ToString("dd/MM/yyyy")}", normal_font); table_detail2.AddCell(cell_detail2); #endregion #region Signature PdfPTable table_signature = new PdfPTable(5); table_signature.TotalWidth = 570f; float[] signature_widths = new float[] { 1f, 1f, 1f, 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 }; cell_signature.Phrase = new Phrase("Membuat,", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Mengetahui,", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Menyetujui,", normal_font); table_signature.AddCell(cell_signature); string signatureArea = string.Empty; for (int i = 0; i < 4; i++) { signatureArea += Environment.NewLine; } cell_signature.Phrase = new Phrase(signatureArea, normal_font); table_signature.AddCell(cell_signature); table_signature.AddCell(cell_signature); table_signature.AddCell(cell_signature); table_signature.AddCell(cell_signature); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Merchandiser", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Ka. Sie Merchandiser", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Ka. Sie Pembelian", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Ka. Bag Produksi", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Direktur Marketing", normal_font); table_signature.AddCell(cell_signature); #endregion #region Cost Calculation Material PdfPTable table_ccm = new PdfPTable(10); table_ccm.TotalWidth = 570f; float[] ccm_widths = new float[] { 1f, 3f, 4f, 6f, 2f, 3f, 3f, 2f, 3f, 3f }; table_ccm.SetWidths(ccm_widths); PdfPCell cell_ccm = 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 }; cell_ccm.Phrase = new Phrase("NO", bold_font); table_ccm.AddCell(cell_ccm); cell_ccm.Phrase = new Phrase("CATEGORIES", bold_font); table_ccm.AddCell(cell_ccm); cell_ccm.Phrase = new Phrase("MATERIALS", bold_font); table_ccm.AddCell(cell_ccm); cell_ccm.Phrase = new Phrase("DESCRIPTION", bold_font); table_ccm.AddCell(cell_ccm); cell_ccm.Phrase = new Phrase("USAGE", bold_font); table_ccm.AddCell(cell_ccm); cell_ccm.Phrase = new Phrase("PRICE", bold_font); table_ccm.AddCell(cell_ccm); cell_ccm.Phrase = new Phrase("QUANTITY", bold_font); table_ccm.AddCell(cell_ccm); cell_ccm.Phrase = new Phrase("UNIT", bold_font); table_ccm.AddCell(cell_ccm); cell_ccm.Phrase = new Phrase("AMOUNT", bold_font); table_ccm.AddCell(cell_ccm); cell_ccm.Phrase = new Phrase("PO NUMBER", bold_font); table_ccm.AddCell(cell_ccm); float row2Y = row1Y - table_detail1.TotalHeight - 10; float row3Height = table_detail2.TotalHeight; float row2RemainingHeight = row2Y - 10 - row3Height - printedOnHeight - margin; float row2AllowedHeight = row2Y - printedOnHeight - margin; double totalBudget = 0; #region Process Cost double ol = viewModel.OL.CalculatedValue ?? 0; double processCost = ol; #endregion for (int i = 0; i < viewModel.CostCalculationRetail_Materials.Count; i++) { cell_ccm.Phrase = new Phrase((i + 1).ToString(), normal_font); table_ccm.AddCell(cell_ccm); cell_ccm.HorizontalAlignment = Element.ALIGN_LEFT; cell_ccm.Phrase = new Phrase(viewModel.CostCalculationRetail_Materials[i].Category.SubCategory != null ? String.Format("{0} - {1}", viewModel.CostCalculationRetail_Materials[i].Category.Name, viewModel.CostCalculationRetail_Materials[i].Category.SubCategory) : viewModel.CostCalculationRetail_Materials[i].Category.Name, normal_font); table_ccm.AddCell(cell_ccm); cell_ccm.Phrase = new Phrase(viewModel.CostCalculationRetail_Materials[i].Material.Name, normal_font); table_ccm.AddCell(cell_ccm); cell_ccm.Phrase = new Phrase(viewModel.CostCalculationRetail_Materials[i].Description, normal_font); table_ccm.AddCell(cell_ccm); cell_ccm.HorizontalAlignment = Element.ALIGN_RIGHT; double usage = viewModel.CostCalculationRetail_Materials[i].Quantity ?? 0; cell_ccm.Phrase = new Phrase(usage.ToString(), normal_font); table_ccm.AddCell(cell_ccm); double price = viewModel.CostCalculationRetail_Materials[i].Price ?? 0; cell_ccm.Phrase = new Phrase(String.Format("{0}/{1}", Number.ToRupiahWithoutSymbol(price), viewModel.CostCalculationRetail_Materials[i].UOMPrice.Name), normal_font); table_ccm.AddCell(cell_ccm); double factor; if (viewModel.CostCalculationRetail_Materials[i].Category.Name == "ACC") { factor = viewModel.AccessoriesAllowance ?? 0; } else { factor = viewModel.FabricAllowance ?? 0; } double totalQuantity = viewModel.Quantity ?? 0; double conversion = (double)viewModel.CostCalculationRetail_Materials[i].Conversion; double usageConversion = usage / conversion; double quantity = (100 + factor) / 100 * usageConversion * totalQuantity; quantity = Math.Ceiling(quantity); cell_ccm.Phrase = new Phrase(quantity.ToString(), normal_font); table_ccm.AddCell(cell_ccm); cell_ccm.HorizontalAlignment = Element.ALIGN_CENTER; cell_ccm.Phrase = new Phrase(viewModel.CostCalculationRetail_Materials[i].UOMPrice.Name, normal_font); table_ccm.AddCell(cell_ccm); cell_ccm.HorizontalAlignment = Element.ALIGN_RIGHT; double amount = quantity * price; cell_ccm.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(amount), normal_font); table_ccm.AddCell(cell_ccm); cell_ccm.HorizontalAlignment = Element.ALIGN_CENTER; cell_ccm.Phrase = new Phrase(viewModel.CostCalculationRetail_Materials[i].PO, normal_font); table_ccm.AddCell(cell_ccm); totalBudget += amount; float currentHeight = table_ccm.TotalHeight; if (currentHeight / row2RemainingHeight > 1) { if (currentHeight / row2AllowedHeight > 1) { PdfPRow headerRow = table_ccm.GetRow(0); PdfPRow lastRow = table_ccm.GetRow(table_ccm.Rows.Count - 1); table_ccm.DeleteLastRow(); table_ccm.WriteSelectedRows(0, -1, 10, row2Y, cb); table_ccm.DeleteBodyRows(); this.DrawPrintedOn(now, bf, cb); document.NewPage(); table_ccm.Rows.Add(headerRow); table_ccm.Rows.Add(lastRow); table_ccm.CalculateHeights(); row2Y = startY; row2RemainingHeight = row2Y - 10 - row3Height - printedOnHeight - margin; row2AllowedHeight = row2Y - printedOnHeight - margin; } } } #endregion #region Detail 3 (Bottom, Column 2) PdfPTable table_detail3 = new PdfPTable(8); table_detail3.TotalWidth = 330f; float[] detail3_widths = new float[] { 3.25f, 4.75f, 1.9f, 0.2f, 1.9f, 1.9f, 0.2f, 1.9f }; table_detail3.SetWidths(detail3_widths); //double budgetCost = viewModel.HPP; double totalProcessCost = processCost * (double)viewModel.Quantity; double budgetCost = totalBudget / (double)viewModel.Quantity; PdfPCell cell_detail3 = new PdfPCell() { HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7 }; PdfPCell cell_detail3_right = new PdfPCell() { HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7 }; PdfPCell cell_detail3_colspan6 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7, Colspan = 6 }; PdfPCell cell_detail3_colspan8 = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 2, PaddingBottom = 7, PaddingLeft = 2, PaddingTop = 7, Colspan = 8 }; cell_detail3.Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER; cell_detail3.Phrase = new Phrase("TOTAL BUDGET", normal_font); table_detail3.AddCell(cell_detail3); cell_detail3.Border = Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER; cell_detail3.Phrase = new Phrase($"{Number.ToRupiah(totalBudget)}", normal_font); table_detail3.AddCell(cell_detail3); cell_detail3_colspan6.Phrase = new Phrase("STANDARD HOURS", normal_font); table_detail3.AddCell(cell_detail3_colspan6); cell_detail3.Border = Rectangle.LEFT_BORDER; cell_detail3.Phrase = new Phrase("", normal_font); table_detail3.AddCell(cell_detail3); cell_detail3.Border = Rectangle.RIGHT_BORDER; table_detail3.AddCell(cell_detail3); cell_detail3.Border = Rectangle.LEFT_BORDER; cell_detail3.Phrase = new Phrase("SMV. CUT", normal_font); table_detail3.AddCell(cell_detail3); table_detail3.AddCell(cell_colon); cell_detail3.Border = Rectangle.NO_BORDER; double SH_Cutting = viewModel.SH_Cutting ?? 0; cell_detail3.Phrase = new Phrase($"{SH_Cutting}", normal_font); table_detail3.AddCell(cell_detail3); cell_detail3.Border = Rectangle.NO_BORDER; cell_detail3.Phrase = new Phrase("SMV. SEW", normal_font); table_detail3.AddCell(cell_detail3); table_detail3.AddCell(cell_colon); cell_detail3.Border = Rectangle.RIGHT_BORDER; double SH_Sewing = viewModel.SH_Sewing ?? 0; cell_detail3.Phrase = new Phrase($"{SH_Sewing}", normal_font); table_detail3.AddCell(cell_detail3); cell_detail3.Border = Rectangle.BOTTOM_BORDER | Rectangle.LEFT_BORDER; cell_detail3.Phrase = new Phrase("", normal_font); table_detail3.AddCell(cell_detail3); cell_detail3.Border = Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER; cell_detail3.Phrase = new Phrase("", normal_font); table_detail3.AddCell(cell_detail3); cell_detail3.Border = Rectangle.BOTTOM_BORDER | Rectangle.LEFT_BORDER; cell_detail3.Phrase = new Phrase("SMV. FIN", normal_font); table_detail3.AddCell(cell_detail3); table_detail3.AddCell(cell_colon); cell_detail3.Border = Rectangle.BOTTOM_BORDER; double SH_Finishing = viewModel.SH_Finishing ?? 0; cell_detail3.Phrase = new Phrase($"{SH_Finishing}", normal_font); table_detail3.AddCell(cell_detail3); cell_detail3.Border = Rectangle.BOTTOM_BORDER; cell_detail3.Phrase = new Phrase("SMV. TOT", normal_font); table_detail3.AddCell(cell_detail3); table_detail3.AddCell(cell_colon); cell_detail3.Border = Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER; double SH_Total = SH_Cutting + SH_Sewing + SH_Finishing; cell_detail3.Phrase = new Phrase($"{SH_Total}", normal_font); table_detail3.AddCell(cell_detail3); cell_detail3_colspan8.Phrase = new Phrase("BUDGET COST / PCS" + "".PadRight(5) + $"{Number.ToRupiah(budgetCost)}", normal_font); table_detail3.AddCell(cell_detail3_colspan8); cell_detail3_colspan8.Phrase = new Phrase("PROCESS COST" + "".PadRight(5) + $"{Number.ToRupiah(processCost)}", normal_font); table_detail3.AddCell(cell_detail3_colspan8); cell_detail3_colspan8.Phrase = new Phrase("TOTAL PROCESS COST" + "".PadRight(5) + $"{Number.ToRupiah(totalProcessCost)}", normal_font); table_detail3.AddCell(cell_detail3_colspan8); #endregion #region Draw Others table_ccm.WriteSelectedRows(0, -1, 10, row2Y, cb); float row3Y = row2Y - table_ccm.TotalHeight - 10; float row3RemainigHeight = row3Y - printedOnHeight - margin; if (row3RemainigHeight < row3Height) { this.DrawPrintedOn(now, bf, cb); row3Y = startY; document.NewPage(); } table_detail2.WriteSelectedRows(0, -1, margin, row3Y, cb); table_detail3.WriteSelectedRows(0, -1, margin + table_detail2.TotalWidth + 10, row3Y, cb); float signatureY = row3Y - row3Height - 10; signatureY = signatureY - 20; float signatureRemainingHeight = signatureY - printedOnHeight - margin; if (signatureRemainingHeight < table_signature.TotalHeight) { this.DrawPrintedOn(now, bf, cb); signatureY = startY; document.NewPage(); } table_signature.WriteSelectedRows(0, -1, margin, signatureY, cb); this.DrawPrintedOn(now, bf, cb); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public override bool Print() { try { //Set Font for the report rptFont = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL); string rptFileName = RptObject.ReportTempFileFullName; if (!string.IsNullOrEmpty(rptFileName)) { document = new Document(PageSize.LETTER, 20, 20, 10, 200); document.AddTitle(RptObject.ReportTitle); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(rptFileName, FileMode.Create)); ExtnPageEvents events = new ExtnPageEvents(); writer.PageEvent = events; PdfPTable tableData = new PdfPTable(9); tableData.TotalWidth = 300f; //Insert the report header InsertReportHeader(tableData); //Create Column headers InsertColumnHeaders(tableData); //Set number of header rows tableData.HeaderRows = 6; document.Open(); //Insert report data var pledgorName = string.Empty; foreach (var extnInfo in ExtensionMemoData) { pledgorName = extnInfo.CustomerName; PdfPCell pCell = new PdfPCell(); pCell.Colspan = 1; pCell.NoWrap = true; pCell.HorizontalAlignment = Element.ALIGN_JUSTIFIED; pCell.Border = Rectangle.NO_BORDER; pCell.Phrase = new Phrase(Utilities.GetStringValue(extnInfo.TicketNumber), rptFont); tableData.AddCell(pCell); pCell.Phrase = new Phrase(String.Format("{0:C}", extnInfo.Amount), rptFont); pCell.HorizontalAlignment = Element.ALIGN_RIGHT; pCell.Colspan = 1; tableData.AddCell(pCell); pCell.Phrase = new Phrase(extnInfo.DueDate.FormatDate(), rptFont); pCell.HorizontalAlignment = Element.ALIGN_JUSTIFIED; tableData.AddCell(pCell); pCell.Phrase = new Phrase(string.Format("{0:C}", extnInfo.DailyAmount), rptFont); pCell.HorizontalAlignment = Element.ALIGN_RIGHT; pCell.Colspan = 1; tableData.AddCell(pCell); pCell.Phrase = new Phrase(extnInfo.NewDueDate.FormatDate(), rptFont); pCell.HorizontalAlignment = Element.ALIGN_JUSTIFIED; pCell.Colspan = 1; tableData.AddCell(pCell); decimal pawnChargeMaturity = extnInfo.InterestAmount; decimal totalAtMaturity = (extnInfo.Amount + pawnChargeMaturity); pCell.Phrase = new Phrase(string.Format("{0:C}", totalAtMaturity), rptFont); pCell.HorizontalAlignment = Element.ALIGN_RIGHT; tableData.AddCell(pCell); pCell.Phrase = new Phrase(extnInfo.NewPfiEligible.FormatDate(), rptFont); pCell.HorizontalAlignment = Element.ALIGN_JUSTIFIED; pCell.NoWrap = true; tableData.AddCell(pCell); decimal pawnChargeRedeem = (Utilities.GetDecimalValue((extnInfo.NewPfiEligible - extnInfo.NewDueDate).TotalDays) * extnInfo.DailyAmount) + totalAtMaturity; pCell.Phrase = new Phrase(string.Format("{0:C}", pawnChargeRedeem), rptFont); pCell.HorizontalAlignment = Element.ALIGN_RIGHT; pCell.Colspan = 1; tableData.AddCell(pCell); pCell.Phrase = new Phrase(string.Format("{0:C}", extnInfo.ExtensionAmount), rptFont); pCell.HorizontalAlignment = Element.ALIGN_RIGHT; pCell.Colspan = 1; tableData.AddCell(pCell); if (PrintMultipleInOneMemo) { totDailyAmt += extnInfo.DailyAmount; totAmtPaidToday += extnInfo.ExtensionAmount; totalAmtDueAtMaturity += totalAtMaturity; numOfLoans++; } else { totDailyAmt = extnInfo.DailyAmount; totAmtPaidToday = extnInfo.ExtensionAmount; totalAmtDueAtMaturity = totalAtMaturity; numOfLoans = 1; AddEndOfReportData(tableData, pledgorName, writer); tableData.DeleteBodyRows(); document.NewPage(); } AddDocument(extnInfo, rptFileName); } if (PrintMultipleInOneMemo) { AddEndOfReportData(tableData, pledgorName, writer); } document.Close(); return(true); } else { FileLogger.Instance.logMessage(LogLevel.ERROR, this, "Extension memo printing failed since file name is not set"); return(false); } } catch (Exception de) { FileLogger.Instance.logMessage(LogLevel.ERROR, this, "Extension memo printing" + de.Message); return(false); } }
public MemoryStream GeneratePdfTemplate(CostCalculationRetailViewModel 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); 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); Font bold_font_8 = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font font_9 = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9); DateTime now = DateTime.Now; Document document = new Document(PageSize.A4, 10, 10, 10, 10); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); writer.CloseStream = false; document.Open(); PdfContentByte cb = writer.DirectContent; float margin = 10; float printedOnHeight = 10; float startY = 840 - margin; #region Header cb.BeginText(); cb.SetFontAndSize(bf, 10); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "PT. EFRATA RETAILINDO", 10, 820, 0); cb.SetFontAndSize(bf_bold, 12); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "COST CALCULATION RETAIL", 10, 805, 0); cb.EndText(); #endregion #region Top PdfPTable table_top = new PdfPTable(9); table_top.TotalWidth = 500f; float[] top_widths = new float[] { 1f, 0.1f, 2f, 1f, 0.1f, 2f, 1f, 0.1f, 2f }; table_top.SetWidths(top_widths); PdfPCell cell_top = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 1, PaddingBottom = 2, PaddingTop = 2 }; PdfPCell cell_colon = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE }; PdfPCell cell_top_keterangan = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_MIDDLE, PaddingRight = 1, PaddingBottom = 2, PaddingTop = 2, Colspan = 7 }; cell_colon.Phrase = new Phrase(":", normal_font); cell_top.Phrase = new Phrase("RO", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.RO}", 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.Buyer.Name}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("OL", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); double OLValue = viewModel.OL.Value ?? 0; string OL = OLValue > 0 ? OLValue.ToString() + " menit" : OLValue.ToString(); cell_top.Phrase = new Phrase($"{OL}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("ARTICLE", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.Article}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("DELIVERY", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.DeliveryDate.ToString("dd MMMM yyyy")}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("OTL 1", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); double OTL1Value = viewModel.OTL1.Value ?? 0; string OTL1 = OTL1Value > 0 ? OTL1Value.ToString() + " detik" : OTL1Value.ToString(); cell_top.Phrase = new Phrase($"{OTL1}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("STYLE", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.Style.name}", 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.SizeRange.Name}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("OTL 2", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); double OTL2Value = viewModel.OTL2.Value ?? 0; string OTL2 = OTL2Value > 0 ? OTL2Value.ToString() + " detik" : OTL2Value.ToString(); cell_top.Phrase = new Phrase($"{OTL2}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("SEASON", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.Season.name}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("EFFICIENCY", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.Efficiency.Value}%", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("OTL 3", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); double OTL3Value = viewModel.OTL3.Value ?? 0; string OTL3 = OTL3Value > 0 ? OTL3Value.ToString() + " detik" : OTL3Value.ToString(); cell_top.Phrase = new Phrase($"{OTL3}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("COUNTER", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.Counter.name}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("RISK", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top.Phrase = new Phrase($"{viewModel.Risk}%", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("TOTAL SMV", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); double STD_HourValue = viewModel.SH_Cutting.Value + viewModel.SH_Finishing.Value + viewModel.SH_Sewing.Value; string STD_Hour = STD_HourValue > 0 ? STD_HourValue.ToString() : STD_HourValue.ToString(); cell_top.Phrase = new Phrase($"{STD_Hour}", normal_font); table_top.AddCell(cell_top); cell_top.Phrase = new Phrase("KETERANGAN", normal_font); table_top.AddCell(cell_top); table_top.AddCell(cell_colon); cell_top_keterangan.Phrase = new Phrase($"{viewModel.Description}", normal_font); table_top.AddCell(cell_top_keterangan); #endregion #region Draw Image float imageHeight; try { byte[] imageByte = Convert.FromBase64String(Base64.GetBase64File(viewModel.ImageFile)); Image image = Image.GetInstance(imgb: imageByte); if (image.Width > 60) { float percentage = 0.0f; percentage = 60 / image.Width; image.ScalePercent(percentage * 100); } imageHeight = image.ScaledHeight; float imageY = 800 - imageHeight; image.SetAbsolutePosition(520, imageY); cb.AddImage(image, inlineImage: true); } catch (Exception) { imageHeight = 0; } #endregion #region Draw Top float row1Y = 800; table_top.WriteSelectedRows(0, -1, 10, row1Y, cb); #endregion #region Detail (Bottom, Column 1.2) PdfPTable table_detail = new PdfPTable(2); table_detail.TotalWidth = 280f; float[] detail_widths = new float[] { 1f, 1f }; table_detail.SetWidths(detail_widths); PdfPCell cell_detail = 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, Rowspan = 4 }; double total = Convert.ToDouble(viewModel.OL.CalculatedValue + viewModel.OTL1.CalculatedValue + viewModel.OTL2.CalculatedValue + viewModel.OTL3.CalculatedValue); cell_detail.Phrase = new Phrase( "OL".PadRight(22) + ": " + viewModel.OL.CalculatedValue + Environment.NewLine + Environment.NewLine + "OTL 1".PadRight(20) + ": " + viewModel.OTL1.CalculatedValue + Environment.NewLine + Environment.NewLine + "OTL 2".PadRight(20) + ": " + viewModel.OTL2.CalculatedValue + Environment.NewLine + Environment.NewLine + "OTL 3".PadRight(20) + ": " + viewModel.OTL3.CalculatedValue + Environment.NewLine + Environment.NewLine + "Total".PadRight(22) + ": " + total + Environment.NewLine , normal_font); table_detail.AddCell(cell_detail); cell_detail = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_BOTTOM, Padding = 5 }; cell_detail.Phrase = new Phrase("HPP", normal_font); table_detail.AddCell(cell_detail); cell_detail = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5 }; cell_detail.Phrase = new Phrase(Number.ToRupiah(viewModel.HPP), font_9); table_detail.AddCell(cell_detail); cell_detail = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_BOTTOM, Padding = 5 }; cell_detail.Phrase = new Phrase("Wholesale Price: HPP X 2.20", normal_font); table_detail.AddCell(cell_detail); cell_detail = new PdfPCell() { Border = Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_TOP, Padding = 5 }; cell_detail.Phrase = new Phrase(Number.ToRupiah(viewModel.WholesalePrice), font_9); table_detail.AddCell(cell_detail); #endregion #region Signature (Bottom, Column 1.2) PdfPTable table_signature = new PdfPTable(3); table_signature.TotalWidth = 280f; float[] signature_widths = new float[] { 1f, 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 }; cell_signature.Phrase = new Phrase("Mengetahui,", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Menyetujui,", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Ka. Sie Merchandiser", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Direktur Operasional", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Wakil Direktur Utama", normal_font); table_signature.AddCell(cell_signature); string signatureArea = string.Empty; for (int i = 0; i < 5; i++) { signatureArea += Environment.NewLine; } cell_signature.Phrase = new Phrase(signatureArea, normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase(signatureArea, normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase(signatureArea, normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("( )", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Haenis Gunarto ", normal_font); table_signature.AddCell(cell_signature); cell_signature.Phrase = new Phrase("Ninuk Setyawati", normal_font); table_signature.AddCell(cell_signature); #endregion #region Price (Bottom, Column 2) PdfPTable table_price = new PdfPTable(5); table_price.TotalWidth = 280f; float[] price_widths = new float[] { 1.6f, 3f, 3f, 4f, 1f }; table_price.SetWidths(price_widths); PdfPCell cell_price_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_price_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_price_right = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2 }; cell_price_center.Phrase = new Phrase("KET (X)", bold_font); table_price.AddCell(cell_price_center); cell_price_center.Phrase = new Phrase("HARGA (Rp)", bold_font); table_price.AddCell(cell_price_center); cell_price_center.Phrase = new Phrase("PEMBULATAN HARGA (Rp)", bold_font); table_price.AddCell(cell_price_center); cell_price_center.Phrase = new Phrase("KETERANGAN", bold_font); table_price.AddCell(cell_price_center); cell_price_center.Phrase = new Phrase("", bold_font); table_price.AddCell(cell_price_center); cell_price_left.Phrase = new Phrase("2", normal_font); table_price.AddCell(cell_price_left); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed20), normal_font); table_price.AddCell(cell_price_right); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding20), normal_font); table_price.AddCell(cell_price_right); cell_price_left.Phrase = new Phrase("", normal_font); table_price.AddCell(cell_price_left); cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding20") ? "*" : "", normal_font); table_price.AddCell(cell_price_center); cell_price_left.Phrase = new Phrase("2.1", normal_font); table_price.AddCell(cell_price_left); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed21), normal_font); table_price.AddCell(cell_price_right); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding21), normal_font); table_price.AddCell(cell_price_right); cell_price_left.Phrase = new Phrase("", normal_font); table_price.AddCell(cell_price_left); cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding21") ? "*" : "", normal_font); table_price.AddCell(cell_price_center); cell_price_left.Phrase = new Phrase("2.2", normal_font); table_price.AddCell(cell_price_left); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed22), normal_font); table_price.AddCell(cell_price_right); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding22), normal_font); table_price.AddCell(cell_price_right); cell_price_left.Phrase = new Phrase("", normal_font); table_price.AddCell(cell_price_left); cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding22") ? "*" : "", normal_font); table_price.AddCell(cell_price_center); cell_price_left.Phrase = new Phrase("2.3", normal_font); table_price.AddCell(cell_price_left); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed23), normal_font); table_price.AddCell(cell_price_right); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding23), normal_font); table_price.AddCell(cell_price_right); cell_price_left.Phrase = new Phrase("", normal_font); table_price.AddCell(cell_price_left); cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding23") ? "*" : "", normal_font); table_price.AddCell(cell_price_center); cell_price_left.Phrase = new Phrase("2.4", normal_font); table_price.AddCell(cell_price_left); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed24), normal_font); table_price.AddCell(cell_price_right); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding24), normal_font); table_price.AddCell(cell_price_right); cell_price_left.Phrase = new Phrase("", normal_font); table_price.AddCell(cell_price_left); cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding24") ? "*" : "", normal_font); table_price.AddCell(cell_price_center); cell_price_left.Phrase = new Phrase("2.5", normal_font); table_price.AddCell(cell_price_left); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed25), normal_font); table_price.AddCell(cell_price_right); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding25), normal_font); table_price.AddCell(cell_price_right); cell_price_left.Phrase = new Phrase("", normal_font); table_price.AddCell(cell_price_left); cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding25") ? "*" : "", normal_font); table_price.AddCell(cell_price_center); cell_price_left.Phrase = new Phrase("2.6", normal_font); table_price.AddCell(cell_price_left); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed26), normal_font); table_price.AddCell(cell_price_right); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding26), normal_font); table_price.AddCell(cell_price_right); cell_price_left.Phrase = new Phrase("", normal_font); table_price.AddCell(cell_price_left); cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding26") ? "*" : "", normal_font); table_price.AddCell(cell_price_center); cell_price_left.Phrase = new Phrase("2.7", normal_font); table_price.AddCell(cell_price_left); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed27), normal_font); table_price.AddCell(cell_price_right); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding27), normal_font); table_price.AddCell(cell_price_right); cell_price_left.Phrase = new Phrase("", normal_font); table_price.AddCell(cell_price_left); cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding27") ? "*" : "", normal_font); table_price.AddCell(cell_price_center); cell_price_left.Phrase = new Phrase("2.8", normal_font); table_price.AddCell(cell_price_left); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed28), normal_font); table_price.AddCell(cell_price_right); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding28), normal_font); table_price.AddCell(cell_price_right); cell_price_left.Phrase = new Phrase("", normal_font); table_price.AddCell(cell_price_left); cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding28") ? "*" : "", normal_font); table_price.AddCell(cell_price_center); cell_price_left.Phrase = new Phrase("2.9", normal_font); table_price.AddCell(cell_price_left); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed29), normal_font); table_price.AddCell(cell_price_right); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding29), normal_font); table_price.AddCell(cell_price_right); cell_price_left.Phrase = new Phrase("", normal_font); table_price.AddCell(cell_price_left); cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding29") ? "*" : "", normal_font); table_price.AddCell(cell_price_center); cell_price_left.Phrase = new Phrase("3.0", normal_font); table_price.AddCell(cell_price_left); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Proposed30), normal_font); table_price.AddCell(cell_price_right); cell_price_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.Rounding30), normal_font); table_price.AddCell(cell_price_right); cell_price_left.Phrase = new Phrase("", normal_font); table_price.AddCell(cell_price_left); cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("Rounding30") ? "*" : "", normal_font); table_price.AddCell(cell_price_center); cell_price_left.Phrase = new Phrase("Others", normal_font); table_price.AddCell(cell_price_left); cell_price_right.Phrase = new Phrase("", normal_font); table_price.AddCell(cell_price_right); cell_price_right.Phrase = new Phrase(viewModel.RoundingOthers > 0 ? Number.ToRupiahWithoutSymbol(viewModel.RoundingOthers) : "", normal_font); table_price.AddCell(cell_price_right); cell_price_left.Phrase = new Phrase("", normal_font); table_price.AddCell(cell_price_left); cell_price_center.Phrase = new Phrase(viewModel.SelectedRounding.ToString().Equals("RoundingOthers") ? "*" : "", normal_font); table_price.AddCell(cell_price_center); #endregion #region Cost Calculation Material PdfPTable table_ccm = new PdfPTable(7); table_ccm.TotalWidth = 570f; float[] ccm_widths = new float[] { 1.25f, 3.5f, 4f, 9f, 3f, 4f, 4f }; table_ccm.SetWidths(ccm_widths); PdfPCell cell_ccm_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_ccm_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_ccm_right = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2 }; cell_ccm_center.Phrase = new Phrase("NO", bold_font); table_ccm.AddCell(cell_ccm_center); cell_ccm_center.Phrase = new Phrase("CATEGORIES", bold_font); table_ccm.AddCell(cell_ccm_center); cell_ccm_center.Phrase = new Phrase("MATERIALS", bold_font); table_ccm.AddCell(cell_ccm_center); cell_ccm_center.Phrase = new Phrase("DESCRIPTION", bold_font); table_ccm.AddCell(cell_ccm_center); cell_ccm_center.Phrase = new Phrase("QUANTITY", bold_font); table_ccm.AddCell(cell_ccm_center); cell_ccm_center.Phrase = new Phrase("RP. PTC/PC", bold_font); table_ccm.AddCell(cell_ccm_center); cell_ccm_center.Phrase = new Phrase("RP. TOTAL", bold_font); table_ccm.AddCell(cell_ccm_center); double Total = 0; float row1Height = imageHeight > table_top.TotalHeight ? imageHeight : table_top.TotalHeight; float row2Y = row1Y - row1Height - 10; float calculatedHppHeight = 7; float row3LeftHeight = table_detail.TotalHeight + 5 + table_signature.TotalHeight; float row3RightHeight = table_price.TotalHeight; float row3Height = row3LeftHeight > row3RightHeight ? row3LeftHeight : row3RightHeight; float remainingRow2Height = row2Y - 10 - row3Height - printedOnHeight - margin; float allowedRow2Height = row2Y - printedOnHeight - margin; for (int i = 0; i < viewModel.CostCalculationRetail_Materials.Count; i++) { cell_ccm_center.Phrase = new Phrase((i + 1).ToString(), normal_font); table_ccm.AddCell(cell_ccm_center); cell_ccm_left.Phrase = new Phrase(viewModel.CostCalculationRetail_Materials[i].Category.SubCategory != null ? String.Format("{0} - {1}", viewModel.CostCalculationRetail_Materials[i].Category.Name, viewModel.CostCalculationRetail_Materials[i].Category.SubCategory) : viewModel.CostCalculationRetail_Materials[i].Category.Name, normal_font); table_ccm.AddCell(cell_ccm_left); cell_ccm_left.Phrase = new Phrase(viewModel.CostCalculationRetail_Materials[i].Material.Name, normal_font); table_ccm.AddCell(cell_ccm_left); cell_ccm_left.Phrase = new Phrase(viewModel.CostCalculationRetail_Materials[i].Description, normal_font); table_ccm.AddCell(cell_ccm_left); cell_ccm_right.Phrase = new Phrase(String.Format("{0} {1}", viewModel.CostCalculationRetail_Materials[i].Quantity, viewModel.CostCalculationRetail_Materials[i].UOMQuantity.Name), normal_font); table_ccm.AddCell(cell_ccm_right); cell_ccm_right.Phrase = new Phrase(String.Format("{0}/{1}", Number.ToRupiahWithoutSymbol(viewModel.CostCalculationRetail_Materials[i].Price), viewModel.CostCalculationRetail_Materials[i].UOMPrice.Name), normal_font); table_ccm.AddCell(cell_ccm_right); cell_ccm_right.Phrase = new Phrase(Number.ToRupiahWithoutSymbol(viewModel.CostCalculationRetail_Materials[i].Total), normal_font); table_ccm.AddCell(cell_ccm_right); Total += viewModel.CostCalculationRetail_Materials[i].Total; float currentHeight = table_ccm.TotalHeight; if (currentHeight / remainingRow2Height > 1) { if (currentHeight / allowedRow2Height > 1) { PdfPRow headerRow = table_ccm.GetRow(0); PdfPRow lastRow = table_ccm.GetRow(table_ccm.Rows.Count - 1); table_ccm.DeleteLastRow(); table_ccm.WriteSelectedRows(0, -1, 10, row2Y, cb); table_ccm.DeleteBodyRows(); this.DrawPrintedOn(now, bf, cb); document.NewPage(); table_ccm.Rows.Add(headerRow); table_ccm.Rows.Add(lastRow); table_ccm.CalculateHeights(); row2Y = startY; remainingRow2Height = row2Y - 10 - row3Height - printedOnHeight - margin; allowedRow2Height = row2Y - printedOnHeight - margin; } } } cell_ccm_right = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2, Colspan = 6 }; cell_ccm_right.Phrase = new Phrase("TOTAL", bold_font_8); table_ccm.AddCell(cell_ccm_right); cell_ccm_right = new PdfPCell() { Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = 2 }; cell_ccm_right.Phrase = new Phrase(Number.ToRupiah(Total), bold_font_8); table_ccm.AddCell(cell_ccm_right); #endregion #region Draw Middle and Bottom table_ccm.WriteSelectedRows(0, -1, 10, row2Y, cb); float row3Y = row2Y - table_ccm.TotalHeight - 10; float remainingRow3Height = row3Y - printedOnHeight - margin; if (remainingRow3Height < row3Height) { this.DrawPrintedOn(now, bf, cb); row3Y = startY; document.NewPage(); } #region Calculated HPP float calculatedHppY = row3Y - calculatedHppHeight; cb.BeginText(); cb.SetFontAndSize(bf, 8); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "KALKULASI HPP: (OL + OTL1 + OTL2 + FABRIC + ACC) + ((OL + OTL1 + OTL2 + FABRIC + ACC) * Risk)", 10, calculatedHppY, 0); cb.EndText(); #endregion float table_detailY = calculatedHppY - 5; table_detail.WriteSelectedRows(0, -1, 10, table_detailY, cb); float table_signatureY = table_detailY - row3Height + table_signature.TotalHeight; table_signature.WriteSelectedRows(0, -1, 10, table_signatureY, cb); table_price.WriteSelectedRows(0, -1, 300, table_detailY, cb); this.DrawPrintedOn(now, bf, cb); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }
public void miseEnForm(string typeDoc) { int incCopie = 0; int nbCopie = 1; string cheminDocFinaux = ConfigurationManager.AppSettings["CheminDocFinaux"].ToString(); string cheminRessources = ConfigurationManager.AppSettings["CheminRessources"].ToString(); while (incCopie < nbCopie) { /*ND 23 10 2015*/ string chemin = ""; /* if (!System.IO.Directory.Exists(cheminDocFinaux + "\\DocFinaux\\Releve\\" + donneEntete["Tiers_nocpt"].Substring(3,6))) { System.IO.Directory.CreateDirectory(cheminDocFinaux + "\\DocFinaux\\Releve\\" + donneEntete["Tiers_nocpt"].Substring(3, 6)); chemin = cheminDocFinaux + "\\DocFinaux\\Releve\\" + donneEntete["Tiers_nocpt"].Substring(3, 6) + "\\" + nomDoc + "_" + donneEntete["Tiers_nocpt"].Substring(3, 6) + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"; }*/ if (!System.IO.Directory.Exists(cheminDocFinaux + "\\DocFinaux\\Facturation\\" + donneEntete["Tiers_nocpt"].Substring(3, 6))) { System.IO.Directory.CreateDirectory(cheminDocFinaux + "\\DocFinaux\\Facturation\\" + donneEntete["Tiers_nocpt"].Substring(3, 6)); chemin = cheminDocFinaux + "\\DocFinaux\\Facturation\\" + donneEntete["Tiers_nocpt"].Substring(3, 6) + "\\RELEVE" + nomDoc + "_" + donneEntete["Tiers_nocpt"].Substring(3, 6) + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"; } else { /*ND 23 10 2015*/ //chemin = cheminDocFinaux + "\\DocFinaux\\Releve\\" + donneEntete["Tiers_nocpt"].Substring(3, 6) + "\\" + nomDoc + "_" + donneEntete["Tiers_nocpt"].Substring(3, 6) + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"; chemin = cheminDocFinaux + "\\DocFinaux\\Facturation\\" + donneEntete["Tiers_nocpt"].Substring(3, 6) + "\\RELEVE" + nomDoc + "_" + donneEntete["Tiers_nocpt"].Substring(3, 6) + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"; } Document nouveauDocument = new Document(PageSize.A4, 20, 20, 12, 2); PdfWriter writer = PdfWriter.GetInstance(nouveauDocument, new FileStream(chemin, FileMode.Create)); //Stockage du document //--------------------------------------------------------------------------------------------------------------------------- //Constitution document PDF //--------------------------------------------------------------------------------------------------------------------------- nouveauDocument.Open(); PdfPTable tableau = new PdfPTable(2); tableau.TotalWidth = 550; tableau.LockedWidth = true; //------------------------------------------------------------------------------------------------- //Encadré ABCR Paragraph p = new Paragraph(); p.Add(new Phrase(donneEntete["Adresse_interne_1"] + "\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); p.Add(new Phrase(donneEntete["Adresse_interne_2"] + "\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); p.Add(new Phrase(donneEntete["Adresse_interne_3"] + "\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); p.Add(new Phrase(donneEntete["Adresse_interne_4"] + "\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); PdfPCell celulleHauteGauche = new PdfPCell(p); celulleHauteGauche.Border = PdfPCell.NO_BORDER; tableau.AddCell(celulleHauteGauche); //Celulle de droite contenant l'adresse de livraison Paragraph pAdl = new Paragraph(); pAdl.Add(new Phrase("\n\n \n")); pAdl.Add(new Phrase("\n ", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase("\n ", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase("\n ", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase("\n ", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase(" ", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); PdfPCell celulleFinDroite = new PdfPCell(pAdl); celulleFinDroite.Bottom = PdfPCell.ALIGN_BOTTOM; celulleFinDroite.Border = PdfPCell.NO_BORDER; celulleFinDroite.PaddingLeft = 35; tableau.AddCell(celulleFinDroite); //Tableau dans celulle bas gauche du tableau d'entete PdfPCell celulleBasGauche = new PdfPCell(); Paragraph ptest = new Paragraph(); ptest.Add(new Phrase("\n Relevé de facture(s)\n\n",FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.BOLD))); celulleBasGauche.AddElement(ptest); PdfPTable tabCell = new PdfPTable(3); tabCell.TotalWidth = 230; tabCell.LockedWidth = true; tabCell.AddCell(new Phrase("COMPTE", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD))); tabCell.AddCell(new Phrase("DATE", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD))); tabCell.AddCell(new Phrase("NO RELEVE", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD))); tabCell.AddCell(new Phrase(donneEntete["Tiers_nocpt"], FontFactory.GetFont(FontFactory.HELVETICA, 10))); tabCell.AddCell(new Phrase(donneEntete["Rel_datrel"], FontFactory.GetFont(FontFactory.HELVETICA, 10))); tabCell.AddCell(new Phrase(donneEntete["Document_numero"], FontFactory.GetFont(FontFactory.HELVETICA, 10))); tabCell.HorizontalAlignment = PdfPCell.ALIGN_LEFT; celulleBasGauche.AddElement(tabCell); celulleBasGauche.Border = PdfPCell.NO_BORDER; celulleBasGauche.Bottom = PdfPCell.ALIGN_BOTTOM; tableau.AddCell(celulleBasGauche); //Adresse facturation Paragraph pAdf = new Paragraph(); // REGLER INDENTATION DU PARAGRAPHE pAdf.Add(new Phrase("\n\n\n\n" + donneEntete["Tiers_adf1"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdf.Add(new Phrase(donneEntete["Tiers_adf2"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdf.Add(new Phrase(donneEntete["Tiers_adf3"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdf.Add(new Phrase(donneEntete["Tiers_adf4"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdf.Add(new Phrase(donneEntete["Tiers_adfcp"] + " " + donneEntete["Tiers_adf6"] + "\n\n\n\n ", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); PdfPCell celulleHauteDroite = new PdfPCell(pAdf); celulleHauteGauche.HorizontalAlignment = Element.ALIGN_RIGHT; celulleHauteDroite.Border = PdfPCell.NO_BORDER; celulleHauteDroite.PaddingLeft = 80; tableau.AddCell(celulleHauteDroite); nouveauDocument.Add(tableau); //-------------------------------------------------------------------------------------------------------- // TABLEAU //------------------------------------------------------------------------------------------------------- CurseurTemplate ct = new CurseurTemplate(); valeurTemplate = ct.chercher("RELEVE"); float[] largeurs = { int.Parse(valeurTemplate["Dimension1"]), int.Parse(valeurTemplate["Dimension2"]), int.Parse(valeurTemplate["Dimension3"]), int.Parse(valeurTemplate["Dimension4"]), int.Parse(valeurTemplate["Dimension5"]), int.Parse(valeurTemplate["Dimension6"]), }; PdfPTable table = new PdfPTable(largeurs); table.TotalWidth = 565; //Chaque colonne crée ci dessus doit être rempli table.LockedWidth = true; PdfPCell cellET1 = new PdfPCell(new Phrase("Date", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); cellET1.SetLeading(2f, 1.2f); cellET1.PaddingBottom = 7f; table.AddCell(cellET1); PdfPCell cellET2 = new PdfPCell(new Phrase("Type Pièce", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); cellET2.SetLeading(2f, 1.2f); cellET2.PaddingBottom = 7f; table.AddCell(cellET2); PdfPCell cellET3 = new PdfPCell(new Phrase("Référence", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); cellET3.SetLeading(2f, 1.2f); cellET3.PaddingBottom = 7f; table.AddCell(cellET3); PdfPCell cellET4 = new PdfPCell(new Phrase("T.V.A", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); cellET4.HorizontalAlignment = Element.ALIGN_RIGHT; cellET4.PaddingBottom = 7f; cellET4.SetLeading(2f, 1.2f); table.AddCell(cellET4); PdfPCell cellET5 = new PdfPCell(new Phrase("Avoir", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); cellET5.HorizontalAlignment = Element.ALIGN_RIGHT; cellET5.PaddingBottom = 7f; cellET5.SetLeading(2f, 1.2f); table.AddCell(cellET5); PdfPCell cellET6 = new PdfPCell(new Phrase("Facture", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); cellET6.HorizontalAlignment = Element.ALIGN_RIGHT; cellET6.PaddingBottom = 7f; cellET6.SetLeading(2f, 1.2f); table.AddCell(cellET6); int i; int nbLigne = 0; float resultat = 0; float dimTab = 0; int décrement = 0; int numPage = 0; //Constitution du tableau /*ND DEBUT 19 10 2015*/ // bool okDési = false; /*ND FIN 19 10 2015*/ /* ND debut 19 10 2015*/ //bool okStart = false; /*ND FIN 19 10 2015*/ double tempoTOT = 0; for (i = 0; i < iBody; i++) { nbLigne++; PdfPCell cell1 = new PdfPCell(new Phrase(donneeBody["Rel_datfac" + i], FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cell1.Border = PdfPCell.NO_BORDER; cell1.Border += PdfPCell.RIGHT_BORDER; cell1.Border += PdfPCell.LEFT_BORDER; cell1.SetLeading(5f, 1.2f); table.AddCell(cell1); PdfPCell cell2 = new PdfPCell(new Phrase(donneeBody["Rel_libavofac" + i], FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cell2.Border = PdfPCell.NO_BORDER; cell2.Border += PdfPCell.RIGHT_BORDER; cell2.Border += PdfPCell.LEFT_BORDER; cell2.SetLeading(5f, 1.2f); table.AddCell(cell2); PdfPCell cell3 = new PdfPCell(new Phrase(donneeBody["Rel_nofac" + i], FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cell3.Border = PdfPCell.NO_BORDER; cell3.Border += PdfPCell.RIGHT_BORDER; cell3.Border += PdfPCell.LEFT_BORDER; cell3.SetLeading(5f, 1.2f); table.AddCell(cell3); PdfPCell cell4 = new PdfPCell(new Phrase(donneeBody["Rel_mtva" + i], FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cell4.Border = PdfPCell.NO_BORDER; cell4.Border += PdfPCell.RIGHT_BORDER; cell4.Border += PdfPCell.LEFT_BORDER; cell4.HorizontalAlignment = Element.ALIGN_RIGHT; cell4.SetLeading(5f, 1.2f); table.AddCell(cell4); PdfPCell cell5 = new PdfPCell(new Phrase(donneeBody["Rel_mttavo"+i], FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cell5.Border = PdfPCell.NO_BORDER; cell5.Border += PdfPCell.RIGHT_BORDER; cell5.Border += PdfPCell.LEFT_BORDER; cell5.HorizontalAlignment = Element.ALIGN_RIGHT; cell5.SetLeading(5f, 1.2f); table.AddCell(cell5); PdfPCell cell6 = new PdfPCell(new Phrase(donneeBody["Rel_mtfac" + i], FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cell6.Border = PdfPCell.NO_BORDER; cell6.Border += PdfPCell.RIGHT_BORDER; cell6.Border += PdfPCell.LEFT_BORDER; cell6.HorizontalAlignment = Element.ALIGN_RIGHT; cell6.SetLeading(5f, 1.2f); table.AddCell(cell6); //--------------------------------------------GESTION DU SAUT DE PAGE------------------------------------------------------------------------------------------- float temp = table.TotalHeight; dimTab = temp; if (dimTab >= 380 && i < iBody) //if (dimTab >= 380 && i <= iBody) { //Saut de page numPage++; PdfPCell cellFin = new PdfPCell(new Phrase(" ")); PdfPCell cellBlanche = new PdfPCell(new Phrase(" ")); PdfPCell cellBlancheDA = new PdfPCell(new Phrase("\n\nA Reporter", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.ITALIC))); PdfPCell cellBlancheD = new PdfPCell(new Phrase("\n\n" + tempoTOT.ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.ITALIC))); cellFin.Colspan = 8; cellBlancheDA.Bottom = PdfPCell.ALIGN_BOTTOM; cellBlancheD.Bottom = PdfPCell.ALIGN_BOTTOM; cellBlanche.FixedHeight = (440 - dimTab); cellBlanche.Border = PdfPCell.NO_BORDER; cellBlanche.Border += PdfPCell.RIGHT_BORDER; cellBlanche.Border += PdfPCell.LEFT_BORDER; cellBlancheDA.FixedHeight = (440 - dimTab); cellBlancheDA.Border = PdfPCell.NO_BORDER; cellBlancheDA.Border += PdfPCell.LEFT_BORDER; cellBlancheDA.Border += PdfPCell.RIGHT_BORDER; cellBlancheD.FixedHeight = (440 - dimTab); cellBlancheD.Border = PdfPCell.NO_BORDER; cellBlancheD.Border += PdfPCell.LEFT_BORDER; cellBlancheD.Border += PdfPCell.RIGHT_BORDER; cellFin.Border = PdfPCell.NO_BORDER; cellFin.Border += PdfPCell.TOP_BORDER; table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlancheDA); table.AddCell(cellBlancheD); table.AddCell(cellFin); nouveauDocument.Add(table);//----------------------------------------------------------------------------Repère ligne en dessous-------------------------------------------------- Phrase pReport = new Phrase(" A REPORTER\n\n\n\n\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD)); /*10 12 15 ND correction bug saut de page donnée entete innexistante*/ // Phrase pPage = new Phrase("\n " + donneEntete["Document_type"] + " " + donneEntete["Duplicata"] + " Page n° " + (numPage + 1) + " ", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD)); Phrase pPage = new Phrase("\n " + donneEntete["Document_type"] + " Page n° " + (numPage + 1) + " ", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD)); pPage.Leading = 15; nouveauDocument.Add(pReport); table.DeleteBodyRows(); nouveauDocument.Add(Chunk.NEXTPAGE); nouveauDocument.Add(tableau); nouveauDocument.Add(pPage); table.AddCell(cellET1); table.AddCell(cellET2); table.AddCell(cellET3); table.AddCell(cellET4); table.AddCell(cellET5); table.AddCell(cellET6); dimTab = 0; décrement = (i - 1); } //FinGestionSautPage } //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- int b; //---------------------------------------------------------------- for (b = 0; b <= i; b++) // { // Compteur dimension du tableau float temp = table.TotalHeight; // resultat = temp; // } //------------------------------------------------------------------- if (i >= iBody) { PdfPCell cellFin = new PdfPCell(new Phrase(" ")); PdfPCell cellBlanche = new PdfPCell(new Phrase(" ")); PdfPCell cellBlancheD = new PdfPCell(new Phrase(" ")); cellFin.Colspan = 8; resultat = 300 - resultat; //<<----------450 correspond au nombre de point de la longueur du tableau, c'est la valeur à modifier pour modifier la taille du tableau cellBlanche.FixedHeight = resultat; cellBlanche.Border = PdfPCell.NO_BORDER; cellBlanche.Border += PdfPCell.RIGHT_BORDER; cellBlanche.Border += PdfPCell.LEFT_BORDER; cellBlancheD.FixedHeight = resultat; cellBlancheD.Border = PdfPCell.NO_BORDER; cellBlancheD.Border += PdfPCell.LEFT_BORDER; cellBlancheD.Border += PdfPCell.RIGHT_BORDER; cellFin.Border = PdfPCell.NO_BORDER; cellFin.Border += PdfPCell.TOP_BORDER; table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlancheD); table.AddCell(cellFin); } table.SpacingAfter = -15F; nouveauDocument.Add(table); //----------------------------------------------------Tableau récap----------------------------------------- PdfPTable tabTot = new PdfPTable(3); tabTot.TotalWidth = 565; tabTot.LockedWidth = true; PdfPCell cellHT = new PdfPCell(new Phrase("HT " + donneeFoot["Tot_ht"], FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); cellHT.Border = PdfPCell.NO_BORDER; PdfPCell cellTVA = new PdfPCell(new Phrase("TVA " + donneeFoot["Tot_tva"], FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); cellTVA.Border = PdfPCell.NO_BORDER; PdfPCell cellTot = new PdfPCell(new Phrase(donneeFoot["Tot_rel"], FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); cellTot.Border = PdfPCell.NO_BORDER; cellHT.HorizontalAlignment = Element.ALIGN_RIGHT; cellTVA.HorizontalAlignment = Element.ALIGN_RIGHT; cellTot.HorizontalAlignment = Element.ALIGN_RIGHT; tabTot.AddCell(cellHT); tabTot.AddCell(cellTVA); tabTot.AddCell(cellTot); PdfPCell cellType = new PdfPCell(new Phrase("\nDate d'échéance : " + donneeFoot["Tot_datech"]+"\n\n"+donneeFoot["Tot_libtraite"], FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.NORMAL))); cellType.Border = PdfPCell.NO_BORDER; cellType.Colspan = 2; PdfPTable tabReleve = new PdfPTable(1); tabReleve.TotalWidth = 138; tabReleve.LockedWidth = true; tabReleve.AddCell(new PdfPCell(new Phrase("TOTAL RELEVE", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD)))); PdfPCell tabCellTot = new PdfPCell(new Phrase("\n"+donneeFoot["Tot_rel"]+" EUR", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD))); tabCellTot.HorizontalAlignment = Element.ALIGN_RIGHT; tabReleve.AddCell(tabCellTot); PdfPCell cellTabReleve = new PdfPCell(); cellTabReleve.Border = PdfPCell.NO_BORDER; cellTabReleve.PaddingLeft= 50; cellTabReleve.VerticalAlignment = Element.ALIGN_BOTTOM; cellTabReleve.AddElement(tabReleve); tabTot.AddCell(cellType); tabTot.AddCell(cellTabReleve); nouveauDocument.Add(tabTot); Phrase pTiré = new Phrase("\n------------------------------------------------------------------------------------------------------------------------------------------"); pTiré.SetLeading(0f, 0.5f); nouveauDocument.Add(pTiré); //--------------------------------------FIN TABLEAU RECAP------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- if (donneeFoot["Tot_libreg"] == "") // Condition si réglement par traites { PdfPTable tableauTraiteHaut = new PdfPTable(3); tableauTraiteHaut.TotalWidth = 565; tableauTraiteHaut.LockedWidth = true; PdfPCell cellBlancheTraite = new PdfPCell(); cellBlancheTraite.Border = PdfPCell.NO_BORDER; tableauTraiteHaut.AddCell(cellBlancheTraite); PdfPCell cellTraiteHaut = new PdfPCell(); cellTraiteHaut.SetLeading(1f, 0.5f); PdfPCell cellTraiteHautD = new PdfPCell(); cellTraiteHautD.SetLeading(1f, 0.5f); cellTraiteHaut.Border = PdfPCell.NO_BORDER; cellTraiteHautD.Border = PdfPCell.NO_BORDER; cellTraiteHaut.AddElement(new Phrase("Contre cette LETTRE de CHANGE stipulée SANS FRAIS veuillez payer la somme indiquée ci-dessous à l'ordre de :", FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); tableauTraiteHaut.AddCell(cellTraiteHaut); cellTraiteHautD.AddElement(new Phrase(" " + donneeFoot["Tra_libacc"] + " " + donneeFoot["Tra_lcr"], FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); tableauTraiteHaut.AddCell(cellTraiteHautD); tableauTraiteHaut.SpacingAfter = -10f; nouveauDocument.Add(tableauTraiteHaut); //--------------------------Tableau Traite principal------------------------------------------------------------------------------------------------------- PdfPTable tableauTraite = new PdfPTable(3); //tableauTraite.SpacingBefore = -10f; tableauTraite.TotalWidth = 565; tableauTraite.LockedWidth = true; PdfPCell cellTraiteMiG = new PdfPCell(); cellTraiteMiG.Border = PdfPCell.NO_BORDER; Paragraph pcellTraiteHG = new Paragraph(); pcellTraiteHG.Add(new Phrase("\nA " + donneeFoot["Tra_lieucr"]+"\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); pcellTraiteHG.Add(new Phrase("Montant pour controle Date de création\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); pcellTraiteHG.Add(new Phrase("|"+donneeFoot["Tra_montae"] + "| |" + donneeFoot["Tra_datrel"]+"|", FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); pcellTraiteHG.Add(new Phrase("\n| ", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.UNDERLINE))); pcellTraiteHG.Add(new Phrase("|\n RIB du tiré .", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.UNDERLINE))); cellTraiteMiG.AddElement(pcellTraiteHG); cellTraiteMiG.HorizontalAlignment = PdfPCell.ALIGN_RIGHT; PdfPCell cellTraiteMiM = new PdfPCell(); cellTraiteMiM.Border = PdfPCell.NO_BORDER; Paragraph pcellTraiteHM = new Paragraph(); pcellTraiteHM.Add(new Phrase("\n\nEchéance\n ", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); pcellTraiteHM.Add(new Phrase("| " + donneeFoot["Tra_datech"] + " |", FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); pcellTraiteHM.Add(new Phrase(" |" + donneeFoot["Tra_cocpt"] + "|\n", FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); pcellTraiteHM.Add(new Phrase(" Ref.tiré ", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cellTraiteMiM.AddElement(pcellTraiteHM); cellTraiteMiM.HorizontalAlignment = PdfPCell.ALIGN_RIGHT; PdfPCell cellTraiteMiD = new PdfPCell(); cellTraiteMiD.Border = PdfPCell.NO_BORDER; cellTraiteMiD.AddElement(new Phrase("\n CODE MONNAIE ISO\n",FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); cellTraiteMiD.AddElement(new Phrase(" EUR\n", FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); cellTraiteMiD.AddElement(new Phrase("Montant\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cellTraiteMiD.AddElement(new Phrase(" *****" + donneeFoot["Tra_montae"] + "***", FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); cellTraiteMiD.PaddingLeft = 70; tableauTraite.AddCell(cellTraiteMiG); tableauTraite.AddCell(cellTraiteMiM); tableauTraite.AddCell(cellTraiteMiD); //------------FIN LIGNE MILEU TABLEAU--------------- PdfPCell cellTraiteBasG = new PdfPCell(); cellTraiteBasG.Border = PdfPCell.NO_BORDER; cellTraiteBasG.AddElement(new Phrase("|" + donneeFoot["Tra_banque"] + " | " + donneeFoot["Tra_guichet"] + " | " + donneeFoot["Tra_cptco"] + " | " + donneeFoot["Tra_rib"]+"|\n", FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); cellTraiteBasG.AddElement(new Phrase("Code établ. Code guichet N°de Compte Clé RIB\n", FontFactory.GetFont(FontFactory.HELVETICA, 6, Font.NORMAL))); cellTraiteBasG.AddElement(new Phrase("Valeur en:", FontFactory.GetFont(FontFactory.HELVETICA, 7, Font.NORMAL))); cellTraiteBasG.AddElement(new Phrase("ACCEPTATION OU AVAL", FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); cellTraiteBasG.AddElement(new Phrase(" NOM\n et ADRESSE", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cellTraiteBasG.AddElement(new Phrase("\nN° SIREN du TIRE "+donneeFoot["Tra_siren"],FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); PdfPCell cellTraiteBasM = new PdfPCell(); cellTraiteBasM.Border = PdfPCell.NO_BORDER; cellTraiteBasM.AddElement(new Phrase(" "+donneeFoot["Tra_tiers_adf1"]+"\n",FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cellTraiteBasM.AddElement(new Phrase(" " + donneeFoot["Tra_tiers_adf2"] + "\n\n\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cellTraiteBasM.AddElement(new Phrase(" " + donneeFoot["Tra_tiers_adfcp"] + " " + donneeFoot["Tra_tiers_adf6"], FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); PdfPCell cellTraiteBasD = new PdfPCell(); cellTraiteBasD.Border = PdfPCell.NO_BORDER; cellTraiteBasD.AddElement(new Phrase(" DOMICILIATION .\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.UNDERLINE))); cellTraiteBasD.AddElement(new Phrase("| " + donneeFoot["Tra_domic1"] + " |\n", FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); cellTraiteBasD.AddElement(new Phrase("| " + donneeFoot["Tra_domic2"] + " |\n", FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); cellTraiteBasD.AddElement(new Phrase(" Signature ", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cellTraiteBasD.AddElement(new Phrase("\n\nCLIENT N° " + donneeFoot["Tra_nocli"] + " RELEVE N° " + donneeFoot["Tra_numrel"], FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); tableauTraite.AddCell(cellTraiteBasG);tableauTraite.AddCell(cellTraiteBasM);tableauTraite.AddCell(cellTraiteBasD); nouveauDocument.Add(tableauTraite); } nouveauDocument.Close(); incCopie++; //--------------------------------------------------COPIE GED-------------------------------------------------------- string nomADH = ""; string numcli = ""; try { String connectionString = ConfigurationManager.AppSettings["ChaineDeConnexionBase"]; OdbcConnection conn = new OdbcConnection(connectionString); conn.Open(); //string requete = "select T1.NOCLI c1 , T1.NOMCL c2 from B00C0ACR.AMAGESTCOM.ACLIENL1 T1 where T1.NOCLI = '" + donneeFoot["Tra_nocli"] + "'"; numcli = donneEntete["Tiers_nocpt"].Substring(3, 6); string requete = "select T1.NOCLI c1 , T1.NOMCL c2 from B00C0ACR.AMAGESTCOM.ACLIENL1 T1 where T1.NOCLI = '" + numcli + "'"; OdbcCommand act = new OdbcCommand(requete, conn); OdbcDataReader act0 = act.ExecuteReader(); //string nomADH = ""; //act0.Read(); while (act0.Read()) { nomADH = (act0.GetString(1)); nomADH = nomADH.Trim(); /*test recup nom*/ // LogHelper.WriteToFile("requete : ", requete + "-" + numcli); } conn.Close(); /*if (!System.IO.Directory.Exists(ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneeFoot["Tra_nocli"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM") + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Facturation\\")) { System.IO.Directory.CreateDirectory(ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneeFoot["Tra_nocli"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Facturation\\"); System.IO.File.Copy(chemin, ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneeFoot["Tra_nocli"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Facturation\\RELEVE" + "\\" + nomDoc + "_" + donneeFoot["Tra_nocli"] + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"); } else { System.IO.File.Copy(chemin, ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneeFoot["Tra_nocli"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Facturation\\RELEVE" + nomDoc + "_" + donneeFoot["Tra_nocli"] + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"); }*/ if (!System.IO.Directory.Exists(ConfigurationManager.AppSettings["cheminGED"] + "\\" + numcli + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM") + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Facturation\\")) { System.IO.Directory.CreateDirectory(ConfigurationManager.AppSettings["cheminGED"] + "\\" + numcli + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Facturation\\"); System.IO.File.Copy(chemin, ConfigurationManager.AppSettings["cheminGED"] + "\\" + numcli + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Facturation\\RELEVE" + "\\" + nomDoc + "_" + donneeFoot["Tra_nocli"] + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"); } else { System.IO.File.Copy(chemin, ConfigurationManager.AppSettings["cheminGED"] + "\\" + numcli + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Facturation\\RELEVE" + nomDoc + "_" + donneeFoot["Tra_nocli"] + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"); } } catch (Exception e) { LogHelper.WriteToFile(e.Message, "nomAdh : " + nomADH + "-"+ numcli + "ENVOI GED Releve"); } //----------------------------------------------FIN COPIE---------------------------------------------------------- //Requette qui retourne le champ "OUI/NON" envoi mail facture String connectionString2 = ConfigurationManager.AppSettings["ChaineDeConnexionBase"]; OdbcConnection conn2 = new OdbcConnection(connectionString2); conn2.Open(); //Requete de séléction sur le champ "envoi facture par mail" string requete2 = "select T1.NOCLI c1 , T1.CLID5 c2 , T1.RENDI c3 , T1.PROFE c4 from B00C0ACR.AMAGESTCOM.ACLIENL1 T1 where T1.CLID5 = 'OUI'"; OdbcCommand act2 = new OdbcCommand(requete2, conn2); OdbcDataReader act20 = null; bool effectuerImpression = true; string numCli =""; try { act20 = act2.ExecuteReader(); while (act20.Read()) { numCli = donneEntete["Tiers_nocpt"].Substring(3, 6); /*ND 27 10 15 correction erreur généré recherche facture oui ou non donnée entete inexistante car code compte*/ // if(act20.GetString(0) == donneEntete["Client_code"])// Si le code client est égale au résultat de la requete sur la ligne lu "NOCLI" if (act20.GetString(0) == numCli)// Si le code client est égale au résultat de la requete sur la ligne lu "NOCLI" { if(act20.GetString(1) == "OUI") //Si la ligne de l'enrigistrement dans la base est à OUI pour cet ID, alors ne pas imprimer { effectuerImpression = false; } } } } catch (Exception e) { LogHelper.WriteToFile(e.Message, "Erreur de connexion à la base, rupture d'impression"); } if (effectuerImpression == true) { int nbImp = 0; int nbImpOK = 0; string[] printer = new string[20]; // tableau qui contient les imprimantes du profil d'impression ProfilImprimante profil = new ProfilImprimante(); profil.chargementXML("Facture"); // chargement selon le type de doc string vendeur = unProfil.Substring(2, 3); vendeur = vendeur.TrimEnd(); var listeProfil = profil.getDonneeProfil(); try { foreach (string v in listeProfil[vendeur]) //lecture des imprimantes liée à un profil { printer[nbImp] = v.ToString(); nbImp++; //on incrémente le nombre d'impression à executer } } catch { printer[nbImp] = ConfigurationManager.AppSettings["ImpDef"]; //Imprimante par defaut (essai) nbImp++; } nbImp = nbImp - 1; while (nbImpOK <= nbImp) // boucle tant que le nombre d'impression fait n'à pas atteint le nombre d'impression demander { string printerName = printer[nbImpOK]; string inputFile = String.Format(@"{0}", chemin); try { //Envoi de l'ordre d'impression vers l'imprimante, les "switches" sont des arguments de la ligne de script "processor" de type GhostscriptProcessor using (GhostscriptProcessor processor = new GhostscriptProcessor()) { List<string> switches = new List<string>(); switches.Add("-empty"); switches.Add("-dPrinted"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOSAFER"); switches.Add("-dNumCopies=" + ConfigurationManager.AppSettings["NbCopieGC"]); switches.Add("-sDEVICE=" + ConfigurationManager.AppSettings["PiloteImpressionFacture"]); //switches.Add("-r360x360");//Pilote d'impression switches.Add("-sOutputFile=%printer%" + printerName); switches.Add("-f"); switches.Add(inputFile); processor.StartProcessing(switches.ToArray(), null); } nbImpOK++; } catch (Exception e) { //LogHelper.WriteToFile(e.Message, "ParseurBP" + donneEntete["Document_numero"].Trim()); LogHelper.WriteToFile(e.Message, "relevé" +donneEntete["Tiers_nocpt"].Trim()); } // incrément à chaque impression terminée } } } }