Ejemplo n.º 1
0
        public void SaveAs(string FileName, fyiReporting.RDL.OutputPresentationType type)
        {
            fyiReporting.RDL.OneFileStreamGen sg = null;

            try
            {
                // Must use the RunGetData before each export or there is no data.
                _report.RunGetData(this.Parameters);

                sg = new fyiReporting.RDL.OneFileStreamGen(FileName, true);
                _report.RunRender(sg, type);
            }
            catch (Exception ex)
            {
                MessageDialog.ShowError(ex.Message);
            }
            finally
            {
                if (sg != null)
                {
                    sg.CloseMainStream();
                }
            }
            return;
        }
Ejemplo n.º 2
0
        public void 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.PDF);
        }
Ejemplo n.º 3
0
        private void RunRenderMht(IStreamGen sg)
        {
            OneFileStreamGen temp = null;
            FileStream       fs   = null;

            try
            {
                string tempHtmlReportFileName = Path.ChangeExtension(Path.GetTempFileName(), "htm");
                temp = new OneFileStreamGen(tempHtmlReportFileName, true);
                RunRender(temp, OutputPresentationType.HTML);
                temp.CloseMainStream();

                // Create the mht file (into a temporary file position)
                MhtBuilder mhtConverter = new MhtBuilder();
                string     fileName     = Path.ChangeExtension(Path.GetTempFileName(), "mht");
                mhtConverter.SavePageArchive(fileName, "file://" + tempHtmlReportFileName);

                // clean up the temporary files
                foreach (string tempFileName in temp.FileList)
                {
                    try
                    {
                        File.Delete(tempFileName);
                    }
                    catch {}
                }

                // Copy the mht file to the requested stream
                Stream os = sg.GetStream();
                fs = File.OpenRead(fileName);
                byte[] ba = new byte[4096];
                int    rb = 0;
                while ((rb = fs.Read(ba, 0, ba.Length)) > 0)
                {
                    os.Write(ba, 0, rb);
                }
            }
            catch (Exception ex)
            {
                rl.LogError(8, "Error converting HTML to MHTML " + ex.Message +
                            Environment.NewLine + ex.StackTrace);
            }
            finally
            {
                if (temp != null)
                {
                    temp.CloseMainStream();
                }
                if (fs != null)
                {
                    fs.Close();
                }
                _Cache = new RCache();
            }
        }
Ejemplo n.º 4
0
        /// <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;
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        /// <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;
        }
Ejemplo n.º 7
0
        private void RunRenderMht(IStreamGen sg)
        {
            OneFileStreamGen temp = null;
            FileStream fs=null;
            try
            {
                string tempHtmlReportFileName = Path.ChangeExtension(Path.GetTempFileName(), "htm");
                temp = new OneFileStreamGen(tempHtmlReportFileName, true);
                RunRender(temp, OutputPresentationType.HTML);
                temp.CloseMainStream();

                // Create the mht file (into a temporary file position)
                MhtBuilder mhtConverter = new MhtBuilder();
                string fileName = Path.ChangeExtension(Path.GetTempFileName(), "mht");
                mhtConverter.SavePageArchive(fileName, "file://" + tempHtmlReportFileName);

                // clean up the temporary files
                foreach (string tempFileName in temp.FileList)
                {
                    try
                    {
                        File.Delete(tempFileName);
                    }
                    catch{}
                }

                // Copy the mht file to the requested stream
                Stream os = sg.GetStream();
                fs = File.OpenRead(fileName);
                byte[] ba = new byte[4096];
                int rb=0;
                while ((rb = fs.Read(ba, 0, ba.Length)) > 0)
                {
                    os.Write(ba, 0, rb);
                }

            }
            catch (Exception ex)
            {
                rl.LogError(8, "Error converting HTML to MHTML " + ex.Message +
                                    Environment.NewLine + ex.StackTrace);
            }
            finally
            {
                if (temp != null)
                    temp.CloseMainStream();
                if (fs != null)
                    fs.Close();
                _Cache = new RCache();
            }
        }
Ejemplo n.º 8
0
        /// <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="type">Type of file to save.  Should be "pdf", "xml", "html", "mhtml", "csv", "rtf", "excel", "tif".</param>
        public void SaveAs(string FileName, fyiReporting.RDL.OutputPresentationType type)
        {
            LoadPageIfNeeded();

            OneFileStreamGen sg = new OneFileStreamGen(FileName, true);	// overwrite with this name
            if (!(type == OutputPresentationType.PDF || type == OutputPresentationType.PDFOldStyle ||
                type == OutputPresentationType.TIF || type  == OutputPresentationType.TIFBW))
            {
                ListDictionary ld = GetParameters();		// split parms into dictionary
                _Report.RunGetData(ld);                     // obtain the data (again)
            }
            try
            {
                switch (type)
                {
                    case  OutputPresentationType.PDF:
                         _Report.ItextPDF = true;
                        _Report.RunRenderPdf(sg, _pgs);
                        break;
                    case OutputPresentationType.PDFOldStyle:
                        _Report.ItextPDF = false;
                        _Report.RunRenderPdf(sg, _pgs);
                        break;
                    case  OutputPresentationType.TIF:
                        _Report.RunRenderTif(sg, _pgs, true);
                        break;
                    case  OutputPresentationType.TIFBW:
                        _Report.RunRenderTif(sg, _pgs, false);
                        break;
                    case OutputPresentationType.CSV:
                        _Report.RunRender(sg, OutputPresentationType.CSV);
                        break;
                    case OutputPresentationType.Word:
                    case OutputPresentationType.RTF:
                        _Report.RunRender(sg, OutputPresentationType.RTF);
                        break;
                    case OutputPresentationType.Excel:
                        _Report.RunRender(sg, OutputPresentationType.Excel);
                        break;
                    case OutputPresentationType.XML:
                        _Report.RunRender(sg, OutputPresentationType.XML);
                        break;
                    case OutputPresentationType.HTML:
                        _Report.RunRender(sg, OutputPresentationType.HTML);
                        break;
                    case OutputPresentationType.MHTML:
                        _Report.RunRender(sg, OutputPresentationType.MHTML);
                        break;
                    default:
                        throw new Exception(Strings.RdlViewer_Error_UnsupportedExtension);
                }
            }
            finally
            {
                if (sg != null)
                {
                    sg.CloseMainStream();
                }

            }
            return;
        }
Ejemplo n.º 9
0
        public void SaveAs (string FileName, fyiReporting.RDL.OutputPresentationType type)
        {
            fyiReporting.RDL.OneFileStreamGen sg = null;

            try
            {
                // Must use the RunGetData before each export or there is no data.
                _report.RunGetData(this.Parameters);

                sg = new fyiReporting.RDL.OneFileStreamGen(FileName, true);
                _report.RunRender(sg, type);
            }
            catch (Exception ex)
            {
                MessageDialog.ShowError(ex.Message);
            }
            finally
            {
                if (sg != null)
                {
                    sg.CloseMainStream();
                }
            }
            return;
        }
Ejemplo n.º 10
0
		/// <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":
                        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;
		}
Ejemplo n.º 11
0
        /// <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", "csv", "rtf", "excel", "tif".</param>
        public void SaveAs(string FileName, string type)
        {
            LoadPageIfNeeded();

            string ext = type.ToLower();
            OneFileStreamGen sg = new OneFileStreamGen(FileName, true);	// overwrite with this name
            if (!(ext == "pdf" || ext == "tif" || ext == "tiff" || ext == "tifbw"))
            {
                ListDictionary ld = GetParameters();		// split parms into dictionary
                _Report.RunGetData(ld);                     // obtain the data (again)
            }
            try
            {
                switch(ext)
                {
                    case "pdf":
                        _Report.RunRenderPdf(sg, _pgs);
                        break;
                    case "tif":
                    case "tiff":
                        _Report.RunRenderTif(sg, _pgs, true);
                        break;
                    case "tifbw":
                        _Report.RunRenderTif(sg, _pgs, false);
                        break;
                    case "csv":
                        _Report.RunRender(sg, OutputPresentationType.CSV);
                        break;
                    case "rtf":
                        _Report.RunRender(sg, OutputPresentationType.RTF);
                        break;
                    case "excel":
                    case "xlsx":
                        _Report.RunRender(sg, OutputPresentationType.Excel);
                        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;
        }
Ejemplo n.º 12
0
		/// <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;
		}