Example #1
0
        public bool Export(PublicationInformation projInfo)
        {
            bool success;
            bool isUnixOS = Common.UnixVersionCheck();
            try
            {
                var regPrinceKey = RegPrinceKey;
                if (regPrinceKey != null || isUnixOS)
                {
                    var curdir = Environment.CurrentDirectory;
                    projInfo.OutputExtension = "pdf";
                    PreExportProcess preProcessor = new PreExportProcess(projInfo);
                    if (isUnixOS)
                    {
                        projInfo.DefaultXhtmlFileWithPath =
                            Common.RemoveDTDForLinuxProcess(projInfo.DefaultXhtmlFileWithPath,"pdfconvert");
                    }
                    Environment.CurrentDirectory = Path.GetDirectoryName(projInfo.DefaultXhtmlFileWithPath);
                    preProcessor.GetTempFolderPath();
                    preProcessor.ImagePreprocess(false);
                    preProcessor.ReplaceSlashToREVERSE_SOLIDUS();
                    if (projInfo.SwapHeadword)
                        preProcessor.SwapHeadWordAndReversalForm();
                    preProcessor.MovePictureAsLastChild(preProcessor.ProcessedXhtml);
                    preProcessor.SetNonBreakInVerseNumber(preProcessor.ProcessedXhtml);
                    preProcessor.ReplaceDoubleSlashToLineBreak(preProcessor.ProcessedXhtml);
                    preProcessor.MoveCallerToPrevText(preProcessor.ProcessedXhtml);
                    string tempFolder = Path.GetDirectoryName(preProcessor.ProcessedXhtml);
                    string tempFolderName = Path.GetFileName(tempFolder);
                    var mc = new MergeCss { OutputLocation = tempFolderName };
                    string mergedCSS = mc.Make(projInfo.DefaultCssFileWithPath, "Temp1.css");
                    preProcessor.ReplaceStringInCss(mergedCSS);
                    preProcessor.InsertPropertyInCSS(mergedCSS);
                    preProcessor.RemoveDeclaration(mergedCSS, ".pictureRight > .picture");
                    preProcessor.RemoveDeclaration(mergedCSS, "div.pictureLeft > img.picture");
                    mergedCSS = preProcessor.RemoveTextIndent(mergedCSS);

                    if (isUnixOS)
                    {
                        Common.StreamReplaceInFile(mergedCSS, "Scheherazade Graphite Alpha", "Scheherazade");
                    }

                    Dictionary<string, Dictionary<string, string>> cssClass = new Dictionary<string, Dictionary<string, string>>();
                    CssTree cssTree = new CssTree();
                    cssTree.OutputType = Common.OutputType.PDF;
                    cssClass = cssTree.CreateCssProperty(mergedCSS, true);
                    if (cssClass.ContainsKey("@page") && cssClass["@page"].ContainsKey("-ps-hide-versenumber-one"))
                    {
                        string value = cssClass["@page"]["-ps-hide-versenumber-one"];
                        if (value.ToLower() == "true")
                        {
                            preProcessor.RemoveVerseNumberOne(preProcessor.ProcessedXhtml, mergedCSS);
                        }
                    }
                    if (cssClass.ContainsKey("@page:left-top-left") && cssClass["@page:left-top-left"].ContainsKey("-ps-referenceformat"))
                    {
                        string value = cssClass["@page:left-top-left"]["-ps-referenceformat"];
                        if (value.ToLower().Contains("gen 1"))
                        {
                            ReplaceBookNametoBookCode(preProcessor.ProcessedXhtml);
                        }
                    }

                    string xhtmlFileName = Path.GetFileNameWithoutExtension(projInfo.DefaultXhtmlFileWithPath);
                    string defaultCSS = Path.GetFileName(mergedCSS);
                    Common.SetDefaultCSS(preProcessor.ProcessedXhtml, defaultCSS);
                    _processedXhtml = preProcessor.ProcessedXhtml;
                    if (!ExportPrince(projInfo, xhtmlFileName, isUnixOS, regPrinceKey, defaultCSS)) 
                        return false;

                    Environment.CurrentDirectory = curdir;
                    if (!projInfo.DefaultXhtmlFileWithPath.ToLower().Contains("local"))
                    {
                        //Copyright information added in PDF files
                        #pragma warning disable 168
                        string pdfFileName = Common.InsertCopyrightInPdf(Common.PathCombine(Path.GetDirectoryName(projInfo.DefaultXhtmlFileWithPath), xhtmlFileName + ".pdf"), "Prince XML", projInfo.ProjectInputType);
                        #pragma warning restore 168
                    }
                    else
                    {
                        string pdfFileName = xhtmlFileName + ".pdf";
                        pdfFileName = Common.PathCombine(Path.GetDirectoryName(projInfo.DefaultXhtmlFileWithPath), pdfFileName);
                        
                        if (!Common.Testing && File.Exists(pdfFileName))
                        {
                            // ReSharper disable RedundantAssignment
                            success = true;
                            // ReSharper restore RedundantAssignment
                            Process.Start(pdfFileName);
                        }
                    }
                    success = true;
                }
                else
                {
                    success = false;
                    if (Common.Testing)
                    {
                        success = true;
                    }
                }
            }
            catch (Exception)
            {
                success = false;
            }
            return success;
        }