FonetDriver provides the client with a single interface to invoking FO.NET.
The examples belows demonstrate several ways of invoking FO.NET. The methodology is the same regardless of how FO.NET is embedded in your system (ASP.NET, WinForm, Web Service, etc).
Inheritance: IDisposable
Example #1
0
        /// <summary>
        ///     Executes the conversion reading the source tree from the input
        ///     reader, converting it to a format dictated by the render and
        ///     writing it to the supplied output stream.
        /// </summary>
        /// <remarks>
        ///     The evaluation copy of this class will output an evaluation
        ///     banner to standard out
        /// </remarks>
        /// <param name="inputReader">
        ///     Reader that provides fast, non-cached, forward-only access
        ///     to XML data
        /// </param>
        /// <param name="outputStream">
        ///     Any subclass of the Stream class, e.g. FileStream
        /// </param>
        public void Render(XmlReader inputReader, Stream outputStream)
        {
            if (activeDriver != null)
            {
                throw new SystemException("ActiveDriver is set.");
            }

            try
            {
                activeDriver = this;

                try
                {
                    // Constructs an area tree renderer and supplies the renderer options
                    PdfRenderer renderer = new PdfRenderer(outputStream);

                    if (renderOptions != null)
                    {
                        renderer.Options = renderOptions;
                    }

                    // Create the stream-renderer.
                    StreamRenderer sr = new StreamRenderer(renderer);

                    // Create the tree builder and give it the stream renderer.
                    FOTreeBuilder tb = new FOTreeBuilder();
                    tb.SetStreamRenderer(sr);

                    // Setup the mapping between xsl:fo elements and our fo classes.
                    StandardElementMapping sem = new StandardElementMapping();
                    sem.AddToBuilder(tb);

                    // Start processing the xml document.
                    tb.Parse(inputReader);
                }
                finally
                {
                    if (CloseOnExit)
                    {
                        // Flush and close the output stream
                        outputStream.Flush();
                        outputStream.Close();
                    }
                }
            }
            finally
            {
                activeDriver = null;
            }
        }
Example #2
0
        protected void RenderDocument(StringBuilder document)
        {
            if (document == null)
                throw new ArgumentNullException("document");

            try {
                var driver = new FonetDriver
                                 {
                                     Options =
                                         new Fonet.Render.Pdf.PdfRendererOptions
                                             {Author = OrgName, Title = DocumentTitle}
                                 };
                driver.OnInfo += driver_OnInfo;
                string tempFile = CreateTempFile(document.ToString());
                driver.Render(tempFile, OutputPath);
                File.Delete(tempFile);
            }
            catch(Exception e)
            {
                Debug.Print(e.Message);
            }

            OnUpdateProgress(100);
            if (ExportCompleted != null)
                ExportCompleted(this, null);
        }
Example #3
0
        /// <summary>
        ///     Executes the conversion reading the source tree from the input 
        ///     reader, converting it to a format dictated by the render and 
        ///     writing it to the supplied output stream.
        /// </summary>
        /// <remarks>
        ///     The evaluation copy of this class will output an evaluation
        ///     banner to standard out
        /// </remarks>
        /// <param name="inputReader">
        ///     Reader that provides fast, non-cached, forward-only access 
        ///     to XML data
        /// </param>
        /// <param name="outputStream">
        ///     Any subclass of the Stream class, e.g. FileStream
        /// </param>
        public void Render(XmlReader inputReader, Stream outputStream)
        {
			if(activeDriver != null)
				throw new SystemException("ActiveDriver is set.");

			try
			{
				activeDriver = this;

				try
				{
					// Constructs an area tree renderer and supplies the renderer options
					PdfRenderer renderer = new PdfRenderer(outputStream);

					if(renderOptions != null)
					{
						renderer.Options = renderOptions;
					}

					// Create the stream-renderer.
					StreamRenderer sr = new StreamRenderer(renderer);

					// Create the tree builder and give it the stream renderer.
					FOTreeBuilder tb = new FOTreeBuilder();
					tb.SetStreamRenderer(sr);

					// Setup the mapping between xsl:fo elements and our fo classes.
					StandardElementMapping sem = new StandardElementMapping();
					sem.AddToBuilder(tb);

					// Start processing the xml document.
					tb.Parse(inputReader);
				}
				finally
				{
					if(CloseOnExit)
					{
						// Flush and close the output stream
						outputStream.Flush();
						outputStream.Close();
					}
				}
			}
			finally
			{
				activeDriver = null;
			}
        }