ReportUtils.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. //using Ghostscript.NET;
  2. //using Ghostscript.NET.Processor;
  3. using System.Data;
  4. using System.Drawing.Printing;
  5. using System.IO;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Forms.Integration;
  9. using FastReport;
  10. using FastReport.Data;
  11. using FastReport.Design;
  12. using FastReport.Design.StandardDesigner;
  13. using FastReport.Export.Pdf;
  14. using FastReport.Utils;
  15. using InABox.Clients;
  16. using InABox.Core;
  17. using InABox.Reports.Common;
  18. using InABox.Scripting;
  19. using InABox.WPF;
  20. using MessageBox = System.Windows.Forms.MessageBox;
  21. using SaveFileDialog = Microsoft.Win32.SaveFileDialog;
  22. using ScriptEditor = InABox.DynamicGrid.ScriptEditor;
  23. using XmlDocument = System.Xml.XmlDocument;
  24. namespace InABox.Reports
  25. {
  26. public enum ReportExportType
  27. {
  28. PDF,
  29. HTML,
  30. RTF,
  31. Excel,
  32. Text,
  33. Image
  34. }
  35. public class ReportExportDefinition
  36. {
  37. public ReportExportDefinition(string caption, Bitmap image, ReportExportType type, Action<DataModel, byte[]> action)
  38. {
  39. Caption = caption;
  40. Image = image;
  41. Type = type;
  42. Action = action;
  43. }
  44. public string Caption { get; }
  45. public Bitmap Image { get; }
  46. public ReportExportType Type { get; }
  47. public Action<DataModel, byte[]> Action { get; }
  48. }
  49. [LibraryInitializer]
  50. public static class ReportUtils
  51. {
  52. public static List<ReportExportDefinition> ExportDefinitions { get; } = new();
  53. public static void RegisterClasses()
  54. {
  55. CoreUtils.RegisterClasses(typeof(ReportTemplate).Assembly, typeof(ReportUtils).Assembly);
  56. foreach (string printer in PrinterSettings.InstalledPrinters)
  57. ReportPrinters.Register(printer);
  58. RegisteredObjects.Add(typeof(MultiImageObject), "ReportPage", Properties.Resources.multi_image, "Multi-Image");
  59. RegisteredObjects.Add(typeof(MultiSignatureObject), "ReportPage", Properties.Resources.signature, "Multi-Signature");
  60. }
  61. public static void PreviewReport(ReportTemplate template, DataModel data, bool printandclose = false, bool allowdesigner = false)
  62. {
  63. var isrdl = template != null && template.IsRDL;
  64. if (isrdl)
  65. {
  66. MessageBox.Show("RDL Reports are no longer supported!");
  67. }
  68. else
  69. {
  70. PreviewWindow window = new(template, data)
  71. {
  72. AllowDesign = allowdesigner,
  73. Title = string.Format("Report Preview - {0}", template.Name),
  74. Height = 800,
  75. Width = 1200,
  76. WindowState = WindowState.Maximized,
  77. };
  78. window.Show();
  79. }
  80. }
  81. public static Report SetupReport(ReportTemplate template, DataModel data, bool repopulate)
  82. {
  83. var templaterdl = template != null ? string.IsNullOrWhiteSpace(template.RDL) ? "" : template.RDL : "";
  84. var tables = new List<string>();
  85. if (!string.IsNullOrWhiteSpace(templaterdl))
  86. {
  87. var xml = new XmlDocument();
  88. xml.LoadString(templaterdl);
  89. var datasources = xml.GetElementsByTagName("TableDataSource");
  90. for (var i = 0; i < datasources.Count; i++)
  91. {
  92. var datasource = datasources[i];
  93. tables.Add(datasource.Attributes.GetNamedItem("Name").Value);
  94. }
  95. }
  96. else
  97. {
  98. foreach(var table in data.DefaultTables)
  99. {
  100. tables.Add(table.TableName);
  101. }
  102. }
  103. var script = new ScriptDocument(template.Script);
  104. var ScriptOK = false;
  105. if (!string.IsNullOrWhiteSpace(template.Script))
  106. if (script.Compile())
  107. {
  108. script.SetValue("Model", data);
  109. ScriptOK = script.Execute("Report", "Init");
  110. }
  111. if (repopulate)
  112. data.LoadModel(tables);
  113. if (ScriptOK)
  114. {
  115. script.SetValue("RequireTables", tables);
  116. script.Execute("Report", "Populate");
  117. }
  118. var report = new Report();
  119. report.LoadFromString(templaterdl);
  120. report.FileName = template.Name;
  121. var ds = data.AsDataSet();
  122. report.RegisterData(ds);
  123. foreach (var table in data.Tables)
  124. {
  125. var dataSource = report.GetDataSource(table.TableName);
  126. if(dataSource != null)
  127. {
  128. foreach (var column in dataSource.Columns)
  129. {
  130. if (column is FastReport.Data.Column col && col.DataType != null && col.DataType.IsAssignableTo(typeof(IEnumerable<byte[]>)))
  131. {
  132. col.BindableControl = ColumnBindableControl.Custom;
  133. col.CustomBindableControl = "MultiImageObject";
  134. }
  135. }
  136. }
  137. }
  138. if (string.IsNullOrWhiteSpace(templaterdl))
  139. {
  140. foreach (var table in data.DefaultTables)
  141. {
  142. var dataSource = report.GetDataSource(table.TableName);
  143. dataSource.Enabled = true;
  144. }
  145. foreach (Relation relation in report.Dictionary.Relations)
  146. if (data.DefaultTables.Any(x => x.TableName.Equals(relation.ParentDataSource.Alias)) &&
  147. data.DefaultTables.Any(x => x.TableName.Equals(relation.ChildDataSource.Alias)))
  148. relation.Enabled = true;
  149. }
  150. return report;
  151. }
  152. public static void DesignReport(ReportTemplate template, DataModel data, bool populate = false)
  153. {
  154. var isrdl = template != null && template.IsRDL;
  155. var templaterdl = template != null ? string.IsNullOrWhiteSpace(template.RDL) ? "" : template.RDL : "";
  156. if (isrdl)
  157. MessageBox.Show("RDL Reports are not supported!");
  158. else
  159. {
  160. PreviewWindow window = new(template, data)
  161. {
  162. AllowDesign = true,
  163. Title = string.Format("Report Designer - {0}", template.Name),
  164. Height = 800,
  165. Width = 1200,
  166. WindowState = WindowState.Maximized,
  167. IsPreview = false,
  168. ShouldPopulate = populate
  169. };
  170. window.Show();
  171. }
  172. }
  173. public static byte[] ReportToPDF(ReportTemplate template, DataModel data, bool repopulate = true)
  174. {
  175. byte[] result = null;
  176. if (template.IsRDL)
  177. MessageBox.Show("RDL Reports are not supported!");
  178. // using (var pdf = new MemoryStream())
  179. // {
  180. // using (var ms = ReportUtils.SetupReportToStream(template.RDL, data.AsDictionary))
  181. // {
  182. // using (ReportWriter reportWriter = new ReportWriter(ms))
  183. // {
  184. // reportWriter.ReportProcessingMode = Syncfusion.ReportWriter.ProcessingMode.Local;
  185. // reportWriter.Save(pdf, WriterFormat.PDF);
  186. //
  187. // //String filename = Path.Combine(GetPath(), "report.pdf");
  188. // //reportWriter.Save(filename, WriterFormat.PDF);
  189. // //PdfLoadedDocument rpt = new PdfLoadedDocument(filename);
  190. //
  191. // PdfLoadedDocument rpt = new PdfLoadedDocument(pdf);
  192. // PdfDocument doc = new PdfDocument(PdfConformanceLevel.Pdf_A1B);
  193. // PdfDocument.Merge(doc, rpt);
  194. // var msFinal = new MemoryStream();
  195. // doc.Save(msFinal);
  196. // result = msFinal.GetBuffer();
  197. // }
  198. // }
  199. // //result = GhostScriptIt(pdf.GetBuffer());
  200. // //result = pdf.GetBuffer();
  201. // }
  202. else
  203. using (var report = SetupReport(template, data, repopulate))
  204. {
  205. report.Prepare();
  206. var ms = new MemoryStream();
  207. report.Export(new PDFExport(), ms);
  208. result = ms.GetBuffer();
  209. }
  210. return result;
  211. }
  212. public static IEnumerable<ReportTemplate> LoadReports(string sectionName, DataModel model)
  213. {
  214. return new Client<ReportTemplate>().Query(
  215. new Filter<ReportTemplate>(x => x.DataModel).IsEqualTo(model.Name)
  216. .And(x => x.Section).IsEqualTo(sectionName),
  217. null,
  218. new SortOrder<ReportTemplate>(x => x.Name)).Rows.Select(x => x.ToObject<ReportTemplate>());
  219. }
  220. private static void PopulateMenu(ItemsControl menu, string sectionName, DataModel model, bool allowdesign, bool populate = false)
  221. {
  222. var reports = new Client<ReportTemplate>().Query(
  223. new Filter<ReportTemplate>(x => x.DataModel).IsEqualTo(model.Name)
  224. .And(x => x.Section).IsEqualTo(sectionName),
  225. null,
  226. new SortOrder<ReportTemplate>(x => x.Name)
  227. );
  228. foreach (var row in reports.Rows)
  229. {
  230. var print = new MenuItem();
  231. print.Header = row.Get<ReportTemplate, string>(x => x.Name);
  232. print.Tag = row.ToObject<ReportTemplate>();
  233. print.Click += (sender, args) =>
  234. {
  235. var template = (sender as MenuItem)!.Tag as ReportTemplate;
  236. if (template != null)
  237. PreviewReport(template, model, false, allowdesign);
  238. };
  239. menu.Items.Add(print);
  240. }
  241. if (allowdesign)
  242. {
  243. if (reports.Rows.Any())
  244. menu.Items.Add(new Separator());
  245. var manage = new MenuItem();
  246. manage.Header = "Manage Reports";
  247. manage.Click += (sender, args) =>
  248. {
  249. var manager = new ReportManager()
  250. {
  251. DataModel = model,
  252. Section = sectionName,
  253. Populate = populate
  254. };
  255. manager.ShowDialog();
  256. };
  257. menu.Items.Add(manage);
  258. }
  259. }
  260. public static void PopulateMenu(MenuItem menu, string sectionName, DataModel model, bool allowdesign, bool populate = false) =>
  261. PopulateMenu(menu as ItemsControl, sectionName, model, allowdesign, populate);
  262. public static void PopulateMenu(ContextMenu menu, string sectionName, DataModel model, bool allowdesign, bool populate = false) =>
  263. PopulateMenu(menu as ItemsControl, sectionName, model, allowdesign, populate);
  264. public static void PrintMenu(FrameworkElement? element, string sectionName, DataModel model, bool allowdesign, bool populate = false)
  265. {
  266. var menu = new ContextMenu();
  267. PopulateMenu(menu, sectionName, model, allowdesign, populate);
  268. if (menu.Items.Count > 0)
  269. {
  270. menu.PlacementTarget = element;
  271. menu.IsOpen = true;
  272. }
  273. }
  274. public static void PrintMenu<TType>(FrameworkElement? element, string sectionName, DataModel<TType> model, bool allowdesign, bool populate = false)
  275. where TType : Entity, IRemotable, IPersistent, new()
  276. {
  277. PrintMenu(element, sectionName, model, allowdesign, populate);
  278. }
  279. #region Old RDL Stuff (Deprecated)
  280. // private static ReportDefinition SetupReportDefinition(String rdl, Dictionary<System.Type, CoreTable> dataenvironment = null)
  281. // {
  282. // ReportDefinition report = null;
  283. // if (String.IsNullOrWhiteSpace(rdl))
  284. // report = CreateReport();
  285. // else
  286. // report = DeserialiseReport(rdl);
  287. //
  288. // if (dataenvironment != null)
  289. // SetupReportData(report, dataenvironment);
  290. // return report;
  291. // }
  292. // public static String SetupReport(String rdl, Dictionary<System.Type, CoreTable> dataenvironment = null)
  293. // {
  294. // var defn = SetupReportDefinition(rdl, dataenvironment);
  295. // return SerialiseReport(defn);
  296. // }
  297. //
  298. // public static MemoryStream SetupReportToStream(String rdl, Dictionary<System.Type, CoreTable> dataenvironment = null)
  299. // {
  300. // var defn = SetupReportDefinition(rdl, dataenvironment);
  301. // return SerialiseReportToStream(defn);
  302. // }
  303. // public static String CleanupReport(String rdl)
  304. // {
  305. // ReportDefinition report = null;
  306. // if (String.IsNullOrWhiteSpace(rdl))
  307. // report = CreateReport();
  308. // else
  309. // report = DeserialiseReport(rdl);
  310. //
  311. // CleanupReportData(report);
  312. //
  313. // return SerialiseReport(report);
  314. //
  315. // }
  316. // private static ReportDefinition CreateReport()
  317. // {
  318. // ReportDefinition rd = new ReportDefinition();
  319. // rd.DataSources = new DataSources();
  320. // rd.DataSets = new DataSets();
  321. //
  322. // rd.ReportSections = new ReportSections();
  323. // rd.ReportSections.Add(
  324. // new ReportSection()
  325. // {
  326. // Width = new Syncfusion.RDL.DOM.Size("7.5in"),
  327. // Body = new Body()
  328. // {
  329. // Style = new Syncfusion.RDL.DOM.Style() { BackgroundColor = "White", Border = new Syncfusion.RDL.DOM.Border() },
  330. // Height = new Syncfusion.RDL.DOM.Size("10in"),
  331. //
  332. // },
  333. // Page = new Syncfusion.RDL.DOM.Page()
  334. // {
  335. // PageHeight = new Syncfusion.RDL.DOM.Size("11in"),
  336. // PageWidth = new Syncfusion.RDL.DOM.Size("8.5in"),
  337. // Style = new Syncfusion.RDL.DOM.Style() { BackgroundColor = "White", Border = new Syncfusion.RDL.DOM.Border() },
  338. // }
  339. // }
  340. // );
  341. // rd.EmbeddedImages = new EmbeddedImages();
  342. //
  343. // rd.RDLType = RDLType.RDL2010;
  344. // rd.CodeModules = new CodeModules();
  345. // rd.CodeModules.Add(new CodeModule() { Value = "System.Drawing, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a" });
  346. // rd.CodeModules.Add(new CodeModule() { Value = "Syncfusion.Pdf.Base, Version = 13.3350.0.7, Culture = neutral, PublicKeyToken = 3d67ed1f87d44c89" });
  347. // rd.CodeModules.Add(new CodeModule() { Value = "Syncfusion.Linq.Base, Version = 13.3350.0.7, Culture = neutral, PublicKeyToken = 3d67ed1f87d44c89" });
  348. //
  349. // rd.Classes = new Classes();
  350. // rd.Classes.Add(new Class() { ClassName = "Syncfusion.Pdf.Barcode.PDFCode39Barcode", InstanceName = "Code39" });
  351. // rd.Classes.Add(new Class() { ClassName = "Syncfusion.Pdf.Barcode.PdfQRBarcode", InstanceName = "QRCode" });
  352. //
  353. // rd.Code = @"
  354. // Public Function Code39BarCode(Text As String) As String
  355. // Dim _msg as String
  356. // try
  357. // Code39.BarHeight = 100
  358. // Code39.Text = Text
  359. // Code39.EnableCheckDigit = True
  360. // Code39.EncodeStartStopSymbols = True
  361. // Code39.ShowCheckDigit = False
  362. // Code39.TextDisplayLocation = 0
  363. // Dim _img As System.Drawing.Image = Code39.ToImage()
  364. // Dim ms As New System.IO.MemoryStream()
  365. // _img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
  366. // Dim _bytes = ms.ToArray()
  367. // Return System.Convert.ToBase64String(_bytes, 0, _bytes.Length)
  368. // Catch ex As Exception
  369. // _msg = ex.toString()
  370. // End Try
  371. // return Nothing
  372. // End Function
  373. //
  374. // Public Function QRBarCode(Text As String) As String
  375. // Dim _msg as String
  376. // try
  377. // QRCode.Text = Text
  378. // QRCode.XDimension = 4
  379. // Dim _img As System.Drawing.Image = QRCode.ToImage()
  380. // Dim ms As New System.IO.MemoryStream()
  381. // _img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
  382. // Dim _bytes = ms.ToArray()
  383. // Return System.Convert.ToBase64String(_bytes, 0, _bytes.Length)
  384. // Catch ex As Exception
  385. // _msg = ex.toString()
  386. // End Try
  387. // return Nothing
  388. // End Function
  389. //
  390. // ";
  391. // return rd;
  392. //
  393. // //MemoryStream memoryStream = new MemoryStream();
  394. // //TextWriter ws2 = new StreamWriter(memoryStream);
  395. // //xs2.Serialize(ws2, rd, serialize);
  396. // //memoryStream.Position = 0;
  397. // ////To save to a file.
  398. // //StringWriter ws3 = new StringWriter
  399. // //TextWriter ws3 = new StreamWriter(_tempfile);
  400. // //xs2.Serialize(ws3, rd, serialize);
  401. // //ws2.Close();
  402. // //ws3.Close();
  403. // //memoryStream.Close();
  404. //
  405. // }
  406. private static string DataTableToXML(Type type, CoreTable table)
  407. {
  408. var doc = new XmlDocument();
  409. var root = doc.CreateElement(string.Empty, type.Name.ToLower() + "s", string.Empty);
  410. doc.AppendChild(root);
  411. //var properties = CoreUtils.PropertyList(type, x => true, true);
  412. if (table != null)
  413. {
  414. if (table.Rows.Any())
  415. {
  416. foreach (var datarow in table.Rows)
  417. {
  418. var row = doc.CreateElement(string.Empty, type.Name.ToLower(), string.Empty);
  419. foreach (var column in table.Columns)
  420. {
  421. var field = doc.CreateElement(string.Empty, column.ColumnName.Replace('.', '_'), string.Empty);
  422. var oVal = datarow[column.ColumnName];
  423. var value = doc.CreateTextNode(oVal != null ? oVal.ToString() : "");
  424. field.AppendChild(value);
  425. row.AppendChild(field);
  426. }
  427. root.AppendChild(row);
  428. }
  429. }
  430. else
  431. {
  432. var row = doc.CreateElement(string.Empty, type.Name.ToLower(), string.Empty);
  433. foreach (var column in table.Columns)
  434. {
  435. var field = doc.CreateElement(string.Empty, column.ColumnName.Replace('.', '_'), string.Empty);
  436. var value = doc.CreateTextNode("");
  437. field.AppendChild(value);
  438. row.AppendChild(field);
  439. }
  440. root.AppendChild(row);
  441. }
  442. }
  443. var xmlString = "";
  444. using (var wr = new StringWriter())
  445. {
  446. doc.Save(wr);
  447. xmlString = wr.ToString();
  448. }
  449. return xmlString.Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n", "");
  450. }
  451. public static DataSet CreateReportDataSource(Dictionary<Type, CoreTable> dataenvironment)
  452. {
  453. var ds = new DataSet();
  454. foreach (var key in dataenvironment.Keys)
  455. {
  456. var table = dataenvironment[key];
  457. var dt = new DataTable(key.EntityName().Split('.').Last());
  458. foreach (var column in table.Columns)
  459. dt.Columns.Add(column.ColumnName);
  460. foreach (var row in table.Rows)
  461. dt.Rows.Add(row.Values.ToArray());
  462. ds.Tables.Add(dt);
  463. }
  464. return ds;
  465. }
  466. // private static void SetupReportData(ReportDefinition report, Dictionary<System.Type,CoreTable> dataenvironment)
  467. // {
  468. //
  469. // report.DataSets.Clear();
  470. // report.DataSources.Clear();
  471. // foreach (System.Type type in dataenvironment.Keys)
  472. // {
  473. // String _tempfile = Path.GetTempFileName();
  474. // String xml = DataTableToXML(type, dataenvironment[type]);
  475. // File.WriteAllText(_tempfile, xml);
  476. // // Create DataSource(s)
  477. // DataSource datasource = new DataSource()
  478. // {
  479. // Name = type.Name,
  480. // ConnectionProperties = new ConnectionProperties()
  481. // {
  482. // DataProvider = "XML",
  483. // IntegratedSecurity = true,
  484. // ConnectString = _tempfile
  485. // },
  486. // SecurityType = SecurityType.None,
  487. // };
  488. // report.DataSources.Add(datasource);
  489. //
  490. // Syncfusion.RDL.DOM.DataSet dataset = new Syncfusion.RDL.DOM.DataSet() { Name = type.Name };
  491. // dataset.Fields = new Fields();
  492. //
  493. // CoreTable table = dataenvironment[type];
  494. // foreach (var column in table.Columns)
  495. // {
  496. // dataset.Fields.Add(
  497. // new Field()
  498. // {
  499. // Name = column.ColumnName.Replace('.', '_'),
  500. // DataField = column.ColumnName.Replace('.', '_'),
  501. // TypeName = column.DataType.Name
  502. // }
  503. // );
  504. // }
  505. //
  506. // //var properties = CoreUtils.PropertyList(type, x => true, true);
  507. //
  508. // //// Create DataSet(s)
  509. // //foreach (String key in properties.Keys)
  510. // //{
  511. // // dataset.Fields.Add(
  512. // // new Field()
  513. // // {
  514. // // Name = key.Replace('.', '_'),
  515. // // DataField = key.Replace('.', '_'),
  516. // // TypeName = properties[key].Name
  517. // // }
  518. // // );
  519. // //}
  520. // dataset.Query = new Query()
  521. // {
  522. // DataSourceName = type.Name,
  523. // CommandType = Syncfusion.RDL.DOM.CommandType.Text,
  524. // CommandText = String.Format("{0}s/{0}", type.Name.ToLower())
  525. // };
  526. // report.DataSets.Add(dataset);
  527. // }
  528. // }
  529. //
  530. // private static void CleanupReportData(ReportDefinition report)
  531. // {
  532. // foreach (var ds in report.DataSources)
  533. // {
  534. // String _tempfile = ds.ConnectionProperties.ConnectString;
  535. // if (File.Exists(_tempfile))
  536. // File.Delete(_tempfile);
  537. // ds.ConnectionProperties.ConnectString = "";
  538. // }
  539. // report.DataSources[0].ConnectionProperties.ConnectString = "";
  540. // }
  541. //
  542. // private static ReportDefinition DeserialiseReport(String rdl)
  543. // {
  544. // String data = rdl;
  545. // try
  546. // {
  547. // byte[] debase64 = Convert.FromBase64String(rdl);
  548. // data = Encoding.UTF8.GetString(debase64);
  549. // }
  550. // catch (Exception e)
  551. // {
  552. // Logger.Send(LogType.Error, "", String.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
  553. // }
  554. // ReportDefinition report = null;
  555. // XmlSerializer xs = new XmlSerializer(typeof(ReportDefinition), "http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition");
  556. // using (StringReader stringreader = new StringReader(data)) // root.ToString()))
  557. // {
  558. // report = (ReportDefinition)xs.Deserialize(stringreader);
  559. // }
  560. // return report;
  561. // }
  562. //
  563. // [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")]
  564. // private static String SerialiseReport(ReportDefinition report)
  565. // {
  566. // var stream = SerialiseReportToStream(report);
  567. // return Encoding.UTF8.GetString(stream.ToArray());
  568. //
  569. // }
  570. //
  571. // [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")]
  572. // private static MemoryStream SerialiseReportToStream(ReportDefinition report)
  573. // {
  574. //
  575. // string nameSpace = "http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition";
  576. //
  577. // if (report.RDLType == RDLType.RDL2010)
  578. // nameSpace = "http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition";
  579. //
  580. // XmlSerializerNamespaces serialize = new XmlSerializerNamespaces();
  581. // serialize.Add("rd", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner");
  582. // XmlSerializer xs2 = new XmlSerializer(typeof(Syncfusion.RDL.DOM.ReportDefinition), nameSpace);
  583. // MemoryStream memoryStream = new MemoryStream();
  584. // TextWriter ws2 = new StreamWriter(memoryStream);
  585. // xs2.Serialize(ws2, report, serialize);
  586. // memoryStream.Position = 0;
  587. // return memoryStream;
  588. // //return Encoding.UTF8.GetString(memoryStream.ToArray());
  589. //
  590. // }
  591. // private static byte[] GhostScriptIt(byte[] pdf)
  592. // {
  593. // String input = Path.GetTempFileName();
  594. // File.WriteAllBytes(input, pdf);
  595. // byte[] result = new byte[] { };
  596. // GhostscriptVersionInfo gv = new GhostscriptVersionInfo(
  597. // new Version(0, 0, 0),
  598. // "gsdll32.dll",
  599. // string.Empty,
  600. // GhostscriptLicense.GPL
  601. // );
  602. // GhostscriptPipedOutput gsPipedOutput = new GhostscriptPipedOutput();
  603. // // pipe handle format: %handle%hexvalue
  604. // string outputPipeHandle = "%handle%" + int.Parse(gsPipedOutput.ClientHandle).ToString("X2");
  605. // using (GhostscriptProcessor processor = new GhostscriptProcessor(gv, true))
  606. // {
  607. // List<string> switches = new List<string>();
  608. // switches.Add("-empty");
  609. // switches.Add("-dQUIET");
  610. // switches.Add("-dSAFER");
  611. // switches.Add("-dBATCH");
  612. // switches.Add("-dNOPAUSE");
  613. // switches.Add("-dNOPROMPT");
  614. // switches.Add("-dCompatibilityLevel=1.4");
  615. // switches.Add("-sDEVICE=pdfwrite");
  616. // switches.Add("-o" + outputPipeHandle);
  617. // switches.Add("-q");
  618. // switches.Add("-f");
  619. // switches.Add(input);
  620. // try
  621. // {
  622. // processor.StartProcessing(switches.ToArray(), null);
  623. // result = gsPipedOutput.Data;
  624. // }
  625. // catch (Exception ex)
  626. // {
  627. // Console.WriteLine(ex.Message);
  628. // }
  629. // finally
  630. // {
  631. // gsPipedOutput.Dispose();
  632. // gsPipedOutput = null;
  633. // }
  634. // }
  635. // File.Delete(input);
  636. // return result;
  637. // }
  638. #endregion
  639. }
  640. }