using System; using System.Collections.Generic; using System.Linq; using System.Web; using Stimulsoft.Report; using Stimulsoft.Report.Chart; using Stimulsoft.Report.Dictionary; using Stimulsoft.Report.Components; using Stimulsoft.Report.Components.ShapeTypes; using Stimulsoft.Base.Drawing; using System.Drawing; using System.IO; using System.Text; /// /// Summary description for CreateReport /// public class CreateReport { private int RichTextCounter; private int TextCounter; public CreateReport(String mrt_fileName, String pdf_fileName) { if (File.Exists(pdf_fileName)) File.Delete(pdf_fileName); Stimulsoft.Report.Export.StiPdfExportSettings pdf = SetupStimulsoft(0.4F, 200F); StiReport stiReport1 = new StiReport(); stiReport1.Load(mrt_fileName); stiReport1.Pages.Add(CreateNewPage("Page2", stiReport1)); stiReport1.Compile(); stiReport1.Render(); stiReport1.ExportDocument(StiExportFormat.Pdf, pdf_fileName, pdf); } private static Stimulsoft.Report.Export.StiPdfExportSettings SetupStimulsoft(float imageQuality, float imageResolution) { StiOptions.Engine.HideRenderingProgress = true; StiOptions.Engine.RenderChartAsBitmap = true; StiOptions.Engine.HideMessages = false; StiOptions.Print.AllowUsePaperSizesFromPrinterSettings = false; //Ställ in kvalitet Stimulsoft.Report.Export.StiPdfExportSettings pdf = new Stimulsoft.Report.Export.StiPdfExportSettings(); pdf.Compressed = true; pdf.ImageCompressionMethod = Stimulsoft.Report.Export.StiPdfImageCompressionMethod.Jpeg; pdf.DitheringType = Stimulsoft.Report.Export.StiMonochromeDitheringType.Ordered; //pdf.EmbeddedFonts = false; pdf.ExportRtfTextAsImage = true; pdf.GetCertificateFromCryptoUI = false; pdf.ImageFormat = Stimulsoft.Report.Export.StiImageFormat.Color; pdf.ImageQuality = imageQuality; pdf.ImageResolution = imageResolution; return pdf; } public StiPage CreateNewPage(String name, StiReport report) { StiPage p = new StiPage(); PageBaseProperties(name, p, report); StiRichText rtb = CreateRichTextBox(new RectangleD(0.38, 0.67, 8.8, 0.58), "RichTextBoxExample", p); StiText tb = CreateTextBox(new RectangleD(0.66, 0.25, 4.06, 0.58), "TextBoxExample", p); StiChart chart = CreateBarChart(new Stimulsoft.Base.Drawing.RectangleD(2.4, 7.4, 13.4, 7.4), p); p.Components.AddRange(new Stimulsoft.Report.Components.StiComponent[] { rtb, tb, chart }); return p; } private void PageBaseProperties(String name, StiPage p, StiReport report) { p.Name = name; p.Guid = Guid.NewGuid().ToString(); p.PageHeight = 29.7; p.PageWidth = 21; p.PaperSize = System.Drawing.Printing.PaperKind.A4; p.Border = new Stimulsoft.Base.Drawing.StiBorder(Stimulsoft.Base.Drawing.StiBorderSides.None, System.Drawing.Color.Black, 2, Stimulsoft.Base.Drawing.StiPenStyle.Solid, false, 4, new Stimulsoft.Base.Drawing.StiSolidBrush(System.Drawing.Color.Black), false); p.Brush = new Stimulsoft.Base.Drawing.StiSolidBrush(System.Drawing.Color.Transparent); p.Report = report; } #region Hjälpfunktioner protected StiRichText CreateRichTextBox(RectangleD location, String text, StiPage page) { StiRichText rtb = new StiRichText(); rtb.BackColor = System.Drawing.Color.Transparent; rtb.ClientRectangle = location; rtb.DataColumn = ""; rtb.Name = "RichText" + RichTextCounter; RichTextCounter++; //rtb.Text = text; rtb.GetValue += new Stimulsoft.Report.Events.StiGetValueEventHandler(rtb__GetValue); rtb.Border = new Stimulsoft.Base.Drawing.StiBorder(Stimulsoft.Base.Drawing.StiBorderSides.None, System.Drawing.Color.Black, 1, Stimulsoft.Base.Drawing.StiPenStyle.Solid, false, 4, new Stimulsoft.Base.Drawing.StiSolidBrush(System.Drawing.Color.Black), false); rtb.Guid = null; rtb.Interaction = null; rtb.Margins = new Stimulsoft.Report.Components.StiMargins(0, 0, 0, 0); rtb.Page = page; rtb.Parent = page; return rtb; } public void rtb__GetValue(object sender, Stimulsoft.Report.Events.StiGetValueEventArgs e) { e.Value = StiRichText.PackRtf("Some rich text"); } protected StiText CreateTextBox(RectangleD location, String text, StiPage page) { StiText rtb = new StiText(); rtb.ClientRectangle = location; rtb.Guid = null; rtb.Name = "Text" + TextCounter; TextCounter++; //rtb.Text = text; rtb.GetValue += new Stimulsoft.Report.Events.StiGetValueEventHandler(tb__GetValue); rtb.Type = Stimulsoft.Report.Components.StiSystemTextType.Expression; rtb.Border = new Stimulsoft.Base.Drawing.StiBorder(Stimulsoft.Base.Drawing.StiBorderSides.All, System.Drawing.Color.Black, 1, Stimulsoft.Base.Drawing.StiPenStyle.Solid, false, 4, new Stimulsoft.Base.Drawing.StiSolidBrush(System.Drawing.Color.Black), false); rtb.Brush = new Stimulsoft.Base.Drawing.StiSolidBrush(System.Drawing.Color.Yellow); rtb.Font = new System.Drawing.Font("Arial", 10F); rtb.Indicator = null; rtb.Interaction = null; rtb.Margins = new Stimulsoft.Report.Components.StiMargins(0, 0, 0, 0); rtb.TextBrush = new Stimulsoft.Base.Drawing.StiSolidBrush(System.Drawing.Color.Black); rtb.TextOptions = new Stimulsoft.Base.Drawing.StiTextOptions(false, false, false, 0F, System.Drawing.Text.HotkeyPrefix.None, System.Drawing.StringTrimming.None); rtb.Page = page; rtb.Parent = page; return rtb; } public void tb__GetValue(object sender, Stimulsoft.Report.Events.StiGetValueEventArgs e) { e.Value = "Some simple text"; } private StiChart CreateBarChart(RectangleD location, StiPage page) { StiChart chart = new Stimulsoft.Report.Chart.StiChart(); chart.ClientRectangle = location; chart.CustomStyleName = ""; chart.Name = "Chart1"; chart.Sort = new System.String[0]; chart.Border = new Stimulsoft.Base.Drawing.StiBorder(Stimulsoft.Base.Drawing.StiBorderSides.None, System.Drawing.Color.Black, 1, Stimulsoft.Base.Drawing.StiPenStyle.Solid, false, 4, new Stimulsoft.Base.Drawing.StiSolidBrush(System.Drawing.Color.Black), false); chart.Brush = new Stimulsoft.Base.Drawing.StiSolidBrush(System.Drawing.Color.FromArgb(255, 255, 255, 255)); chart.Guid = null; chart.Interaction = null; chart.MasterComponent = null; chart.Style = new Stimulsoft.Report.Chart.StiStyle01(); chart.Title = new Stimulsoft.Report.Chart.StiChartTitle(new System.Drawing.Font("Tahoma", 12F, System.Drawing.FontStyle.Bold), "", new Stimulsoft.Base.Drawing.StiSolidBrush(System.Drawing.Color.FromArgb(255, 95, 72, 29)), true, System.Drawing.StringAlignment.Center, Stimulsoft.Report.Chart.StiChartTitleDock.Top, 2, false, true); chart.Area = CreateClusteredColumnArea(chart); chart.Legend = CreateLegend(chart); chart.Page = page; chart.Parent = page; chart.SeriesLabels = CreateLabels(chart); return chart; } private StiClusteredColumnArea CreateClusteredColumnArea(StiChart chart) { StiClusteredColumnArea chart_Area = new Stimulsoft.Report.Chart.StiClusteredColumnArea(); chart_Area.BorderColor = System.Drawing.Color.FromArgb(255, 95, 72, 29); chart_Area.Brush = new Stimulsoft.Base.Drawing.StiGradientBrush(System.Drawing.Color.FromArgb(255, 255, 255, 255), System.Drawing.Color.FromArgb(255, 255, 255, 219), 90); chart_Area.GridLinesHor = new Stimulsoft.Report.Chart.StiGridLinesHor(System.Drawing.Color.FromArgb(100, 95, 72, 29), Stimulsoft.Base.Drawing.StiPenStyle.Dot, true, System.Drawing.Color.FromArgb(100, 95, 72, 29), Stimulsoft.Base.Drawing.StiPenStyle.Dot, false, 0, true); chart_Area.GridLinesHorRight = new Stimulsoft.Report.Chart.StiGridLinesHor(System.Drawing.Color.Silver, Stimulsoft.Base.Drawing.StiPenStyle.Dot, false, System.Drawing.Color.Gainsboro, Stimulsoft.Base.Drawing.StiPenStyle.Dot, false, 0, true); chart_Area.GridLinesVert = new Stimulsoft.Report.Chart.StiGridLinesVert(System.Drawing.Color.FromArgb(100, 95, 72, 29), Stimulsoft.Base.Drawing.StiPenStyle.Dot, true, System.Drawing.Color.FromArgb(100, 95, 72, 29), Stimulsoft.Base.Drawing.StiPenStyle.Dot, false, 0, true); chart_Area.InterlacingHor = new Stimulsoft.Report.Chart.StiInterlacingHor(new Stimulsoft.Base.Drawing.StiSolidBrush(System.Drawing.Color.FromArgb(10, 145, 122, 79)), true, true); chart_Area.InterlacingVert = new Stimulsoft.Report.Chart.StiInterlacingVert(new Stimulsoft.Base.Drawing.StiSolidBrush(System.Drawing.Color.FromArgb(10, 145, 122, 79)), true, true); chart_Area.XAxis = new Stimulsoft.Report.Chart.StiXBottomAxis(new Stimulsoft.Report.Chart.StiAxisLabels("", "", "", 0F, new System.Drawing.Font("Tahoma", 8F), true, Stimulsoft.Report.Chart.StiLabelsPlacement.OneLine, System.Drawing.Color.FromArgb(255, 95, 72, 29), 0F, Stimulsoft.Report.Chart.StiMarkerAlignment.Right, 0F, true, false), new Stimulsoft.Report.Chart.StiAxisRange(true, 0, 0), new Stimulsoft.Report.Chart.StiAxisTitle(new System.Drawing.Font("Tahoma", 12F, System.Drawing.FontStyle.Bold), "", System.Drawing.Color.FromArgb(255, 95, 72, 29), true, System.Drawing.StringAlignment.Center, Stimulsoft.Report.Chart.StiDirection.LeftToRight, true), new Stimulsoft.Report.Chart.StiAxisTicks(true, 5F, false, 2F, 4, 0, 5F), new Stimulsoft.Report.Chart.StiAxisInteraction(false, true), Stimulsoft.Report.Chart.StiArrowStyle.None, Stimulsoft.Base.Drawing.StiPenStyle.Solid, System.Drawing.Color.FromArgb(255, 95, 72, 29), 1F, true, true, Stimulsoft.Report.Chart.StiShowXAxis.Both, false, true, new Stimulsoft.Report.Chart.StiAxisDateTimeStep(Stimulsoft.Report.Chart.StiTimeDateStep.None, 1), false); chart_Area.XTopAxis = new Stimulsoft.Report.Chart.StiXTopAxis(new Stimulsoft.Report.Chart.StiAxisLabels("", "", "", 0F, new System.Drawing.Font("Tahoma", 8F), true, Stimulsoft.Report.Chart.StiLabelsPlacement.OneLine, System.Drawing.Color.FromArgb(255, 95, 72, 29), 0F, Stimulsoft.Report.Chart.StiMarkerAlignment.Right, 0F, true, false), new Stimulsoft.Report.Chart.StiAxisRange(true, 0, 0), new Stimulsoft.Report.Chart.StiAxisTitle(new System.Drawing.Font("Tahoma", 12F, System.Drawing.FontStyle.Bold), "", System.Drawing.Color.FromArgb(255, 95, 72, 29), true, System.Drawing.StringAlignment.Center, Stimulsoft.Report.Chart.StiDirection.LeftToRight, true), new Stimulsoft.Report.Chart.StiAxisTicks(true, 5F, false, 2F, 4, 0, 5F), new Stimulsoft.Report.Chart.StiAxisInteraction(false, true), Stimulsoft.Report.Chart.StiArrowStyle.None, Stimulsoft.Base.Drawing.StiPenStyle.Solid, System.Drawing.Color.FromArgb(255, 95, 72, 29), 1F, false, true, false, true, false); chart_Area.YAxis = new Stimulsoft.Report.Chart.StiYLeftAxis(new Stimulsoft.Report.Chart.StiAxisLabels("", "", "", 0F, new System.Drawing.Font("Tahoma", 8F), true, Stimulsoft.Report.Chart.StiLabelsPlacement.OneLine, System.Drawing.Color.FromArgb(255, 95, 72, 29), 0F, Stimulsoft.Report.Chart.StiMarkerAlignment.Right, 0F, true, false), new Stimulsoft.Report.Chart.StiAxisRange(true, 0, 0), new Stimulsoft.Report.Chart.StiAxisTitle(new System.Drawing.Font("Tahoma", 12F, System.Drawing.FontStyle.Bold), "", System.Drawing.Color.FromArgb(255, 95, 72, 29), true, System.Drawing.StringAlignment.Center, Stimulsoft.Report.Chart.StiDirection.BottomToTop, true), new Stimulsoft.Report.Chart.StiAxisTicks(true, 5F, false, 2F, 4, 0, 5F), new Stimulsoft.Report.Chart.StiAxisInteraction(false, true), Stimulsoft.Report.Chart.StiArrowStyle.None, Stimulsoft.Base.Drawing.StiPenStyle.Solid, System.Drawing.Color.FromArgb(255, 95, 72, 29), 1F, true, true, Stimulsoft.Report.Chart.StiShowYAxis.Both, true, false); chart_Area.YRightAxis = new Stimulsoft.Report.Chart.StiYRightAxis(new Stimulsoft.Report.Chart.StiAxisLabels("", "", "", 0F, new System.Drawing.Font("Tahoma", 8F), true, Stimulsoft.Report.Chart.StiLabelsPlacement.OneLine, System.Drawing.Color.FromArgb(255, 95, 72, 29), 0F, Stimulsoft.Report.Chart.StiMarkerAlignment.Left, 0F, true, false), new Stimulsoft.Report.Chart.StiAxisRange(true, 0, 0), new Stimulsoft.Report.Chart.StiAxisTitle(new System.Drawing.Font("Tahoma", 12F, System.Drawing.FontStyle.Bold), "", System.Drawing.Color.FromArgb(255, 95, 72, 29), true, System.Drawing.StringAlignment.Center, Stimulsoft.Report.Chart.StiDirection.TopToBottom, true), new Stimulsoft.Report.Chart.StiAxisTicks(true, 5F, false, 2F, 4, 0, 5F), new Stimulsoft.Report.Chart.StiAxisInteraction(false, true), Stimulsoft.Report.Chart.StiArrowStyle.None, Stimulsoft.Base.Drawing.StiPenStyle.Solid, System.Drawing.Color.FromArgb(255, 95, 72, 29), 1F, false, true, true, false); chart_Area.Chart = chart; return chart_Area; } private StiLegend CreateLegend(StiChart chart) { StiLegend chart_Legend = new Stimulsoft.Report.Chart.StiLegend(); chart_Legend.BorderColor = System.Drawing.Color.FromArgb(255, 95, 72, 29); chart_Legend.LabelsColor = System.Drawing.Color.FromArgb(255, 95, 72, 29); chart_Legend.MarkerSize = new System.Drawing.Size(10, 10); chart_Legend.TitleColor = System.Drawing.Color.FromArgb(255, 95, 72, 29); chart_Legend.Brush = new Stimulsoft.Base.Drawing.StiGradientBrush(System.Drawing.Color.FromArgb(255, 255, 255, 255), System.Drawing.Color.FromArgb(255, 255, 242, 199), 90); chart_Legend.Font = new System.Drawing.Font("Arial", 8F); chart_Legend.TitleFont = new System.Drawing.Font("Arial", 14F, System.Drawing.FontStyle.Bold); chart_Legend.Chart = chart; return chart_Legend; } private StiNoneLabels CreateLabels(StiChart chart) { StiNoneLabels chart_SeriesLabels = new Stimulsoft.Report.Chart.StiNoneLabels(); chart_SeriesLabels.MarkerSize = new System.Drawing.Size(8, 6); chart_SeriesLabels.ValueTypeSeparator = "-"; chart_SeriesLabels.Chart = chart; return chart_SeriesLabels; } #endregion }