Exemplo n.º 1
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);
        }