Ejemplo n.º 1
0
        protected SingleConvertToPDF()
        {
            try {
                string sPathExe = "C:\\Program Files (x86)\\Prince\\Engine\\bin\\prince.exe";
                if (File.Exists(sPathExe))
                {
                    // instantiate Prince by specifying the full path to the engine executable
                    prn = new Prince("C:\\Program Files (x86)\\Prince\\Engine\\bin\\prince.exe");
                    // specify the log file for error and warning messages
                    // make sure that you have write permissions for this file
                    sPathDirectory = System.AppDomain.CurrentDomain.BaseDirectory;
                    prn.SetLog(sPathDirectory + "\\HtmlToPdf\\logPrinceHtmlToPdf.txt");
                    // apply a CSS style sheet (optional)

                    prn.AddStyleSheet(sPathDirectory + "\\css\\bootstrap-theme.css");
                    prn.AddStyleSheet(sPathDirectory + "\\css\\bootstrap-theme.min.css");
                    prn.AddStyleSheet(sPathDirectory + "\\css\\bootstrap.min.css");
                    prn.AddStyleSheet(sPathDirectory + "\\css\\UserPourPdf.css");

                    // apply an external JavaScript file (optional)
                    //prn.AddScript("C:\\docs\\js\\test.js");
                }
                else
                {
                    sInitLog = "Fichier exe Prince n'esiste pas en : " + sPathExe;
                    SingleLogFileAsXml.Instance().AjouteLog("Init", sInitLog);
                }
            }
            catch (Exception ex) {
                sInitLog = ex.Message;
                SingleLogFileAsXml.Instance().AjouteLog("Init", "SingleConvertToPDF : Exception : " + ex.Message);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initialize document.
        /// </summary>
        /// <param name="conf">Config object that defines which pages and images to use.</param>
        /// <param name="princePath">Path to the PrinceXML binary.</param>
        public PrinceDocument(PDF.Config conf, string princePath)
        {
            prince = new Prince(princePath);

            // We are dealing with Html
            prince.SetHTML(true);

            // Add default stylesheets
            prince.AddStyleSheet(AppDomain.CurrentDomain.BaseDirectory + "\\assets\\mediawiki.css");
            prince.AddStyleSheet(AppDomain.CurrentDomain.BaseDirectory + "\\assets\\book.css");
            prince.AddStyleSheet(AppDomain.CurrentDomain.BaseDirectory + "\\assets\\ruby.css");

            // Add additional stylesheets
            foreach (Uri path in conf.StyleSheets)
            {
                prince.AddStyleSheet(path.AbsolutePath);
            }

            this.conf = conf;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Write the Pdf file
        /// </summary>
        /// <param name="outName">Name to use for Pdf file</param>
        public void Create(string outName)
        {
            Debug.Assert(!string.IsNullOrEmpty(Xhtml), "xhtml not set");

            if (Common.UnixVersionCheck())
            {
                if (!File.Exists("/usr/bin/Prince"))
                {
                    throw new MISSINGPRINCE();
                }
                Common.RunCommand("Prince ", Xhtml + " " + Css + " -o " + outName, 1);
                return;
            }
            RegistryKey regPrinceKey;

            try
            {
                regPrinceKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\Prince_is1");
                if (regPrinceKey == null)
                {
                    regPrinceKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\{3AC28E9C-8F06-4E2C-ADDA-726E2230A03A}");
                }
                if (regPrinceKey == null)
                {
                    regPrinceKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\Prince_is1");
                }
                if (regPrinceKey == null)
                {
                    regPrinceKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\{3AC28E9C-8F06-4E2C-ADDA-726E2230A03A}");
                }
            }
            catch (Exception)
            {
                regPrinceKey = null;
            }
            if (regPrinceKey != null)
            {
                object princePath     = regPrinceKey.GetValue("InstallLocation");
                string princeFullName = Common.PathCombine(princePath as string, "Engine/Bin/Prince.exe");
                var    myPrince       = new Prince(princeFullName);
                var    mc             = new MergeCss();
                if (File.Exists(Css))
                {
                    myPrince.AddStyleSheet(mc.Make(Css, "Temp1.css"));
                }
                myPrince.Convert(Xhtml, outName);
            }
            else
            {
                throw new MISSINGPRINCE();
            }
        }
Ejemplo n.º 4
0
        private static bool ExportPrince(PublicationInformation projInfo, string xhtmlFileName, bool isUnixOS,
                                         RegistryKey regPrinceKey, string defaultCSS)
        {
            if (!isUnixOS)
            {
                Object princePath = regPrinceKey.GetValue("InstallLocation");
                _fullPrincePath = Common.PathCombine((string)princePath, "Engine/bin/prince.exe");
                var myPrince = new Prince(_fullPrincePath);
                if (projInfo.IsReversalExist && projInfo.IsLexiconSectionExist)
                {
                    string[] xhtmlFiles   = new string[2];
                    var      reversalFile = Path.GetDirectoryName(_processedXhtml);
                    xhtmlFiles[0] = _processedXhtml;
                    xhtmlFiles[1] = Common.PathCombine(reversalFile, "FlexRev.xhtml");
                    myPrince.AddStyleSheet(defaultCSS);
                    myPrince.ConvertMultiple(xhtmlFiles, xhtmlFileName + ".pdf");
                }
                else
                {
                    if (File.Exists(_fullPrincePath))
                    {
                        myPrince.AddStyleSheet(defaultCSS);
                        myPrince.Convert(_processedXhtml, xhtmlFileName + ".pdf");
                    }
                }
            }
            else
            {
                if (isUnixOS)
                {
                    if (!Directory.Exists("/usr/lib/prince/bin"))
                    {
                        return(false);
                    }
                }
                Environment.CurrentDirectory = Path.GetDirectoryName(projInfo.DefaultXhtmlFileWithPath);
                Directory.SetCurrentDirectory(Path.GetDirectoryName(projInfo.DefaultXhtmlFileWithPath));

                string inputArguments;
                if (projInfo.IsReversalExist)
                {
                    var reversalFile     = Path.GetDirectoryName(_processedXhtml);
                    var reversalFilename = Common.PathCombine(reversalFile, "FlexRev.xhtml");
                    inputArguments = "-s " + defaultCSS + " " + _processedXhtml + " " + reversalFilename + " " + " -o " + xhtmlFileName + ".pdf";
                }
                else
                {
                    inputArguments = "-s " + defaultCSS + " " + _processedXhtml + " -o " + xhtmlFileName + ".pdf";
                }

                using (Process p1 = new Process())
                {
                    p1.StartInfo.FileName = "prince";
                    if (File.Exists(_processedXhtml))
                    {
                        p1.StartInfo.Arguments = inputArguments;
                    }
                    p1.StartInfo.RedirectStandardOutput = true;
                    p1.StartInfo.RedirectStandardError  = p1.StartInfo.RedirectStandardOutput;
                    p1.StartInfo.UseShellExecute        = !p1.StartInfo.RedirectStandardOutput;
                    p1.Start();
                    p1.WaitForExit();
                }
            }
            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Write the Pdf file
        /// </summary>
        /// <param name="outName">Name to use for Pdf file</param>
        public void Create(string outName)
        {
            Debug.Assert(!string.IsNullOrEmpty(Xhtml), "xhtml not set");

            if (Common.UnixVersionCheck())
            {
                if (!File.Exists("/usr/bin/Prince"))
                    throw new MISSINGPRINCE();
                Common.RunCommand("Prince ", Xhtml + " " + Css + " -o " + outName, 1);
                return;
            }
            RegistryKey regPrinceKey;
            try
            {
                regPrinceKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\Prince_is1");
                if (regPrinceKey == null)
                    regPrinceKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\{3AC28E9C-8F06-4E2C-ADDA-726E2230A03A}");
                if (regPrinceKey == null)
                    regPrinceKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\Prince_is1");
                if (regPrinceKey == null)
                    regPrinceKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\{3AC28E9C-8F06-4E2C-ADDA-726E2230A03A}");

            }
            catch (Exception)
            {
                regPrinceKey = null;
            }
            if (regPrinceKey != null)
            {
                object princePath = regPrinceKey.GetValue("InstallLocation");
                string princeFullName = Common.PathCombine(princePath as string, "Engine/Bin/Prince.exe");
                var myPrince = new Prince(princeFullName);
                var mc = new MergeCss();
                if (File.Exists(Css))
                    myPrince.AddStyleSheet(mc.Make(Css, "Temp1.css"));
                myPrince.Convert(Xhtml, outName);
            }
            else
            {
                throw new MISSINGPRINCE();
            }
        }
Ejemplo n.º 6
0
        private static bool ExportPrince(PublicationInformation projInfo, string xhtmlFileName, bool isUnixOS,
                                   RegistryKey regPrinceKey, string defaultCSS)
        {
            if (!isUnixOS)
            {
                Object princePath = regPrinceKey.GetValue("InstallLocation");
                _fullPrincePath = Common.PathCombine((string) princePath, "Engine/bin/prince.exe");

                if (File.Exists(_fullPrincePath))
                {
                    var myPrince = new Prince(_fullPrincePath);
                    myPrince.AddStyleSheet(defaultCSS);
                    myPrince.Convert(_processedXhtml, xhtmlFileName + ".pdf");
                }
            }
            else
            {
                if (isUnixOS)
                {
                    if (!Directory.Exists("/usr/lib/prince/bin"))
                    {
                        return false;
                    }
                }
                Environment.CurrentDirectory = Path.GetDirectoryName(projInfo.DefaultXhtmlFileWithPath);
                Directory.SetCurrentDirectory(Path.GetDirectoryName(projInfo.DefaultXhtmlFileWithPath));
                string p1Error = string.Empty;
                string inputArguments = "";
                inputArguments = _processedXhtml + " -o " + xhtmlFileName + ".pdf";
                using (Process p1 = new Process())
                {
                    p1.StartInfo.FileName = "prince";
                    if (File.Exists(_processedXhtml))
                    {
                        p1.StartInfo.Arguments = inputArguments;
                    }
                    p1.StartInfo.RedirectStandardOutput = true;
                    p1.StartInfo.RedirectStandardError = p1.StartInfo.RedirectStandardOutput;
                    p1.StartInfo.UseShellExecute = !p1.StartInfo.RedirectStandardOutput;
                    p1.Start();
                    p1.WaitForExit();
                    p1Error = p1.StandardError.ReadToEnd();
                }
            }
            return true;
        }