private void CalculateColumnsPositions(ModelsEntity.Offer res) { var maxColCharNo = new Dictionary <int, int>(); maxColCharNo.Add(1, res.OfferLines.Max(ol => ol.Product.ProductName.Count())); maxColCharNo.Add(2, res.OfferLines.Max(ol => ol.Quantity.ToString().Count())); maxColCharNo.Add(3, res.OfferLines.Max(ol => ol.W.Count())); maxColCharNo.Add(4, res.OfferLines.Max(ol => ol.Medium.Count())); maxColCharNo.Add(5, res.OfferLines.Max(ol => ol.AdditionalEquipment.Count())); maxColCharNo.Add(6, res.OfferLines.Max(ol => ol.SalesPrice.ToString().Count())); maxColCharNo.Add(7, res.OfferLines.Max(ol => ol.OfferLineProcess.Count())); maxColCharNo[1] = maxColCharNo[1] < col1Name.Length ? col1Name.Length : maxColCharNo[1]; maxColCharNo[2] = maxColCharNo[2] < col2Name.Length ? col2Name.Length : maxColCharNo[2]; maxColCharNo[3] = maxColCharNo[3] < col3Name.Length ? col3Name.Length : maxColCharNo[3]; maxColCharNo[4] = maxColCharNo[4] < col4Name.Length ? col4Name.Length : maxColCharNo[4]; maxColCharNo[5] = maxColCharNo[5] < col5Name.Length ? col5Name.Length : maxColCharNo[5]; maxColCharNo[6] = maxColCharNo[6] < col6Name.Length ? col6Name.Length : maxColCharNo[6]; maxColCharNo[7] = maxColCharNo[7] < col7Name.Length ? col7Name.Length : maxColCharNo[7]; double allScopeInCharNo = 0; foreach (var item in maxColCharNo) { allScopeInCharNo += item.Value; } double sample = availableScopeFroColumns / allScopeInCharNo; if (allScopeInCharNo < 83) { sample = 6.2; } col1Pos = 40; col2Pos = maxColCharNo[1] * sample + col1Pos + spaceBetweenColumns; col3Pos = maxColCharNo[2] * sample + col2Pos + spaceBetweenColumns; col4Pos = maxColCharNo[3] * sample + col3Pos + spaceBetweenColumns + 10; col5Pos = maxColCharNo[4] * sample + col4Pos + spaceBetweenColumns; col6Pos = maxColCharNo[5] * sample + col5Pos + spaceBetweenColumns; col7Pos = maxColCharNo[6] * sample + col6Pos + spaceBetweenColumns; }
private void DrawPageContent(ref PdfPage page, ModelsEntity.Offer res) { var gfx = XGraphics.FromPdfPage(page); var regularFont = new XFont("Times New Roman", 12, XFontStyle.Regular); var boldFont = new XFont("Times New Roman", 12, XFontStyle.Bold); var regularTableFont = new XFont("Times New Roman", 10, XFontStyle.Regular); var boldTableFont = new XFont("Times New Roman", 10, XFontStyle.Bold); var smallClauseFont = new XFont("Times New Roman", 9, XFontStyle.Regular); int height = marginTop + 40; var framePoints = new XPoint[5] { new XPoint(marginLeft, marginTop), new XPoint(page.Width - marginRight, marginTop), new XPoint(page.Width - marginRight, page.Height - marginBottom), new XPoint(marginLeft, page.Height - marginBottom), new XPoint(marginLeft, marginTop), }; var fieldSize = new XSize(page.Width - marginLeft - marginRight, lineHeight); var pageSize = new XSize(page.Width, page.Height); var blackPen = new XPen(XBrushes.Black); //gfx.DrawLines(blackPen, framePoints); gfx.DrawImage(XImage.FromFile("Resources\\Chemitex logo - gradienty_m.jpg"), page.Width - marginRight - marginLeft - 160, marginTop, 160, 70); gfx.DrawString("Oferta", regularFont, XBrushes.Black, new XRect(NewLine(ref height, 0), pageSize), XStringFormats.TopCenter); gfx.DrawString(res.Name, boldFont, XBrushes.Black, new XRect(NewLine(ref height, 0), pageSize), XStringFormats.TopCenter); NewLine(ref height); var projIdHeight = height; gfx.DrawString("Projekt id:", regularFont, XBrushes.Black, new XRect(NewLine(ref height), fieldSize), XStringFormats.TopLeft); gfx.DrawString(res.ProjectsId, boldFont, XBrushes.Black, new XRect(NewLine(ref height), fieldSize), XStringFormats.TopLeft); gfx.DrawString("Typ zamówienia:", regularFont, XBrushes.Black, new XRect(NewLine(ref height), fieldSize), XStringFormats.TopLeft); gfx.DrawString(res.OrderType, boldFont, XBrushes.Black, new XRect(NewLine(ref height), fieldSize), XStringFormats.TopLeft); gfx.DrawString("Status:", regularFont, XBrushes.Black, new XRect(NewLine(ref height), fieldSize), XStringFormats.TopLeft); gfx.DrawString(res.Status, boldFont, XBrushes.Black, new XRect(NewLine(ref height), fieldSize), XStringFormats.TopLeft); gfx.DrawString("Data oferty:", regularFont, XBrushes.Black, new XRect(NewLine(ref height), fieldSize), XStringFormats.TopLeft); gfx.DrawString(res.OfferDate?.ToString("dd-MM-yyyy"), boldFont, XBrushes.Black, new XRect(NewLine(ref height), fieldSize), XStringFormats.TopLeft); height = projIdHeight; gfx.DrawString("Klient:", regularFont, XBrushes.Black, new XRect(NewLine(ref height, 400), fieldSize), XStringFormats.TopLeft); gfx.DrawString(res.Clients.Name, boldFont, XBrushes.Black, new XRect(NewLine(ref height, 400), fieldSize), XStringFormats.TopLeft); gfx.DrawString("Data zamówienia:", regularFont, XBrushes.Black, new XRect(NewLine(ref height, 400), fieldSize), XStringFormats.TopLeft); gfx.DrawString(res.OrderDate?.ToString("dd-MM-yyyy"), boldFont, XBrushes.Black, new XRect(NewLine(ref height, 400), fieldSize), XStringFormats.TopLeft); gfx.DrawString("Planowane zakończenie:", regularFont, XBrushes.Black, new XRect(NewLine(ref height, 400), fieldSize), XStringFormats.TopLeft); gfx.DrawString(res.PlannedEnd?.ToString("dd-MM-yyyy"), boldFont, XBrushes.Black, new XRect(NewLine(ref height, 400), fieldSize), XStringFormats.TopLeft); NewLine(ref height); NewLine(ref height); NewLine(ref height); gfx.DrawString("Pozycje oferty", regularFont, XBrushes.Black, new XRect(NewLine(ref height, 0), pageSize), XStringFormats.TopCenter); gfx.DrawLine(blackPen, NewLine(ref height), new XPoint(page.Width - marginLeft - marginRight, height)); DrawOfferLineHeaderRow(ref gfx, ref height, boldTableFont, ref page); //var oldHeight = height; foreach (var ol in res.OfferLines) { gfx.DrawLine(blackPen, NewLine(ref height), new XPoint(page.Width - marginLeft - marginRight, height)); DrawOfferLineRow(ref gfx, ref height, regularTableFont, ref page, ol); } //gfx.DrawLine(blackPen, new XPoint(col1Pos, oldHeight), new XPoint(col1Pos, height + interline)); //gfx.DrawLine(blackPen, new XPoint(col2Pos, oldHeight), new XPoint(col2Pos, height + interline)); //gfx.DrawLine(blackPen, new XPoint(col3Pos, oldHeight), new XPoint(col3Pos, height + interline)); //gfx.DrawLine(blackPen, new XPoint(col4Pos, oldHeight), new XPoint(col4Pos, height + interline)); //gfx.DrawLine(blackPen, new XPoint(col5Pos, oldHeight), new XPoint(col5Pos, height + interline)); //gfx.DrawLine(blackPen, new XPoint(col6Pos, oldHeight), new XPoint(col6Pos, height + interline)); //gfx.DrawLine(blackPen, new XPoint(col7Pos, oldHeight), new XPoint(col7Pos, height + interline)); NewLine(ref height); NewLine(ref height); var xtxtf = new XTextFormatter(gfx); xtxtf.Alignment = XParagraphAlignment.Center; xtxtf.DrawString(File.ReadAllText("Resources\\ClausePdfText.txt"), smallClauseFont, XBrushes.Black, new XRect(NewLine(ref height, 0), pageSize)); }