/// <summary> /// Save the report to the output selected. /// </summary> /// <param name='report'> /// Report. /// </param> /// <param name='FileName'> /// File name. /// </param> private void ExportReport(Report report, string FileName, OutputPresentationType exportType) { OneFileStreamGen sg = null; try { sg = new OneFileStreamGen(FileName, true); report.RunRender(sg, exportType); } catch (Exception ex) { Gtk.MessageDialog m = new Gtk.MessageDialog(null, Gtk.DialogFlags.Modal, Gtk.MessageType.Error, Gtk.ButtonsType.Ok, false, ex.Message); m.Run(); m.Destroy(); } finally { if (sg != null) { sg.CloseMainStream(); } } return; }
public void RenderPdf_iTextSharpDraw(string file2test, string cultureName, string suffixFileName, Func <Dictionary <string, IEnumerable> > fillDatasets) { GeneralUtils.ChangeCurrentCultrue(cultureName); OneFileStreamGen sg = null; Uri fileRdlUri = new Uri(_reportFolder, file2test); Report rap = RdlUtils.GetReport(fileRdlUri); rap.Folder = _reportFolder.LocalPath; if (fillDatasets != null) { Dictionary <string, IEnumerable> dataSets = fillDatasets(); foreach (var dataset in dataSets) { rap.DataSets[dataset.Key].SetData(dataset.Value); } } rap.RunGetData(null); string fileNameOut = string.Format("{0}_{1}_{2}{3}", file2test, cultureName, suffixFileName, _extOuput); string fullOutputPath = System.IO.Path.Combine(_outputFolder.LocalPath, fileNameOut); sg = new OneFileStreamGen(fullOutputPath, true); rap.RunRender(sg, OutputPresentationType.RenderPdf_iTextSharp); }
/// <summary> /// Export the report to file /// </summary> /// <param name="source">Xml source of report</param> /// <param name="parameters">Example: parameter1=someValue¶meter2=anotherValue</param> public static void Export(string source, string parameters, string fileName, OutputPresentationType exportType) { // Compile the report report = GetReport(source); if (report == null) { throw new ArgumentException("Can not compile report"); } report.RunGetData(GetParmeters(parameters)); OneFileStreamGen sg = null; try { sg = new OneFileStreamGen(fileName, true); report.RunRender(sg, exportType); } catch (Exception ex) { throw ex; } finally { if (sg != null) { sg.CloseMainStream(); } } }
private string BuildReport(string templateName, List <Param> paramList, OutputPresentationType output) { var outputFileName = GetOutputFileName(templateName, output); GeneralUtils.ChangeCurrentCultrue("es-ES"); var report = GetReport(templateName, paramList); var paramsList = GetReportParams(paramList, ref report); report.RunGetData(paramsList); var pages = report.BuildPages(); var sg = new OneFileStreamGen(outputFileName, true); switch (output) { case OutputPresentationType.Word: report.RunRender(sg, OutputPresentationType.HTML, pages); outputFileName = GetWordDocumentFromHtml(outputFileName); break; case OutputPresentationType.RenderPdf_iTextSharp: case OutputPresentationType.PDF: report.ItextPDF = true; report.RunRenderPdf(sg, pages); break; case OutputPresentationType.PDFOldStyle: report.ItextPDF = false; report.RunRenderPdf(sg, pages); break; default: report.RunRender(sg, output, pages); break; } sg.CloseMainStream(); sg.Dispose(); return(outputFileName); }
/// <summary> /// Save the file. The extension determines the type of file to save. /// </summary> /// <param name="FileName">Name of the file to be saved to.</param> /// <param name="ext">Type of file to save. Should be "pdf", "xml", "html", "mhtml".</param> public void SaveAs(string FileName, string type) { LoadPageIfNeeded(); string ext = type.ToLower(); OneFileStreamGen sg = new OneFileStreamGen(FileName, true); // overwrite with this name try { switch (ext) { case "pdf": _Report.RunRenderPdf(sg, _pgs); break; case "xml": _Report.RunRender(sg, OutputPresentationType.XML); break; case "html": case "htm": _Report.RunRender(sg, OutputPresentationType.HTML); break; case "mhtml": case "mht": _Report.RunRender(sg, OutputPresentationType.MHTML); break; default: throw new Exception("Unsupported file extension for SaveAs"); } } finally { if (sg != null) { sg.CloseMainStream(); } } return; }
private void SaveAsPdf(Report report, OneFileStreamGen sg) { Pages pgs = report.BuildPages(); FileStream strm = null; System.Drawing.Image im = null; // Handle any parameters float x = 0; // x position of image float y = 0; // y position of image float h = 0; // height of image float w = 0; // width position of image string fname = null; int index = _StampInfo.LastIndexOf('?'); bool bClip = false; // we force clip if either height or width not specified if (index >= 0) { // Get all the arguments for sizing the image ListDictionary ld = this.GetParameters(_StampInfo.Substring(index + 1)); fname = _StampInfo.Substring(0, index); string ws = (string)ld["x"]; x = Size(ws); ws = (string)ld["y"]; y = Size(ws); ws = (string)ld["h"]; if (ws == null) { bClip = true; ws = "12in"; // just give it a big value } h = Size(ws); ws = (string)ld["w"]; if (ws == null) { bClip = true; ws = "12in"; // just give it a big value } w = Size(ws); } else { fname = _StampInfo; // force size bClip = true; h = Size("12in"); w = Size("12in"); } // Stamp the first page foreach (Page p in pgs) // we loop then break after obtaining one { try { strm = new FileStream(fname, System.IO.FileMode.Open, FileAccess.Read); im = System.Drawing.Image.FromStream(strm); int height = im.Height; int width = im.Width; MemoryStream ostrm = new MemoryStream(); /* Replaced with high quality JPEG encoder * 06122007AJM */ ImageFormat imf = ImageFormat.Jpeg; //im.Save(ostrm, imf); System.Drawing.Imaging.ImageCodecInfo[] info; info = ImageCodecInfo.GetImageEncoders(); EncoderParameters encoderParameters; encoderParameters = new EncoderParameters(1); encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 100L); System.Drawing.Imaging.ImageCodecInfo codec = null; for (int i = 0; i < info.Length; i++) { if (info[i].FormatDescription == "JPEG") { codec = info[i]; break; } } im.Save(ostrm, codec, encoderParameters); // end change byte[] ba = ostrm.ToArray(); ostrm.Close(); PageImage pi = new PageImage(imf, ba, width, height); pi.SI = new StyleInfo(); // defaults are ok; don't want border, etc // Set location, height and width pi.X = x; pi.Y = y; pi.H = h; pi.W = w; pi.Sizing = bClip? ImageSizingEnum.Clip: ImageSizingEnum.FitProportional; p.InsertObject(pi); } catch (Exception e) { // image failed to load, continue processing Console.WriteLine("Stamping image failed. {0}", e.Message); } finally { if (strm != null) { strm.Close(); } if (im != null) { im.Dispose(); } } break; // only stamp the first page } // Now create the PDF report.RunRenderPdf(sg, pgs); }
/// <summary> /// Save the file. The extension determines the type of file to save. /// </summary> /// <param name="FileName">Name of the file to be saved to.</param> /// <param name="ext">Type of file to save. Should be "pdf", "xml", "html", mht.</param> private void SaveAs(Report report, string FileName, string type) { string ext = type.ToLower(); OneFileStreamGen sg = null; try { if (ext == "tifb") { FileName = FileName.Substring(0, FileName.Length - 1); // get rid of the 'b' } sg = new OneFileStreamGen(FileName, true); // overwrite with this name switch (ext) { case "pdf": if (this._StampInfo == null) { report.RunRender(sg, OutputPresentationType.PDF); } else { SaveAsPdf(report, sg); } break; case "xml": report.RunRender(sg, OutputPresentationType.XML); break; case "mht": report.RunRender(sg, OutputPresentationType.MHTML); break; case "html": case "htm": report.RunRender(sg, OutputPresentationType.HTML); break; case "csv": report.RunRender(sg, OutputPresentationType.CSV); break; case "xlsx": report.RunRender(sg, OutputPresentationType.Excel); break; case "rtf": report.RunRender(sg, OutputPresentationType.RTF); break; case "tif": case "tiff": report.RunRender(sg, OutputPresentationType.TIF); break; case "tifb": report.RunRender(sg, OutputPresentationType.TIFBW); break; default: Console.WriteLine("Unsupported file extension '{0}'. Must be 'pdf', 'xml', 'mht', 'csv', 'xslx', 'rtf', 'tif', 'tifb' or 'html'", type); returnCode = 8; break; } } catch (Exception e) { Console.WriteLine(e.Message); returnCode = 8; } finally { if (sg != null) { sg.CloseMainStream(); } } if (report.ErrorMaxSeverity > 0) { // have errors fill out the msgs Console.WriteLine("{0} has the following runtime errors:", FileName); foreach (string emsg in report.ErrorItems) { Console.WriteLine(emsg); // output message to console } report.ErrorReset(); } return; }
/// <summary> /// Save the file. The extension determines the type of file to save. /// </summary> /// <param name="FileName">Name of the file to be saved to.</param> /// <param name="ext">Type of file to save. Should be "pdf", "xml", "html", mht.</param> private void SaveAs(Report report, string FileName, string type) { string ext = type.ToLower(); OneFileStreamGen sg = null; try { bool isOldPdf = false; if (System.Environment.OSVersion.Platform == PlatformID.Unix && type == "pdf") { if (System.IO.Directory.Exists("/usr/share/fonts/truetype/msttcorefonts") == false) { isOldPdf = true; } } if (ext == "tifb") { FileName = FileName.Substring(0, FileName.Length - 1); // get rid of the 'b' } sg = new OneFileStreamGen(FileName, true); // overwrite with this name switch (ext) { case "pdf": if (this._StampInfo == null) { if (isOldPdf) { report.RunRender(sg, OutputPresentationType.PDFOldStyle); } else { report.RunRender(sg, OutputPresentationType.PDF); } } else { SaveAsPdf(report, sg); } break; case "xml": report.RunRender(sg, OutputPresentationType.XML); break; case "mht": report.RunRender(sg, OutputPresentationType.MHTML); break; case "html": case "htm": report.RunRender(sg, OutputPresentationType.HTML); break; case "csv": report.RunRender(sg, OutputPresentationType.CSV); break; case "xlsx_table": report.RunRender(sg, OutputPresentationType.ExcelTableOnly); break; case "xlsx": report.RunRender(sg, OutputPresentationType.Excel2007); break; case "rtf": report.RunRender(sg, OutputPresentationType.RTF); break; case "tif": case "tiff": report.RunRender(sg, OutputPresentationType.TIF); break; case "tifb": report.RunRender(sg, OutputPresentationType.TIFBW); break; default: Console.WriteLine("Unsupported file extension '{0}'. Must be 'pdf', 'xml', 'mht', 'csv', 'xslx', 'xlsx_table', 'rtf', 'tif', 'tifb' or 'html'", type); returnCode = 8; break; } } catch (Exception e) { Console.WriteLine(e.Message); returnCode = 8; } finally { if (sg != null) { sg.CloseMainStream(); } } if (report.ErrorMaxSeverity > 0) { // have errors fill out the msgs Console.WriteLine("{0} has the following runtime errors:", FileName); foreach (string emsg in report.ErrorItems) { Console.WriteLine(emsg); // output message to console } report.ErrorReset(); } return; }