public byte[] GetFileBytes(Report report) { var pages = report.BuildPages(); int width = (int)report.PageWidthPoints; int height = (int)report.PageHeightPoints; string filename = string.Format("gen-{0}.pdf", Guid.NewGuid()); try { using (Cairo.PdfSurface pdf = new Cairo.PdfSurface(filename, width, height)) { using (Cairo.Context g = new Cairo.Context(pdf)) { var render = new fyiReporting.RdlGtkViewer.RenderCairo(g); render.RunPages(pages); } } byte[] bytes = File.ReadAllBytes(filename); return bytes; } finally { if (File.Exists(filename)) { File.Delete(filename); } } }
// Run the report passing the parameter values and the output public void Run(IDictionary parms, OutputPresentationType type) { r.RunGetData(parms); var pgs = r.BuildPages(); r.RunRender(_sg, type, pgs); 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); }
private void Generate(Report report) { try { _Pages = report.BuildPages(); // create array for XAML pages. Actual XAML will be created on demand. _XamlPages = new string[_Pages.Count]; for (int i = 0; i < _XamlPages.Length; i++) _XamlPages[i] = null; } catch(Exception e) { AddError(8, string.Format("Exception generating report {0}", e.Message)); } if (report.ErrorMaxSeverity > 0) { AddError(report.ErrorMaxSeverity, report.ErrorItems); report.ErrorReset(); } return; }
private Pages GetPages(Report report) { Pages pgs = null; ListDictionary ld = GetParameters(); // split parms into dictionary try { report.RunGetData(ld); pgs = report.BuildPages(); if (report.ErrorMaxSeverity > 0) { if (_errorMsgs == null) { _errorMsgs = report.ErrorItems; // keep a copy of the errors } else { foreach (string err in report.ErrorItems) { _errorMsgs.Add(err); } } report.ErrorReset(); } } catch (Exception e) { string msg = e.Message; } return pgs; }
public void Rebuild() { _report = this.GetReport(SourceRdl); _report.RunGetData(Parameters); pages = _report.BuildPages(); List<ReportArea> tempList = new List<ReportArea>(); foreach (ReportArea w in this.vboxPages.Children) { tempList.Add(w); } foreach (ReportArea w in tempList) { vboxPages.Remove(w); } for (int pageCount = 0; pageCount < pages.Count; pageCount++) { ReportArea area = new ReportArea(this.DefaultBackend); area.SetReport(_report, pages[pageCount]); vboxPages.PackStart(area, true, true); } this.Show(); if (_report.ErrorMaxSeverity > 0) { // TODO: add error messages back //SetErrorMessages(report.ErrorItems); } }