private void SamplePage2(PdfDocument document) { PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); gfx.MUH = PdfFontEncoding.Unicode; Document doc = new Document(); MigraDoc.Rendering.DocumentRenderer docRender = new MigraDoc.Rendering.DocumentRenderer(doc); docRender.PrepareDocument(); XRect A4Rect = new XRect(0, 0, XUnit.FromCentimeter(21).Point, XUnit.FromCentimeter(29.7).Point); int pageCount = docRender.FormattedDocument.PageCount; for (int idx = 0; idx < pageCount; idx++) { XRect rect = GetRect(idx); XGraphicsContainer container = gfx.BeginContainer(rect, A4Rect, XGraphicsUnit.Point); gfx.DrawRectangle(XPens.LightGray, A4Rect); docRender.RenderPage(gfx, idx + 1); gfx.EndContainer(container); } }
internal static byte[] GenerateApplicationPdf(Application application) { //Create pdf document PdfDocument pdf = new PdfDocument(); PdfPage page = pdf.AddPage(); //Create pdf content Document doc = CreateDocument("Application", string.Format("{1}, {0}",application.Person.Name, application.Person.Surname)); PopulateDocument(ref doc, application); //Create renderer for content DocumentRenderer renderer = new DocumentRenderer(doc); renderer.PrepareDocument(); XRect A4 = new XRect(0, 0, XUnit.FromCentimeter(21).Point, XUnit.FromCentimeter(29.7).Point); XGraphics gfx = XGraphics.FromPdfPage(page); int pages = renderer.FormattedDocument.PageCount; for(int i = 0; i < pages; i++) { var container = gfx.BeginContainer(A4, A4, XGraphicsUnit.Point); gfx.DrawRectangle(XPens.LightGray, A4); renderer.RenderPage(gfx, (i + 1)); gfx.EndContainer(container); } using (MemoryStream ms = new MemoryStream()) { pdf.Save(ms, true); return ms.ToArray(); } }
internal FormattedCell(Cell cell, DocumentRenderer documentRenderer, Borders cellBorders, FieldInfos fieldInfos, XUnit xOffset, XUnit yOffset) { this.cell = cell; this.fieldInfos = fieldInfos; this.yOffset = yOffset; this.xOffset = xOffset; this.bordersRenderer = new BordersRenderer(cellBorders, null); this.documentRenderer = documentRenderer; }
internal FormattedCell(Cell cell, DocumentRenderer documentRenderer, Borders cellBorders, FieldInfos fieldInfos, XUnit xOffset, XUnit yOffset) { _cell = cell; _fieldInfos = fieldInfos; _yOffset = yOffset; _xOffset = xOffset; _bordersRenderer = new BordersRenderer(cellBorders, null); _documentRenderer = documentRenderer; }
static void DrawCenterText(Document doc, MigraDoc.Rendering.DocumentRenderer docRenderer, XGraphics gfx, Color color, String fontName, Unit fontSize, String text, double x, double y, double width = 5) { DrawFormatted(doc, docRenderer, gfx, color, fontName, fontSize, ParagraphAlignment.Center, text, x, y, width); }
static void DrawRightValue(Document doc, MigraDoc.Rendering.DocumentRenderer docRenderer, XGraphics gfx, Color color, String fontName, Unit fontSize, float value, double x, double y, double width = 5) { DrawFormattedValue(doc, docRenderer, gfx, color, fontName, fontSize, ParagraphAlignment.Right, value, x, y, width); }
public static void ExportSchedulePage( Dictionary<int, Dictionary<string, Dictionary<int, Tuple<string, List<Tuple<Lesson, int>>, string>>>> schedule, string facultyName, string filename, string dow, ScheduleRepository repo, bool save, bool quit, bool print) { double scheduleFontsize = 10; int pageCount; Document document; do { // Create a new PDF document document = CreateDocument(repo, facultyName, dow, schedule, scheduleFontsize); // Create a renderer and prepare (=layout) the document var docRenderer = new DocumentRenderer(document); docRenderer.PrepareDocument(); pageCount = docRenderer.FormattedDocument.PageCount; scheduleFontsize -= 0.5; } while (pageCount > 1); // Render the file var pdfRenderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Always) {Document = document}; pdfRenderer.RenderDocument(); // Save the document... if (save) { pdfRenderer.PdfDocument.Save(filename); } // ...and start a viewer. //Process.Start(filename); if (print) { if (!save) { pdfRenderer.PdfDocument.Save(filename); } SendToPrinter(filename); } }
static void DrawFormatted(Document doc, MigraDoc.Rendering.DocumentRenderer docRenderer, XGraphics gfx, Color color, String fontName, Unit fontSize, ParagraphAlignment alignment, String text, double x, double y, double width = 5) { Section sec = doc.AddSection(); Paragraph para = sec.AddParagraph(); para.Format.Alignment = alignment; para.Format.Font.Name = fontName; para.Format.Font.Size = fontSize; para.Format.Font.Bold = true; para.Format.Font.Color = color; //para.Format.Borders.Color = color; //para.Format.LineSpacing = 10; //para.Format.LineSpacingRule = LineSpacingRule.Exactly; para.AddText(text); docRenderer.RenderObject(gfx, XUnit.FromCentimeter(x), XUnit.FromCentimeter(y), XUnit.FromCentimeter(width), para); }
private void SamplePage1(PdfDocument document) { PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); gfx.MUH = PdfFontEncoding.Unicode; XFont font = new XFont("Verdana", 13, XFontStyle.Bold); gfx.DrawString("The following paragraph was rendered using MigraDoc:", font, XBrushes.Black, new XRect(100, 100, page.Width - 100, 100), XStringFormats.Center); Document doc = new Document(); Section sec = doc.AddSection(); Paragraph para = sec.AddParagraph(); para.Format.Alignment = ParagraphAlignment.Justify; para.Format.Font.Name = "Times New Roman"; para.Format.Font.Size = 12; para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray; para.AddText("Duisism odigna acipsum delesenisl "); para.AddFormattedText("ullum in velenit"); para.AddText(" ipit iurero dolum zzriliquisis nit wis dolore vel et nonsequipit, velendigna " + "auguercilit lor se dipisl duismod tatem zzrit at laore magna feummod oloborting ea con vel " + "essit augiati onsequat luptat nos diatum vel ullum illummy nonsent nit ipis et nonsequis " + "niation utpat. Odolobor augait et non etueril landre min ut ulla feugiam commodo lortie ex " + "essent augait el ing eumsan hendre feugait prat augiatem amconul laoreet. ≤≥≈≠"); para.Format.Borders.Distance = "20pt"; para.Format.Borders.Color = Colors.Coral; MigraDoc.Rendering.DocumentRenderer documentRenderer = new MigraDoc.Rendering.DocumentRenderer(doc); documentRenderer.PrepareDocument(); documentRenderer.RenderObject(gfx, XUnit.FromCentimeter(5), XUnit.FromCentimeter(10), "12cm", para); }
/// <summary> /// Creates a fitting renderer for the given document object for formatting. /// </summary> /// <param name="gfx">The XGraphics object to do measurements on.</param> /// <param name="documentRenderer">The document renderer.</param> /// <param name="documentObject">the document object to format.</param> /// <param name="fieldInfos">The field infos.</param> /// <returns>The fitting Renderer.</returns> internal static Renderer Create(XGraphics gfx, DocumentRenderer documentRenderer, DocumentObject documentObject, FieldInfos fieldInfos) { Renderer renderer = null; if (documentObject is Paragraph) { renderer = new ParagraphRenderer(gfx, (Paragraph)documentObject, fieldInfos); } else if (documentObject is Table) { renderer = new TableRenderer(gfx, (Table)documentObject, fieldInfos); } else if (documentObject is PageBreak) { renderer = new PageBreakRenderer(gfx, (PageBreak)documentObject, fieldInfos); } else if (documentObject is TextFrame) { renderer = new TextFrameRenderer(gfx, (TextFrame)documentObject, fieldInfos); } else if (documentObject is Chart) { renderer = new ChartRenderer(gfx, (Chart)documentObject, fieldInfos); } else if (documentObject is Image) { renderer = new ImageRenderer(gfx, (Image)documentObject, fieldInfos); } if (renderer != null) { renderer._documentRenderer = documentRenderer; } return(renderer); }
void PrepareDocumentRenderer(bool prepareCompletely) { if (_document == null) #if !NETFX_CORE throw new InvalidOperationException(Messages2.PropertyNotSetBefore("DocumentRenderer", MethodBase.GetCurrentMethod().Name)); #else throw new InvalidOperationException(Messages2.PropertyNotSetBefore("DocumentRenderer", "PrepareDocumentRenderer")); #endif if (_documentRenderer == null) { _documentRenderer = new DocumentRenderer(_document); _documentRenderer.WorkingDirectory = _workingDirectory; } if (prepareCompletely && _documentRenderer.FormattedDocument == null) { _documentRenderer.PrepareDocument(); } }
internal FormattedDocument(Document document, DocumentRenderer documentRenderer) { _document = document; _documentRenderer = documentRenderer; }
bool StoreTempImage(string fileName) { try { const float resolution = 96; int horzPixels = (int)(GetShapeWidth().Inch * resolution); int vertPixels = (int)(GetShapeHeight().Inch * resolution); Bitmap bmp = new Bitmap(horzPixels, vertPixels); #if true XGraphics gfx = XGraphics.CreateMeasureContext(new XSize(horzPixels, vertPixels), XGraphicsUnit.Point, XPageDirection.Downwards); #else #if GDI XGraphics gfx = XGraphics.FromGraphics(Graphics.FromImage(bmp), new XSize(horzPixels, vertPixels)); #endif #if WPF // TODOWPF XGraphics gfx = null; //XGraphics.FromGraphics(Graphics.FromImage(bmp), new XSize(horzPixels, vertPixels)); #endif #endif //REM: Should not be necessary: gfx.ScaleTransform(resolution / 72); //gfx.PageUnit = XGraphicsUnit.Point; DocumentRenderer renderer = new DocumentRenderer(_chart.Document); renderer.RenderObject(gfx, 0, 0, GetShapeWidth().Point, _chart); bmp.SetResolution(resolution, resolution); bmp.Save(fileName, ImageFormat.Png); } catch (Exception) { return false; } return true; }
internal FormattedTextFrame(TextFrame textframe, DocumentRenderer documentRenderer, FieldInfos fieldInfos) { _textframe = textframe; _fieldInfos = fieldInfos; _documentRenderer = documentRenderer; }
public TopDownFormatter(IAreaProvider areaProvider, DocumentRenderer documentRenderer, DocumentElements elements) { _documentRenderer = documentRenderer; _areaProvider = areaProvider; _elements = elements; }
internal TopDownFormatter(IAreaProvider areaProvider, DocumentRenderer documentRenderer, DocumentElements elements) { this.documentRenderer = documentRenderer; this.areaProvider = areaProvider; this.elements = elements; }
internal FormattedTextArea(DocumentRenderer documentRenderer, TextArea textArea, FieldInfos fieldInfos) { TextArea = textArea; _fieldInfos = fieldInfos; _documentRenderer = documentRenderer; }
public FormattedDocument(Document document, DocumentRenderer documentRenderer) { _document = document; _documentRenderer = documentRenderer; }
internal FormattedHeaderFooter(HeaderFooter headerFooter, DocumentRenderer documentRenderer, FieldInfos fieldInfos) { _headerFooter = headerFooter; _fieldInfos = fieldInfos; _documentRenderer = documentRenderer; }
void PrepareDocumentRenderer(bool prepareCompletely) { if (document == null) throw new InvalidOperationException(Messages.PropertyNotSetBefore("DocumentRenderer", MethodBase.GetCurrentMethod().Name)); if (documentRenderer == null) { documentRenderer = new DocumentRenderer(document); documentRenderer.WorkingDirectory = WorkingDirectory; } if (prepareCompletely && documentRenderer.formattedDocument == null) { documentRenderer.PrepareDocument(); } }
internal FormattedDocument(Document document, DocumentRenderer documentRenderer) { this.document = document; this.documentRenderer = documentRenderer; }
private XUnit CalcContentHeight(DocumentRenderer documentRenderer) { XUnit height = RenderInfo.GetTotalHeight(GetRenderInfos()); if (height == 0) { height = ParagraphRenderer.GetLineHeight(this.cell.Format, this.gfx, documentRenderer); height += this.cell.Format.SpaceBefore; height += this.cell.Format.SpaceAfter; } return height; }
void PrepareDocumentRenderer() { if (this.document == null) throw new InvalidOperationException(Messages.PropertyNotSetBefore("DocumentRenderer", MethodInfo.GetCurrentMethod().Name)); this.documentRenderer = new DocumentRenderer(this.document); this.documentRenderer.WorkingDirectory = this.workingDirectory; this.documentRenderer.PrepareDocument(); }
internal FormattedDocument(Document document, DocumentRenderer documentRenderer) { this.document = document; this.documentRenderer = documentRenderer; }
internal TopDownFormatter(IAreaProvider areaProvider, DocumentRenderer documentRenderer, DocumentElements elements) { this.documentRenderer = documentRenderer; this.areaProvider = areaProvider; this.elements = elements; }
internal FormattedTextArea(DocumentRenderer documentRenderer, TextArea textArea, FieldInfos fieldInfos) { this.textArea = textArea; this.fieldInfos = fieldInfos; this.documentRenderer = documentRenderer; }
bool StoreTempImage(string fileName) { try { float resolution = 300; int horzPixels = (int)(GetShapeWidth().Inch * resolution); int vertPixels = (int)(GetShapeHeight().Inch * resolution); Bitmap bmp = new Bitmap(horzPixels, vertPixels); // Always renders to a Bitmap for embedding in output. XGraphics gfx = XGraphics.FromGraphics(Graphics.FromImage(bmp), new XSize(horzPixels, vertPixels)); //REM: Should not be necessary: gfx.ScaleTransform(resolution / 72); //gfx.PageUnit = XGraphicsUnit.Point; DocumentRenderer renderer = new DocumentRenderer(this.chart.Document); renderer.RenderObject(gfx, 0, 0, GetShapeWidth().Point, this.chart); bmp.SetResolution(resolution, resolution); bmp.Save(fileName, ImageFormat.Png); } catch (Exception) { return false; } return true; }
internal FormattedTextFrame(TextFrame textframe, DocumentRenderer documentRenderer, FieldInfos fieldInfos) { _textframe = textframe; _fieldInfos = fieldInfos; _documentRenderer = documentRenderer; }
/// <summary> /// Creates a fitting renderer for the given document object for formatting. /// </summary> /// <param name="gfx">The XGraphics object to do measurements on.</param> /// <param name="documentRenderer">The document renderer.</param> /// <param name="documentObject">the document object to format.</param> /// <param name="fieldInfos">The field infos.</param> /// <returns>The fitting Renderer.</returns> internal static Renderer Create(XGraphics gfx, DocumentRenderer documentRenderer, DocumentObject documentObject, FieldInfos fieldInfos) { Renderer renderer = null; if (documentObject is Paragraph) renderer = new ParagraphRenderer(gfx, (Paragraph)documentObject, fieldInfos); else if (documentObject is Table) renderer = new TableRenderer(gfx, (Table)documentObject, fieldInfos); else if (documentObject is PageBreak) renderer = new PageBreakRenderer(gfx, (PageBreak)documentObject, fieldInfos); else if (documentObject is TextFrame) renderer = new TextFrameRenderer(gfx, (TextFrame)documentObject, fieldInfos); else if (documentObject is Chart) renderer = new ChartRenderer(gfx, (Chart)documentObject, fieldInfos); else if (documentObject is Image) renderer = new ImageRenderer(gfx, (Image)documentObject, fieldInfos); else if (documentObject is Barcode) renderer = new BarcodeRenderer(gfx, (Barcode)documentObject, fieldInfos); if (renderer != null) renderer.documentRenderer = documentRenderer; return renderer; }
public static void AddSummaryTable(Document document, int year, Apartment apartment, Owner owner, Building building, bool useDefaultFolder = false) { // Initial data Document doc = document; Style style = doc.Styles["Normal"]; style.Font.Name = "Calibri"; style = doc.Styles.AddStyle("Table", "Normal"); style.Font.Name = "Calibri"; style.Font.Size = 12; var section = doc.LastSection; // Tables Table summaryTable = new Table(); Row[] summaryRows = new Row[14]; decimal[] paymentsSum = new decimal[12]; decimal[] chargesSum = new decimal[12]; int distinctGroupsCount; using (var db = new DB.DomenaDBContext()) { var charges = db.Charges.Include(x => x.Components).Include(x => x.Components.Select(y => y.GroupName)).Where(x => !x.IsDeleted && x.ApartmentId.Equals(apartment.ApartmentId) && x.ChargeDate.Year.Equals(year)); var componentsList = new List <ChargeComponent>(); foreach (var charge in charges) { componentsList.AddRange(charge.Components); } var groups = componentsList.Select(x => x.GroupName); var payments = db.Payments.Include(x => x.ChargeGroup).Where(x => !x.IsDeleted && x.ApartmentId == apartment.ApartmentId && x.PaymentRegistrationDate.Year == year); var paymentGroups = payments.Select(x => x.ChargeGroup); var allGroups = new List <BuildingChargeGroupName>(); allGroups.AddRange(groups); allGroups.AddRange(paymentGroups); var distinctGroups = allGroups.Distinct(); distinctGroupsCount = distinctGroups.Count(); var uniqueCategories = componentsList.GroupBy(x => x.CostCategoryId).Select(x => x.FirstOrDefault()).Select(x => x.CostCategoryId); summaryTable.Borders.Width = 0.5; summaryTable.AddColumn(Unit.FromCentimeter(2)); int columnsCount = distinctGroups.Count() * 2 + 3; for (int i = 0; i < columnsCount; i++) { var column = summaryTable.AddColumn(Unit.FromCentimeter((double)17 / columnsCount)); column.Format.Alignment = ParagraphAlignment.Center; } // |--Podsumowanie--| var summaryRow = summaryTable.AddRow(); summaryRow.Shading.Color = new Color(135, 176, 77); summaryRow.Cells[0].MergeRight = columnsCount; summaryRow.Cells[0].AddParagraph("Podsumowanie"); summaryRow.Cells[0].Format.Font.Bold = true; summaryRow.Cells[0].Format.Alignment = ParagraphAlignment.Center; // |--Miesiąc--|--G1--|--G2--|--Razem--| summaryRow = summaryTable.AddRow(); summaryRow.Shading.Color = new Color(135, 176, 77); summaryRow.Cells[0].MergeDown = 1; summaryRow.Cells[0].AddParagraph("Miesiąc"); summaryRow.Cells[0].Format.Font.Bold = true; summaryRow.Cells[0].VerticalAlignment = VerticalAlignment.Center; summaryRow.Cells[0].Format.Alignment = ParagraphAlignment.Center; int iter = 1; foreach (var dg in distinctGroups) { summaryRow.Cells[iter].MergeRight = 1; summaryRow.Cells[iter].AddParagraph(dg.GroupName); summaryRow.Cells[iter].Format.Font.Bold = true; summaryRow.Cells[iter].Format.Alignment = ParagraphAlignment.Center; iter += 2; } summaryRow.Cells[iter].MergeRight = 2; summaryRow.Cells[iter].AddParagraph("Razem"); summaryRow.Cells[iter].Format.Font.Bold = true; summaryRow.Cells[iter].Format.Alignment = ParagraphAlignment.Center; // |--Miesiąc (merged)--|--G1 wpłaty--|--G1 naliczenia--|--Suma wpłat--|--Suma naliczeń--|--Saldo--| summaryRow = summaryTable.AddRow(); summaryRow.Shading.Color = new Color(135, 176, 77); iter = 1; foreach (var dg in distinctGroups) { summaryRow.Cells[iter].AddParagraph(dg.GroupName + " wpłaty"); summaryRow.Cells[iter].Format.Font.Bold = true; summaryRow.Cells[iter].VerticalAlignment = VerticalAlignment.Center; summaryRow.Cells[iter].Format.Alignment = ParagraphAlignment.Center; iter++; summaryRow.Cells[iter].AddParagraph(dg.GroupName + " naliczenia"); summaryRow.Cells[iter].Format.Font.Bold = true; summaryRow.Cells[iter].VerticalAlignment = VerticalAlignment.Center; summaryRow.Cells[iter].Format.Alignment = ParagraphAlignment.Center; iter++; } summaryRow.Cells[iter].AddParagraph("Suma wpłat"); summaryRow.Cells[iter].Format.Font.Bold = true; summaryRow.Cells[iter].VerticalAlignment = VerticalAlignment.Center; summaryRow.Cells[iter].Format.Alignment = ParagraphAlignment.Center; iter++; summaryRow.Cells[iter].AddParagraph("Suma naliczeń"); summaryRow.Cells[iter].Format.Font.Bold = true; summaryRow.Cells[iter].VerticalAlignment = VerticalAlignment.Center; summaryRow.Cells[iter].Format.Alignment = ParagraphAlignment.Center; iter++; summaryRow.Cells[iter].AddParagraph("Saldo"); summaryRow.Cells[iter].Format.Font.Bold = true; summaryRow.Cells[iter].VerticalAlignment = VerticalAlignment.Center; summaryRow.Cells[iter].Format.Alignment = ParagraphAlignment.Center; iter++; summaryRows[0] = summaryTable.AddRow(); summaryRows[0].Cells[0].AddParagraph("Zeszły rok"); for (int i = 1; i < columnsCount; i++) { summaryRows[0].Cells[i].AddParagraph("-"); } decimal lastYearSaldo = Payments.CalculateSaldo(year - 1, apartment); decimal thisYearSaldo = lastYearSaldo; summaryRows[0].Cells[columnsCount].AddParagraph(lastYearSaldo + " zł"); for (int i = 1; i < 13; i++)//months { summaryRows[i] = summaryTable.AddRow(); summaryRows[i].Cells[0].AddParagraph(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(new DateTime(2000, i, 1).ToString("MMMM"))); } summaryRows[13] = summaryTable.AddRow(); summaryRows[13].Cells[0].AddParagraph("Razem"); summaryRows[13].Cells[0].Format.Font.Bold = true; int summaryGroupIterator = 1; foreach (var g in distinctGroups) { if (g != null) { Table address = OwnerTableInfo(owner, building, apartment); document.LastSection.Add(address); Paragraph sep = new Paragraph(); sep.Format.SpaceAfter = "0.5cm"; document.LastSection.Add(sep); // iterujemy po kazdej grupie a w srodku po kazdej kategorii + Wplty w grupie + suma var categoriesInGroup = componentsList.Where(x => x.GroupName != null && x.GroupName.BuildingChargeGroupNameId == g.BuildingChargeGroupNameId).GroupBy(x => x.CostCategoryId).Select(x => x.FirstOrDefault()).Select(x => x.CostCategoryId); Table groupTable = new Table(); groupTable.Borders.Width = 0.5; groupTable.AddColumn(Unit.FromCentimeter(2)); Column col; foreach (var cat in categoriesInGroup) { col = groupTable.AddColumn(Unit.FromCentimeter((double)14 / categoriesInGroup.Count())); col.Format.Alignment = ParagraphAlignment.Center; } col = groupTable.AddColumn(Unit.FromCentimeter(1.5)); col.Format.Alignment = ParagraphAlignment.Center; col = groupTable.AddColumn(Unit.FromCentimeter(1.5)); col.Format.Alignment = ParagraphAlignment.Center; // Header row Row currentRow = groupTable.AddRow(); currentRow.Shading.Color = new Color(135, 176, 77); Cell cell = currentRow.Cells[0]; cell.AddParagraph(g.GroupName); cell.Format.Font.Bold = true; cell.Format.Alignment = ParagraphAlignment.Center; cell.MergeRight = categoriesInGroup.Count() + 2; currentRow = groupTable.AddRow(); currentRow.Shading.Color = new Color(135, 176, 77); cell = currentRow.Cells[0]; cell.AddParagraph("Miesiąc"); cell.Format.Font.Bold = true; var iterator = 1; foreach (var cat in categoriesInGroup) { cell = currentRow.Cells[iterator]; cell.AddParagraph(db.CostCategories.FirstOrDefault(x => x.BuildingChargeBasisCategoryId == cat).CategoryName); cell.Format.Font.Bold = true; iterator++; } cell = currentRow.Cells[iterator]; cell.AddParagraph("Wpłaty"); cell.Format.Font.Bold = true; cell = currentRow.Cells[iterator + 1]; cell.AddParagraph("Saldo"); cell.Format.Font.Bold = true; decimal currentYear = 0; for (int i = 1; i < 13; i++)//months { currentRow = groupTable.AddRow(); cell = currentRow.Cells[0]; cell.AddParagraph(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(new DateTime(2000, i, 1).ToString("MMMM"))); var thisMonthComponents = new List <ChargeComponent>(); charges.Where(x => x.ChargeDate.Month == i).ToList().ForEach(x => thisMonthComponents.AddRange(x.Components)); decimal groupSum = 0; iterator = 1; foreach (var cat in categoriesInGroup) { var currentComponets = thisMonthComponents.Where(x => x.CostCategoryId == cat && x.GroupName.BuildingChargeGroupNameId == g.BuildingChargeGroupNameId); groupSum += currentComponets.Sum(x => x.Sum); currentRow.Cells[iterator].AddParagraph(currentComponets.Sum(x => x.Sum).ToString() + " zł"); iterator++; } //Wplaty var groupPayments = payments.Where(x => x.PaymentRegistrationDate.Month == i && x.ChargeGroup.BuildingChargeGroupNameId == g.BuildingChargeGroupNameId).Select(x => x.PaymentAmount).DefaultIfEmpty(0).Sum(); currentRow.Cells[iterator].AddParagraph(groupPayments.ToString() + " zł"); iterator++; summaryRows[i].Cells[summaryGroupIterator].AddParagraph(groupPayments.ToString() + " zł"); paymentsSum[i - 1] += groupPayments; //Suma currentRow.Cells[iterator].AddParagraph((groupPayments - groupSum).ToString() + " zł");//(groupPayments - groupSum).ToString() + " zł"; currentYear += groupPayments - groupSum; summaryRows[i].Cells[summaryGroupIterator + 1].AddParagraph(groupSum.ToString() + " zł"); chargesSum[i - 1] += groupSum; } currentRow = groupTable.AddRow(); cell = currentRow.Cells[0]; cell.AddParagraph("Razem"); cell.Format.Font.Bold = true; iterator = 1; foreach (var cat in categoriesInGroup) { cell = currentRow.Cells[iterator]; cell.AddParagraph("-"); cell.Format.Font.Bold = true; iterator++; } cell = currentRow.Cells[iterator]; cell.Format.Font.Bold = true; cell.AddParagraph("-"); cell = currentRow.Cells[iterator + 1]; cell.Format.Font.Bold = true; cell.AddParagraph(currentYear.ToString() + " zł"); document.LastSection.Add(groupTable); section.AddPageBreak(); summaryRows[13].Cells[summaryGroupIterator].AddParagraph("-"); summaryRows[13].Cells[summaryGroupIterator].Format.Font.Bold = true; summaryRows[13].Cells[summaryGroupIterator + 1].AddParagraph("-"); summaryRows[13].Cells[summaryGroupIterator + 1].Format.Font.Bold = true; summaryGroupIterator += 2; } } } // Summary table for (int i = 0; i < 12; i++) { summaryRows[i + 1].Cells[distinctGroupsCount * 2 + 1].AddParagraph(paymentsSum[i].ToString() + " zł"); summaryRows[i + 1].Cells[distinctGroupsCount * 2 + 2].AddParagraph(chargesSum[i].ToString() + " zł"); summaryRows[i + 1].Cells[distinctGroupsCount * 2 + 3].AddParagraph((paymentsSum[i] - chargesSum[i]).ToString() + " zł"); } summaryRows[13].Cells[distinctGroupsCount * 2 + 1].AddParagraph(paymentsSum.DefaultIfEmpty(0).Sum().ToString() + " zł"); summaryRows[13].Cells[distinctGroupsCount * 2 + 1].Format.Font.Bold = true; summaryRows[13].Cells[distinctGroupsCount * 2 + 2].AddParagraph(chargesSum.DefaultIfEmpty(0).Sum().ToString() + " zł"); summaryRows[13].Cells[distinctGroupsCount * 2 + 2].Format.Font.Bold = true; summaryRows[13].Cells[distinctGroupsCount * 2 + 3].AddParagraph((paymentsSum.DefaultIfEmpty(0).Sum() - chargesSum.DefaultIfEmpty(0).Sum()).ToString() + " zł"); summaryRows[13].Cells[distinctGroupsCount * 2 + 3].Format.Font.Bold = true; document.LastSection.Add(summaryTable); // Finish document and save MigraDoc.Rendering.DocumentRenderer docRenderer = new MigraDoc.Rendering.DocumentRenderer(doc); docRenderer.PrepareDocument(); PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always); renderer.Document = doc; renderer.RenderDocument(); try { if (!useDefaultFolder) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "PDF file|*.pdf"; sfd.Title = "Zapisz raport jako..."; sfd.ShowDialog(); if (sfd.FileName != "") { renderer.PdfDocument.Save(sfd.FileName); System.Diagnostics.Process.Start(sfd.FileName); } } else { System.IO.FileInfo file = new System.IO.FileInfo("Reports\\"); file.Directory.Create(); string filename = year.ToString() + "_" + building.Name + "_" + apartment.ApartmentNumber + ".pdf"; renderer.PdfDocument.Save(Path.Combine(file.FullName, filename.Replace(' ', '_'))); System.Diagnostics.Process.Start(Path.Combine(file.FullName, filename.Replace(' ', '_'))); } } catch (Exception e) { Log.Logger.Error("Error during pdf save", e); MessageBox.Show("Błąd zapisu pliku pdf. Zamknij wszystkie otwarte dokumenty pdf i spróbuj ponownie."); } }
internal FormattedTextArea(DocumentRenderer documentRenderer, TextArea textArea, FieldInfos fieldInfos) { this.textArea = textArea; this.fieldInfos = fieldInfos; this.documentRenderer = documentRenderer; }
internal FormattedHeaderFooter(HeaderFooter headerFooter, DocumentRenderer documentRenderer, FieldInfos fieldInfos) { _headerFooter = headerFooter; _fieldInfos = fieldInfos; _documentRenderer = documentRenderer; }
internal FormattedDocument(Document document, DocumentRenderer documentRenderer) { _document = document; _documentRenderer = documentRenderer; }
internal FormattedTextFrame(TextFrame textframe, DocumentRenderer documentRenderer, FieldInfos fieldInfos) { this.textframe = textframe; this.fieldInfos = fieldInfos; this.documentRenderer = documentRenderer; }
/// <summary> /// Creates a fitting renderer for the render info to render and layout with. /// </summary> /// <param name="gfx">The XGraphics object to render on.</param> /// <param name="documentRenderer">The document renderer.</param> /// <param name="renderInfo">The RenderInfo object stored after a previous call of Format().</param> /// <param name="fieldInfos">The field infos.</param> /// <returns>The fitting Renderer.</returns> internal static Renderer Create(XGraphics gfx, DocumentRenderer documentRenderer, RenderInfo renderInfo, FieldInfos fieldInfos) { Renderer renderer = null; if (renderInfo.DocumentObject is Paragraph) renderer = new ParagraphRenderer(gfx, renderInfo, fieldInfos); else if (renderInfo.DocumentObject is Table) renderer = new TableRenderer(gfx, renderInfo, fieldInfos); else if (renderInfo.DocumentObject is PageBreak) renderer = new PageBreakRenderer(gfx, renderInfo, fieldInfos); else if (renderInfo.DocumentObject is TextFrame) renderer = new TextFrameRenderer(gfx, renderInfo, fieldInfos); else if (renderInfo.DocumentObject is Chart) renderer = new ChartRenderer(gfx, renderInfo, fieldInfos); //else if (renderInfo.DocumentObject is Chart) // renderer = new ChartRenderer(gfx, renderInfo, fieldInfos); else if (renderInfo.DocumentObject is Image) renderer = new ImageRenderer(gfx, renderInfo, fieldInfos); if (renderer != null) renderer._documentRenderer = documentRenderer; return renderer; }
internal FormattedTextFrame(TextFrame textframe, DocumentRenderer documentRenderer, FieldInfos fieldInfos) { this.textframe = textframe; this.fieldInfos = fieldInfos; this.documentRenderer = documentRenderer; }
///// <summary> ///// Gets or sets the working directory. ///// </summary> //public string WorkingDirectory //{ // get // { // return this.workingDirectory; // } // set // { // this.workingDirectory = value; // } //} //string workingDirectory = ""; /// <summary> /// Called when the Ddl property has changed. /// </summary> void DdlUpdated() { if (this.ddl != null) { this.document = MigraDoc.DocumentObjectModel.IO.DdlReader.DocumentFromString(this.ddl); this.renderer = new DocumentRenderer(document); this.renderer.PrivateFonts = this.privateFonts; this.renderer.PrepareDocument(); Page = 1; this.preview.Invalidate(); } // if (this.job != null) // this.job.Dispose(); // // if (this.ddl == null || this.ddl == "") // return; // // this.job = new PrintJob(); // this.job.Type = JobType.Standard; // this.job.Ddl = this.ddl; // this.job.WorkingDirectory = this.workingDirectory; // this.job.InitDocument(); // this.preview = this.job.GetPreview(this.Handle); // this.previewHandle = this.preview.Hwnd; // // if (this.preview != null) // this.preview.Page = 1; }
internal TopDownFormatter(IAreaProvider areaProvider, DocumentRenderer documentRenderer, DocumentElements elements) { _documentRenderer = documentRenderer; _areaProvider = areaProvider; _elements = elements; }
/// <summary> /// Help function to receive a line height on empty paragraphs. /// </summary> /// <param name="format">The format.</param> /// <param name="gfx">The GFX.</param> /// <param name="renderer">The renderer.</param> internal static XUnit GetLineHeight(ParagraphFormat format, XGraphics gfx, DocumentRenderer renderer) { XFont font = FontHandler.FontToXFont(format.Font, renderer.PrivateFonts, gfx.MUH, gfx.MFEH); XUnit singleLineSpace = font.GetHeight(); switch (format.LineSpacingRule) { case LineSpacingRule.Exactly: return format.LineSpacing.Point; case LineSpacingRule.AtLeast: return Math.Max(format.LineSpacing.Point, font.GetHeight(gfx)); case LineSpacingRule.Multiple: return format.LineSpacing * format.Font.Size; case LineSpacingRule.OnePtFive: return 1.5 * singleLineSpace; case LineSpacingRule.Double: return 2.0 * singleLineSpace; case LineSpacingRule.Single: default: return singleLineSpace; } }
private void Button_Click_1(object sender, RoutedEventArgs e) { Books books = new Books(); PdfDocument document = new PdfDocument(); // Create a new PDF document document.Info.Title = "Created with PDFsharp"; document.Info.Author = "Faktury2020"; PdfPage page = document.AddPage(); // Create an empty page XGraphics gfx = XGraphics.FromPdfPage(page); // Get an XGraphics object for drawing XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode); // Set font encoding to unicode //albo mogę ew. spróbować jeśli przestanie działać: //gfx.MUH = PdfFontEncoding.Unicode; //gfx.MFEH = PdfFontEmbedding.Default; XFont font = new XFont("Times New Roman", 12, XFontStyle.Regular, options); //Then you'll create a font: Document doc = new Document(); //tu startuje migradoc, po kolei: dokument, sekcja i paragraf.. Section sec = doc.AddSection(); //def tableMiejsceiDataWystawienia TUTAJ Table tableMiejsceiDataWystawienia = new Table(); tableMiejsceiDataWystawienia.Borders.Width = 0.0; Column columnMiejsceiDataWystawienia = tableMiejsceiDataWystawienia.AddColumn(Unit.FromCentimeter(5)); columnMiejsceiDataWystawienia.Format.Alignment = ParagraphAlignment.Left; Column columnMiejsceiDataWystawienia2 = tableMiejsceiDataWystawienia.AddColumn(Unit.FromCentimeter(12)); columnMiejsceiDataWystawienia2.Format.Alignment = ParagraphAlignment.Right; Row rowMiejsceiDataWystawienia = tableMiejsceiDataWystawienia.AddRow(); Cell cellMiejsceiDataWystawienia = rowMiejsceiDataWystawienia.Cells[0]; cellMiejsceiDataWystawienia = rowMiejsceiDataWystawienia.Cells[0]; cellMiejsceiDataWystawienia.AddParagraph("Katowice"); // rowKontoBankowe.Format.Alignment = ParagraphAlignment.Right; cellMiejsceiDataWystawienia = rowMiejsceiDataWystawienia.Cells[1]; cellMiejsceiDataWystawienia.AddParagraph("Wystawiono dnia: 16-03-2020"); doc.LastSection.Add(tableMiejsceiDataWystawienia); //Paragraph miasto = sec.AddParagraph(); //miasto.AddText("Katowice"); //miasto.Format.Alignment = ParagraphAlignment.Left; //Paragraph dataWystawienia = sec.AddParagraph(); //dataWystawienia.AddText("Wystawiono dnia: 16-03-2020"); //dataWystawienia.Format.Alignment = ParagraphAlignment.Right; sec.AddParagraph(); Paragraph numerFaktury = sec.AddParagraph(); numerFaktury.AddText("Faktura proforma 1-TEST-2-2020"); numerFaktury.Format.Font.Bold = true; numerFaktury.Format.Alignment = ParagraphAlignment.Center; sec.AddParagraph(); Paragraph dataSprzedazy = sec.AddParagraph(); dataSprzedazy.AddText("Data sprzedaży: 2-2020"); dataSprzedazy.Format.Font.Bold = true; dataSprzedazy.Format.Alignment = ParagraphAlignment.Right; Paragraph sposobZaplaty = sec.AddParagraph(); sposobZaplaty.AddText("Forma płatności: GOTÓWKA"); sposobZaplaty.Format.Font.Bold = true; sposobZaplaty.Format.Alignment = ParagraphAlignment.Right; Paragraph terminPlatnosci = sec.AddParagraph(); terminPlatnosci.AddText("Termin płatności: 01-04-2020"); terminPlatnosci.Format.Font.Bold = true; terminPlatnosci.Format.Alignment = ParagraphAlignment.Right; //def table sprzedawca-nabywca(SN) and its parts Table tableSN = new Table(); tableSN.Borders.Width = 0.0; Column columnSN = tableSN.AddColumn(Unit.FromCentimeter(9)); columnSN.Format.Alignment = ParagraphAlignment.Left; _ = tableSN.AddColumn(Unit.FromCentimeter(9)); columnSN.Format.Alignment = ParagraphAlignment.Left; Row rowSN = tableSN.AddRow(); Cell cellSN = rowSN.Cells[0]; cellSN = rowSN.Cells[0]; cellSN.AddParagraph("Sprzedawca"); cellSN.Format.Font.Bold = true; cellSN = rowSN.Cells[1]; cellSN.AddParagraph("Nabywca"); cellSN.Format.Font.Bold = true; Row rowEmpty = tableSN.AddRow(); Cell cellEmpty = rowEmpty.Cells[0]; cellEmpty = rowEmpty.Cells[0]; // cellEmpty.AddParagraph(""); //to jest niepotrzebne = i tak jest pusta linia cellEmpty = rowEmpty.Cells[1]; // cellEmpty.AddParagraph(""); //to jest niepotrzebne = i tak jest pusta linia Row rowNazwaSprzedawcyiNabywcy = tableSN.AddRow(); Cell cellNazwaSprzedawcyiNabywcy = rowEmpty.Cells[0]; cellNazwaSprzedawcyiNabywcy = rowNazwaSprzedawcyiNabywcy.Cells[0]; cellNazwaSprzedawcyiNabywcy.AddParagraph("xSolutions Sp. z o.o."); cellNazwaSprzedawcyiNabywcy.Format.Font.Bold = true; cellNazwaSprzedawcyiNabywcy = rowNazwaSprzedawcyiNabywcy.Cells[1]; cellNazwaSprzedawcyiNabywcy.AddParagraph("Aldona Nieznana"); cellNazwaSprzedawcyiNabywcy.Format.Font.Bold = true; Row rowUlicaSprzedawcyiNabywcy = tableSN.AddRow(); Cell cellUlicaSprzedawcyiNabywcy = rowEmpty.Cells[0]; cellUlicaSprzedawcyiNabywcy = rowUlicaSprzedawcyiNabywcy.Cells[0]; cellUlicaSprzedawcyiNabywcy.AddParagraph("ul. Mickiewicza 29"); cellUlicaSprzedawcyiNabywcy = rowUlicaSprzedawcyiNabywcy.Cells[1]; cellUlicaSprzedawcyiNabywcy.AddParagraph("ul Nieznana 20"); Row rowMiastoiKodSprzedawcyiNabywcy = tableSN.AddRow(); Cell cellMiastoiKodSprzedawcyiNabywcy = rowEmpty.Cells[0]; cellMiastoiKodSprzedawcyiNabywcy = rowUlicaSprzedawcyiNabywcy.Cells[0]; cellMiastoiKodSprzedawcyiNabywcy.AddParagraph("40-085 Katowice"); cellMiastoiKodSprzedawcyiNabywcy = rowUlicaSprzedawcyiNabywcy.Cells[1]; cellMiastoiKodSprzedawcyiNabywcy.AddParagraph("41-200 Sosnowiec"); Row rowEmpty2 = tableSN.AddRow(); // Cell cellEmpty2 = rowEmpty2.Cells[0]; //cellEmpty2 = rowEmpty2.Cells[0]; //cellEmpty2 = rowEmpty2.Cells[1]; Row rowNIPSprzedawcyiNabywcy = tableSN.AddRow(); Cell cellNIPSprzedawcyiNabywcy = rowEmpty.Cells[0]; cellNIPSprzedawcyiNabywcy = rowNIPSprzedawcyiNabywcy.Cells[0]; cellNIPSprzedawcyiNabywcy.AddParagraph("NIP 634-293-59-61"); cellNIPSprzedawcyiNabywcy.Format.Font.Bold = true; cellNIPSprzedawcyiNabywcy = rowNIPSprzedawcyiNabywcy.Cells[1]; cellNIPSprzedawcyiNabywcy.AddParagraph("NIP 000-000-00-00"); cellNIPSprzedawcyiNabywcy.Format.Font.Bold = true; Row rowEmpty3 = tableSN.AddRow(); //def table bank i konto bankowe Table tableBankiKontoBankowe = new Table(); tableBankiKontoBankowe.Borders.Width = 0.0; Column columnBankiKontoBankowe1 = tableBankiKontoBankowe.AddColumn(Unit.FromCentimeter(5)); columnBankiKontoBankowe1.Format.Alignment = ParagraphAlignment.Right; Column columnBankiKontoBankowe2 = tableBankiKontoBankowe.AddColumn(Unit.FromCentimeter(9)); columnBankiKontoBankowe2.Format.Alignment = ParagraphAlignment.Left; Row rowBankiKontoBankowe = tableBankiKontoBankowe.AddRow(); Cell cellBankiKontoBankowe = rowBankiKontoBankowe.Cells[0]; cellBankiKontoBankowe = rowBankiKontoBankowe.Cells[0]; cellBankiKontoBankowe.AddParagraph("Bank: "); cellBankiKontoBankowe.Format.Font.Bold = true; cellBankiKontoBankowe = rowBankiKontoBankowe.Cells[1]; cellBankiKontoBankowe.AddParagraph("Nest Bank"); cellBankiKontoBankowe.Format.Font.Bold = true; //def konto bankowe Row rowKontoBankowe = tableBankiKontoBankowe.AddRow(); Cell cellKontoBankowe = rowKontoBankowe.Cells[0]; cellKontoBankowe = rowKontoBankowe.Cells[0]; cellKontoBankowe.AddParagraph("Konto: "); // rowKontoBankowe.Format.Alignment = ParagraphAlignment.Right; cellKontoBankowe.Format.Font.Bold = true; cellKontoBankowe = rowKontoBankowe.Cells[1]; cellKontoBankowe.AddParagraph("44 2530 0008 2064 1044 1937 0001"); cellKontoBankowe.Format.Font.Bold = true; Row rowEmpty4 = tableBankiKontoBankowe.AddRow(); // chcę, aby 'POZYCJE FAKTURY' było napisane nie w obramowaniu a nad tabelą, robię więc manewr polegający na przedłużeniu niewidocznej tabeli Row rowPozycjeFaktury = tableBankiKontoBankowe.AddRow(); Cell cellPozycjeFaktury = rowPozycjeFaktury.Cells[1]; cellPozycjeFaktury = rowPozycjeFaktury.Cells[1]; cellPozycjeFaktury.AddParagraph("POZYCJE FAKTURY"); cellPozycjeFaktury.Format.Font.Bold = true; rowPozycjeFaktury.Format.Alignment = ParagraphAlignment.Left; doc.LastSection.Add(tableSN); doc.LastSection.Add(tableBankiKontoBankowe); //def table Pozycje-Faktury(PF) Table table = new Table(); table.Borders.Width = 0.5; //def column Lp Column column = table.AddColumn(Unit.FromCentimeter(1)); //def colum NazwaTowaruLubUsługi _ = table.AddColumn(Unit.FromCentimeter(6)); // def column Ilość _ = table.AddColumn(Unit.FromCentimeter(1)); // def column Jednostka _ = table.AddColumn(Unit.FromCentimeter(1.5)); // def column Wartość jednostkowa brutto _ = table.AddColumn(Unit.FromCentimeter(4)); // def column Wartość brutto _ = table.AddColumn(Unit.FromCentimeter(3)); //def header of table Row row = table.AddRow(); Cell cell0 = row.Cells[0]; cell0.AddParagraph("Lp."); cell0.Format.Font.Bold = true; cell0.Format.Alignment = ParagraphAlignment.Center; Cell cell1 = row.Cells[1]; cell1.AddParagraph("Nazwa towaru lub usługi"); cell1.Format.Font.Bold = true; cell1.Format.Alignment = ParagraphAlignment.Center; Cell cell2 = row.Cells[2]; cell2.AddParagraph("Ilość"); cell2.Format.Font.Bold = true; cell2.Format.Alignment = ParagraphAlignment.Center; Cell cell3 = row.Cells[3]; cell3.AddParagraph("Jedn."); cell3.Format.Font.Bold = true; cell3.Format.Alignment = ParagraphAlignment.Center; Cell cell4 = row.Cells[4]; cell4.AddParagraph("Wartość jednostkowa brutto PLN"); cell4.Format.Font.Bold = true; cell4.Format.Alignment = ParagraphAlignment.Center; Cell cell5 = row.Cells[5]; cell5.AddParagraph("Wartość brutto \n PLN"); cell5.Format.Font.Bold = true; cell5.Format.Alignment = ParagraphAlignment.Center; Row row2 = table.AddRow(); Cell cellR2C0 = row2.Cells[0]; cellR2C0.AddParagraph("1"); cellR2C0.Format.Alignment = ParagraphAlignment.Center; Cell cellR2C1 = row2.Cells[1]; cellR2C1.AddParagraph("Abonament xBiuro - pakiet STANDARD na 12-MIESIĘCY"); cellR2C1.Format.Alignment = ParagraphAlignment.Center; Cell cellR2C2 = row2.Cells[2]; cellR2C2.AddParagraph("1"); cellR2C2.Format.Alignment = ParagraphAlignment.Center; Cell cellR2C3 = row2.Cells[3]; cellR2C3.AddParagraph("usługa"); cellR2C3.Format.Alignment = ParagraphAlignment.Center; Cell cellR2C4 = row2.Cells[4]; cellR2C4.AddParagraph("723,24"); cellR2C4.Format.Alignment = ParagraphAlignment.Center; Cell cellR2C5 = row2.Cells[5]; cellR2C5.AddParagraph("723,24"); cellR2C5.Format.Alignment = ParagraphAlignment.Center; //foreach (var elem in books) //{ // row = table.AddRow(); // cell = row.Cells[0]; // cell.AddParagraph(elem.author); // cell = row.Cells[1]; // cell.AddParagraph(elem.title); // cell = row.Cells[2]; // cell.AddParagraph(elem.year.ToString()); //} //add table to document doc.LastSection.Add(table); Paragraph slownie = sec.AddParagraph(); slownie.Format.Font.Bold = true; slownie.AddText("\n SŁOWNIE: SIEDEMSET DWADZIEŚCIA TRZY ZŁOTE I 24/100 GROSZY BRUTTO"); //def tablePODSUMOWANIE Razem, Zapłacono, Pozostało do zapłaty Table tablePodsumowanie = new Table(); tablePodsumowanie.Borders.Width = 0.5; Column columnPodsumowanie1 = tablePodsumowanie.AddColumn(Unit.FromCentimeter(8.25)); columnPodsumowanie1.Format.Alignment = ParagraphAlignment.Right; Column columnPodsumowanie2 = tablePodsumowanie.AddColumn(Unit.FromCentimeter(8.25)); columnPodsumowanie2.Format.Alignment = ParagraphAlignment.Center; Row rowPodsumowanie1 = tablePodsumowanie.AddRow(); Cell cellPodsumowanie1 = rowPodsumowanie1.Cells[0]; cellPodsumowanie1 = rowPodsumowanie1.Cells[0]; cellPodsumowanie1.AddParagraph("Razem"); cellPodsumowanie1.Format.Font.Bold = true; cellPodsumowanie1 = rowPodsumowanie1.Cells[1]; cellPodsumowanie1.AddParagraph("723,24 PLN"); cellPodsumowanie1.Format.Font.Bold = false; Row rowPodsumowanie2 = tablePodsumowanie.AddRow(); Cell cellPodsumowanie2 = rowPodsumowanie2.Cells[0]; cellPodsumowanie2 = rowPodsumowanie2.Cells[0]; cellPodsumowanie2.AddParagraph("Zapłacono"); // rowKontoBankowe.Format.Alignment = ParagraphAlignment.Right; cellPodsumowanie2.Format.Font.Bold = true; cellPodsumowanie2 = rowPodsumowanie2.Cells[1]; cellPodsumowanie2.AddParagraph("0,00 PLN"); cellPodsumowanie2.Format.Font.Bold = false; Row rowPodsumowanie3 = tablePodsumowanie.AddRow(); Cell cellPodsumowanie3 = rowPodsumowanie3.Cells[0]; cellPodsumowanie3 = rowPodsumowanie3.Cells[0]; cellPodsumowanie3.AddParagraph("Pozostało do zaplaty"); // rowKontoBankowe.Format.Alignment = ParagraphAlignment.Right; cellPodsumowanie3.Format.Font.Bold = true; cellPodsumowanie3 = rowPodsumowanie3.Cells[1]; cellPodsumowanie3.AddParagraph("723,24 PLN"); cellPodsumowanie3.Format.Font.Bold = false; doc.LastSection.Add(tablePodsumowanie); Paragraph uwagi = sec.AddParagraph(); uwagi.Format.Font.Bold = false; uwagi.AddText("UWAGI: Zwolnienie podmiotowe z VAT wg. art. 113 ust. 1 Ustawy o VAT. W przypadku braku opłacenia faktury w terminie świadczenie usługi zostanie automatycznie wstrzymane. \n \n \n"); //def table bank i konto bankowe Table tablePodpisy = new Table(); tablePodpisy.Borders.Width = 0.0; Column columnPodpisy1 = tablePodpisy.AddColumn(Unit.FromCentimeter(8.25)); columnPodpisy1.Format.Alignment = ParagraphAlignment.Center; Column columnPodpisy2 = tablePodpisy.AddColumn(Unit.FromCentimeter(8.25)); columnPodpisy2.Format.Alignment = ParagraphAlignment.Center; Row rowPodpisy = tablePodpisy.AddRow(); Cell cellPodpisy = rowPodpisy.Cells[0]; cellPodpisy = rowPodpisy.Cells[0]; cellPodpisy.AddParagraph("Faktura bez podpisu odbiorcy faktury "); cellPodpisy = rowPodpisy.Cells[1]; cellPodpisy.AddParagraph("Osoba upoważniona do wystawienia faktury "); Row rowPodpisy2 = tablePodpisy.AddRow(); Cell cellPodpisy2 = rowPodpisy2.Cells[0]; cellPodpisy2 = rowPodpisy.Cells[0]; cellPodpisy2.AddParagraph(" "); cellPodpisy2 = rowPodpisy.Cells[1]; cellPodpisy2.AddParagraph("\n \n Tomasz Chajduga"); doc.LastSection.Add(tablePodpisy); // Create a renderer and prepare (=layout) the document MigraDoc.Rendering.DocumentRenderer docRenderer = new MigraDoc.Rendering.DocumentRenderer(doc); docRenderer.PrepareDocument(); gfx.MUH = PdfFontEncoding.Unicode; docRenderer.RenderPage(gfx, 1); const string filename = "HelloWorld4.pdf"; //When drawing is done, write the file document.Save(filename); // Save the document... //Process.Start(filename); // ...and start a viewer. }
public static void AddChargeTable(Document document, ChargeDataGrid selectedCharge, bool useDefaultFolder = false, string bankAccountCaption = null) { Document doc = document; Style style = doc.Styles["Normal"]; style.Font.Name = "Calibri"; style = doc.Styles.AddStyle("Table", "Normal"); style.Font.Name = "Calibri"; style.Font.Size = 12; var section = doc.LastSection; Table address = OwnerTableInfo(selectedCharge.Owner, selectedCharge.Building, selectedCharge.Apartment); address.Borders.Color = Colors.Transparent; document.LastSection.Add(address); Paragraph sep = new Paragraph(); sep.Format.SpaceAfter = "0.5cm"; document.LastSection.Add(sep); Table table = new Table(); table.Borders.Width = 0.5; table.AddColumn(Unit.FromCentimeter(5.5)); table.AddColumn(Unit.FromCentimeter(3.75)); var column = table.AddColumn(Unit.FromCentimeter(2.25)); column.Format.Alignment = ParagraphAlignment.Center; column = table.AddColumn(Unit.FromCentimeter(1.25)); column.Format.Alignment = ParagraphAlignment.Right; column = table.AddColumn(Unit.FromCentimeter(2.25)); column.Format.Alignment = ParagraphAlignment.Right; column = table.AddColumn(Unit.FromCentimeter(2)); column.Format.Alignment = ParagraphAlignment.Right; Row row = table.AddRow(); row.Shading.Color = new Color(135, 176, 77); Cell cell = row.Cells[0]; cell.AddParagraph("KATEGORIA"); cell.Format.Font.Bold = true; cell = row.Cells[1]; cell.AddParagraph("JEDNOSTKA"); cell.Format.Font.Bold = true; cell = row.Cells[3]; cell.AddParagraph("KOSZT JEDN."); cell.Format.Font.Bold = true; cell = row.Cells[4]; cell.AddParagraph("JEDN."); cell.Format.Font.Bold = true; cell = row.Cells[5]; cell.AddParagraph("SUMA"); cell.Format.Font.Bold = true; cell = row.Cells[2]; cell.AddParagraph("GRUPA"); cell.Format.Font.Bold = true; var length = selectedCharge.Components.Count; int groupsCount; decimal sum = 0; List <BuildingChargeGroupBankAccount> bankAccounts; using (var db = new DB.DomenaDBContext()) { bankAccounts = db.BuildingChargeGroupBankAccounts.Include(x => x.Building).Include(x => x.GroupName).Where(x => !x.IsDeleted && x.Building.BuildingId == selectedCharge.Building.BuildingId).ToList(); foreach (var c in selectedCharge.Components) { row = table.AddRow(); cell = row.Cells[0]; cell.AddParagraph(db.CostCategories.FirstOrDefault(x => x.BuildingChargeBasisCategoryId.Equals(c.CostCategoryId)).CategoryName); cell = row.Cells[1]; cell.AddParagraph(EnumCostDistribution.CostDistributionToString((CostDistribution)c.CostDistribution)); cell = row.Cells[3]; cell.AddParagraph(c.CostPerUnit + " zł"); cell = row.Cells[4]; string units = ""; switch ((CostDistribution)c.CostDistribution) { default: break; case CostDistribution.PerApartmentTotalArea: units = (selectedCharge.Apartment.AdditionalArea + selectedCharge.Apartment.ApartmentArea).ToString(); break; case CostDistribution.PerAdditionalArea: units = (selectedCharge.Apartment.AdditionalArea).ToString(); break; case CostDistribution.PerApartment: units = "1"; break; case CostDistribution.PerApartmentArea: units = (selectedCharge.Apartment.ApartmentArea).ToString(); break; case CostDistribution.PerLocators: units = (selectedCharge.Apartment.Locators).ToString(); break; } cell.AddParagraph(units); cell = row.Cells[5]; cell.AddParagraph(c.Sum + " zł"); cell = row.Cells[2]; cell.AddParagraph(c.GroupName.GroupName); sum += c.Sum; } var groups = selectedCharge.Components.GroupBy(x => x.GroupName.GroupName); row = table.AddRow(); row.HeightRule = RowHeightRule.Exactly; row.Height = 1; row.Shading.Color = Colors.Black; groupsCount = groups.Count(); foreach (var g in groups) { row = table.AddRow(); cell = row.Cells[0]; cell.AddParagraph("Razem - " + g.Key); cell = row.Cells[5]; cell.AddParagraph(g.Select(c => c.Sum).Sum() + " zł"); } } row = table.AddRow(); cell = row.Cells[0]; cell.AddParagraph("Razem"); cell.Format.Font.Bold = true; cell = row.Cells[5]; cell.AddParagraph(sum + " zł"); cell.Format.Font.Bold = true; table.SetEdge(0, 0, 6, length + 3 + groupsCount, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 1, Colors.Black); document.LastSection.Add(table); if (bankAccounts != null && bankAccounts.Count > 0 && selectedCharge.Components != null && selectedCharge.Components.Count() > 0 && selectedCharge.Components.GroupBy(x => x.GroupName).Count() > 0 ) { Paragraph paragraph = document.LastSection.AddParagraph(); if (bankAccountCaption == null) { using (var db = new DB.DomenaDBContext()) { bankAccountCaption = db.Settings.FirstOrDefault(s => s.Key == "bank-account")?.Value; } } //paragraph.AddText("Wpłat należy dokonywać regularnie do dnia 10 każdego miesiąca na rachunek bankowy: "); paragraph.AddText(bankAccountCaption); foreach (var g in selectedCharge.Components.GroupBy(x => x.GroupName)) { var ba = bankAccounts.FirstOrDefault(x => x.GroupName.BuildingChargeGroupNameId == g.Key.BuildingChargeGroupNameId); if (ba != null) { paragraph = document.LastSection.AddParagraph(); paragraph.AddText(g.Key.GroupName + ": " + ba.BankAccount); } } } MigraDoc.Rendering.DocumentRenderer docRenderer = new MigraDoc.Rendering.DocumentRenderer(doc); docRenderer.PrepareDocument(); PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always); renderer.Document = doc; renderer.RenderDocument(); // Save the document... try { if (!useDefaultFolder) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "PDF file|*.pdf"; sfd.Title = "Zapisz raport jako..."; sfd.ShowDialog(); if (sfd.FileName != "") { renderer.PdfDocument.Save(sfd.FileName); System.Diagnostics.Process.Start(sfd.FileName); } } else { System.IO.FileInfo file = new System.IO.FileInfo("Reports\\"); file.Directory.Create(); string filename = selectedCharge.ChargeDate.ToString("MMMM_yyyy") + "_" + selectedCharge.Building.Name + "_" + selectedCharge.Apartment.ApartmentNumber + ".pdf"; renderer.PdfDocument.Save(Path.Combine(file.FullName, filename.Replace(' ', '_'))); System.Diagnostics.Process.Start(Path.Combine(file.FullName, filename.Replace(' ', '_'))); } } catch (Exception e) { MessageBox.Show("Błąd zapisu pliku - plik może być aktualnie używany. Spróbuj ponownie."); Log.Logger.Error(e, "Error in report file save"); } }
internal FormattedTextArea(DocumentRenderer documentRenderer, TextArea textArea, FieldInfos fieldInfos) { TextArea = textArea; _fieldInfos = fieldInfos; _documentRenderer = documentRenderer; }
internal FormattedHeaderFooter(HeaderFooter headerFooter, DocumentRenderer documentRenderer, FieldInfos fieldInfos) { this.headerFooter = headerFooter; this.fieldInfos = fieldInfos; this.documentRenderer = documentRenderer; }
/// <summary> /// Renders a single paragraph. /// </summary> static void SamplePage1(PdfDocument document) { PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); // HACK² gfx.MUH = PdfFontEncoding.Unicode; gfx.MFEH = PdfFontEmbedding.Default; XFont font = new XFont("Verdana", 13, XFontStyle.Bold); gfx.DrawString("The following paragraph was rendered using MigraDoc:", font, XBrushes.Black, new XRect(100, 100, page.Width - 200, 300), XStringFormats.Center); // You always need a MigraDoc document for rendering. Document doc = new Document(); Section sec = doc.AddSection(); // Add a single paragraph with some text and format information. Paragraph para = sec.AddParagraph(); para.Format.Alignment = ParagraphAlignment.Justify; para.Format.Font.Name = "Times New Roman"; para.Format.Font.Size = 12; para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray; para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray; para.AddText("Duisism odigna acipsum delesenisl "); para.AddFormattedText("ullum in velenit", TextFormat.Bold); para.AddText(" ipit iurero dolum zzriliquisis nit wis dolore vel et nonsequipit, velendigna "+ "auguercilit lor se dipisl duismod tatem zzrit at laore magna feummod oloborting ea con vel "+ "essit augiati onsequat luptat nos diatum vel ullum illummy nonsent nit ipis et nonsequis "+ "niation utpat. Odolobor augait et non etueril landre min ut ulla feugiam commodo lortie ex "+ "essent augait el ing eumsan hendre feugait prat augiatem amconul laoreet. ≤≥≈≠"); para.Format.Borders.Distance = "5pt"; para.Format.Borders.Color = Colors.Gold; // Create a renderer and prepare (=layout) the document MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc); docRenderer.PrepareDocument(); // Render the paragraph. You can render tables or shapes the same way. docRenderer.RenderObject(gfx, XUnit.FromCentimeter(5), XUnit.FromCentimeter(10), "12cm", para); }
internal FormattedHeaderFooter(HeaderFooter headerFooter, DocumentRenderer documentRenderer, FieldInfos fieldInfos) { this.headerFooter = headerFooter; this.fieldInfos = fieldInfos; this.documentRenderer = documentRenderer; }
/// <summary> /// Renders a whole MigraDoc document scaled to a single PDF page. /// </summary> static void SamplePage2(PdfDocument document) { PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); // HACK² gfx.MUH = PdfFontEncoding.Unicode; gfx.MFEH = PdfFontEmbedding.Default; // Create document from HalloMigraDoc sample Document doc = HelloMigraDoc.Documents.CreateDocument(); // Create a renderer and prepare (=layout) the document MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc); docRenderer.PrepareDocument(); // For clarity we use point as unit of measure in this sample. // A4 is the standard letter size in Germany (21cm x 29.7cm). XRect A4Rect = new XRect(0, 0, A4Width, A4Height); int pageCount = docRenderer.FormattedDocument.PageCount; for (int idx = 0; idx < pageCount; idx++) { XRect rect = GetRect(idx); // Use BeginContainer / EndContainer for simplicity only. You can naturaly use you own transformations. XGraphicsContainer container = gfx.BeginContainer(rect, A4Rect, XGraphicsUnit.Point); // Draw page border for better visual representation gfx.DrawRectangle(XPens.LightGray, A4Rect); // Render the page. Note that page numbers start with 1. docRenderer.RenderPage(gfx, idx + 1); // Note: The outline and the hyperlinks (table of content) does not work in the produced PDF document. // Pop the previous graphical state gfx.EndContainer(container); } }