Example #1
0
        public static byte[] ProcessXslFo(string xslfo, string name)
        {
            var foUserAgent = FopFactory.newFOUserAgent();
            foUserAgent.setCreator("Crispin (Apache FOP 2.1 via IKVM)");
            foUserAgent.setTitle(name);

            var outputStream = new java.io.ByteArrayOutputStream();

            var fop = FopFactory.newFop(org.apache.xmlgraphics.util.MimeConstants.__Fields.MIME_PDF, foUserAgent, outputStream);

            var transformerFactory = new com.sun.org.apache.xalan.@internal.xsltc.trax.TransformerFactoryImpl();
            var transformer = transformerFactory.newTransformer();

            var source = new StreamSource(new java.io.StringReader(xslfo));

            var result = new SAXResult(fop.getDefaultHandler());

            transformer.transform(source, result);

            /*
             * Adding the page count requires a second pass. This should be configurable
             * by the report itself.
             * */
            /*
            transformer.setParameter("page-count", fop.getResults().getPageCount().ToString());
            transformer.transform(src, res);
             * */

            outputStream.close();

            return outputStream.toByteArray();
        }
Example #2
0
        public static byte[] ProcessXslFo(string xslfo, string name)
        {
            var foUserAgent = FopFactory.newFOUserAgent();

            foUserAgent.setCreator("Crispin (Apache FOP 2.1 via IKVM)");
            foUserAgent.setTitle(name);

            var outputStream = new java.io.ByteArrayOutputStream();

            var fop = FopFactory.newFop(org.apache.xmlgraphics.util.MimeConstants.__Fields.MIME_PDF, foUserAgent, outputStream);

            var transformerFactory = new com.sun.org.apache.xalan.@internal.xsltc.trax.TransformerFactoryImpl();
            var transformer        = transformerFactory.newTransformer();

            var source = new StreamSource(new java.io.StringReader(xslfo));

            var result = new SAXResult(fop.getDefaultHandler());

            transformer.transform(source, result);

            /*
             * Adding the page count requires a second pass. This should be configurable
             * by the report itself.
             * */
            /*
             * transformer.setParameter("page-count", fop.getResults().getPageCount().ToString());
             * transformer.transform(src, res);
             * */

            outputStream.close();

            return(outputStream.toByteArray());
        }
Example #3
0
        private void PDF_Click(object sender, RoutedEventArgs e)
        {
            PDF.IsEnabled = false;
            string               filename      = ConfigurationManager.AppSettings["file"].Split('.')[0];
            string               fileextension = "." + ConfigurationManager.AppSettings["file"].Split('.')[1];
            string               saved_file    = String.Format(@"./{0}_{1}_{2}{3}", filename, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString().Replace(':', '.'), fileextension);
            string               pdf_file      = String.Format(@"./{0}_{1}_{2}.pdf", filename, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString().Replace(':', '.'), fileextension);
            SaveFile             sf            = new SaveFile(saved_file, document);
            XslCompiledTransform xslt          = new XslCompiledTransform();

            xslt.Load("./report.xslt");
            xslt.Transform(saved_file, "./report.xml");
            xslt.Load("./pdf.xslt");
            xslt.Transform("./report.xml", "./report.fo");
            FopFactory fopFactory = FopFactory.newInstance(new java.net.URI("."));


            //in this stream we will get the generated pdf file
            OutputStream o = new DotNetOutputMemoryStream();

            try
            {
                Fop fop = fopFactory.newFop("application/pdf", o);
                TransformerFactory factory     = TransformerFactory.newInstance();
                Transformer        transformer = factory.newTransformer();


                //read the template from disc
                Source src = new StreamSource(new File("report.fo"));
                Result res = new SAXResult(fop.getDefaultHandler());
                transformer.transform(src, res);
            }
            finally
            {
                o.close();
            }
            using (System.IO.FileStream fs = System.IO.File.Create(pdf_file))
            {
                //write from the .NET MemoryStream stream to disc the generated pdf file
                var data = ((DotNetOutputMemoryStream)o).Stream.GetBuffer();
                fs.Write(data, 0, data.Length);
            }
            PDF.IsEnabled = true;
        }
Example #4
0
        /// <summary>
        /// Get the Area Tree from Antenna House Formatter
        /// </summary>
        /// <param name="inputStream">XSL:FO tree as ByteArryInputStream</param>
        /// <param name="configFileName">FOP configuration file name: Setting file for Antenna House Formatter rendering</param>
        /// <returns></returns>
        protected XPathDocument GetAreaTrea(ByteArrayInputStream inputStream, string configFileName)
        {
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();

            FOUserAgent            userAgent    = new FOUserAgent(FopFactory.newInstance());
            FopFactoryConfigurator configurator = new FopFactoryConfigurator(userAgent.getFactory());

            if (string.IsNullOrEmpty(configFileName) == false)
            {
                userAgent.getFactory().setUserConfig(configFileName);
            }
            Fop fop = userAgent.getFactory().newFop(MimeConstants.__Fields.MIME_FOP_AREA_TREE, userAgent, outStream);
            TransformerFactory tf          = new TransformerFactoryImpl();
            Transformer        transformer = tf.newTransformer();
            Source             src         = new StreamSource(inputStream);
            Result             res         = new SAXResult(fop.getDefaultHandler());

            transformer.transform(src, res);

            return(outStream.ToXPathDocument());
        }
Example #5
0
        /// <summary>
        /// Start this from directory \samples\samples\fop\
        /// with \samples\lib populated with jni4net.j.jar and jni4net.n.dll
        /// and with \samples\samples\fop\lib populated with FOP jar files.
        /// </summary>
        private static void Main()
        {
            FixStartupDirectory();

            // automaticaly setup Java classpath to find jni4net.j
            var setup = new BridgeSetup(true);

            // setup Java classpath to find FOP libraries
            setup.AddAllJarsClassPath("lib");

            // we don't need to call back from Java
            setup.BindStatic = false;

            // now we create JVM and bind jni4net core
            Bridge.CreateJVM(setup);

            // now we bind all proxies of FOP objects
            // which are compiled in this assembly
            Bridge.RegisterAssembly(typeof(Program).Assembly);

            const string inFileName  = "data/jni4net.fo";
            const string outFileName = "data/jni4net.pdf";


            //Below is just plain Copy&Paste of FOP basic sample java code
            OutputStream output = null;

            try
            {
                // Step 1: Construct a FopFactory
                // (reuse if you plan to render multiple documents!)
                FopFactory fopFactory = FopFactory.newInstance();

                // Step 2: Set up output stream.
                output = new BufferedOutputStream(new FileOutputStream(new File(outFileName)));

                // Step 3: Construct fop with desired output format
                Fop fop = fopFactory.newFop(MimeConstants_.MIME_PDF, output);

                // Step 4: Setup JAXP using identity transformer
                TransformerFactory factory     = TransformerFactory.newInstance();
                Transformer        transformer = factory.newTransformer(); // identity transformer

                // Step 5: Setup input and output for XSLT transformation
                // Setup input stream
                Source src = new StreamSource(new File(inFileName));

                // Resulting SAX events (the generated FO) must be piped through to FOP
                Result res = new SAXResult(fop.getDefaultHandler());

                // Step 6: Start XSLT transformation and FOP processing
                transformer.transform(src, res);
            }
            finally
            {
                // Clean-up
                if (output != null)
                {
                    output.close();
                }
            }
        }
Example #6
0
        /// <summary>
        /// Start this from directory \samples\samples\fop\
        /// with \samples\lib populated with jni4net.j.jar and jni4net.n.dll
        /// and with \samples\samples\fop\lib populated with FOP jar files.
        /// </summary>
        private static void Main()
        {
            FixStartupDirectory();

            // automaticaly setup Java classpath to find jni4net.j
            var setup = new BridgeSetup(true);

            // setup Java classpath to find FOP libraries
            setup.AddAllJarsClassPath("lib");

            // we don't need to call back from Java
            setup.BindStatic = false;

            // now we create JVM and bind jni4net core
            Bridge.CreateJVM(setup);

            // now we bind all proxies of FOP objects
            // which are compiled in this assembly
            Bridge.RegisterAssembly(typeof (Program).Assembly);

            const string inFileName = "data/jni4net.fo";
            const string outFileName = "data/jni4net.pdf";


            //Below is just plain Copy&Paste of FOP basic sample java code
            OutputStream output = null;
            try
            {
                // Step 1: Construct a FopFactory
                // (reuse if you plan to render multiple documents!)
                FopFactory fopFactory = FopFactory.newInstance();

                // Step 2: Set up output stream.
                output = new BufferedOutputStream(new FileOutputStream(new File(outFileName)));

                // Step 3: Construct fop with desired output format
                Fop fop = fopFactory.newFop(MimeConstants_.MIME_PDF, output);

                // Step 4: Setup JAXP using identity transformer
                TransformerFactory factory = TransformerFactory.newInstance();
                Transformer transformer = factory.newTransformer(); // identity transformer

                // Step 5: Setup input and output for XSLT transformation
                // Setup input stream
                Source src = new StreamSource(new File(inFileName));

                // Resulting SAX events (the generated FO) must be piped through to FOP
                Result res = new SAXResult(fop.getDefaultHandler());

                // Step 6: Start XSLT transformation and FOP processing
                transformer.transform(src, res);
            }
            finally
            {
                // Clean-up
                if (output != null)
                {
                    output.close();
                }
            }
        }