/* * Copyright (c) 2004 RenderX, Inc. All Rights Reserved. * * This software is provided as a sample for evaluation * of XEP.NET formatter only. RenderX declines every liability * for negative effects of its use for other purposes. */ using System; using System.IO; using System.Xml; using System.Xml.Xsl; using System.Xml.XPath; using System.Collections; namespace Examples.Net { /// /// Example that displays how to perform formatting from XSL-FO to PDF /// public class FoToPdfStream { /// /// Return values. /// internal enum ReturnValue { Error=-1, Ok=0 }; /// /// The main entry point /// [STAThread] static int Main(string[] saArgs) { try { if (saArgs == null || saArgs.Length != 2) { Console.Out.WriteLine("Invalid arguments.\n\n usage:\n FoToPdfStream fo_file pdf_file\n"); return (int)ReturnValue.Error; } FoToPdfStream.Process(saArgs[0], saArgs[1]); } catch (Exception e) { //This should catch everything Console.Out.WriteLine(); Console.Out.WriteLine("Some error has occured:"); Console.Out.WriteLine(e); return (int)ReturnValue.Error; } return (int)ReturnValue.Ok; } /// /// Process command line arguments transform given FO file to PDF. /// /// Return value code, 0 - Ok, others - error. protected static void Process(String sFoFile, String sPdfFile) { if (!File.Exists(sFoFile)) throw new FileNotFoundException("Can't find file " + sFoFile); Stream inStream = File.OpenRead(sFoFile); Stream outPdf = File.Create(sPdfFile); Hashtable props = new Hashtable(); try { props.Add("ROOT", @"C:\Program Files\RenderX\XEP.NET 3.8"); Renderx.Xep.Formatter formatter = new Renderx.Xep.Formatter(props, null); formatter.Format(sFoFile, new XmlTextReader(inStream), outPdf, Renderx.Xep.Formatter.OUTPUT_PDF, null, null); } finally { inStream.Close(); outPdf.Close(); } } } }