コード例 #1
0
        public ReponseConvertToPDF ConvertHtmlToPdf(string sHtml)
        {
            ReponseConvertToPDF reponseConvertToPDF = new ReponseConvertToPDF()
            {
                sMessage = "ConvertHtmlToPdf : " + sInitLog
            };
            string message = "";

            try {
                DateTime dtNow            = DateTime.Now;
                string   Sufixe           = dtNow.DayOfYear.ToString() + "_" + dtNow.Hour.ToString() + "_" + dtNow.Minute.ToString() + "_" + dtNow.Second.ToString();
                string   sFileBase        = sPathDirectory + "\\HtmlToPdf\\base" + Sufixe + ".html";
                string   sFileResultat    = sPathDirectory + "\\HtmlToPdf\\resultat" + Sufixe + ".pdf";
                string   sFileResultatWEB = "HtmlToPdf/resultat" + Sufixe + ".pdf";
                //string sFilecss = sPathDirectory + "\\HtmlToPdf\\CssFile.css";
                File.AppendAllText(sFileBase, sHtml);
                // convert a HTML document into a PDF file
                //prn.AddStyleSheet(sFilecss);
                prn.Convert(sFileBase, sFileResultat);
                reponseConvertToPDF.sFileResultat = sFileResultatWEB;
                SingleLogFileAsXml.Instance().AjouteLog("Pdf", "SingleConvertToPDF. ConvertHtmlToPdf : " + sFileResultatWEB);
            }
            catch (Exception ex) {
                message = ex.Message;
                SingleLogFileAsXml.Instance().AjouteLog("Pdf", "SingleConvertToPDF. ConvertHtmlToPdf : Exception : " + ex.Message);
            }
            return(reponseConvertToPDF);
        }
コード例 #2
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();
            }
        }
コード例 #3
0
ファイル: ExportPdf.cs プロジェクト: sillsdev/pathway
        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);
        }
コード例 #4
0
ファイル: Pdf.cs プロジェクト: neilmayhew/pathway
        /// <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();
            }
        }
コード例 #5
0
ファイル: ExportPdf.cs プロジェクト: neilmayhew/pathway
        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;
        }