コード例 #1
0
ファイル: ExportPdf.cs プロジェクト: sillsdev/pathway
        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";
                _pdfSymbols.Load(XmlReader.Create(Common.UsersXsl("PdfSymbols.xsl")));
                PreExportProcess preProcessor = new PreExportProcess(projInfo);
                if (isUnixOS)
                {
                    projInfo.DefaultXhtmlFileWithPath =
                        Common.RemoveDTDForLinuxProcess(projInfo.DefaultXhtmlFileWithPath, "pdfconvert");
                }
                Environment.CurrentDirectory = Path.GetDirectoryName(projInfo.DefaultXhtmlFileWithPath);

                preProcessor.IncludeHyphenWordsOnXhtml(preProcessor.ProcessedXhtml);
                preProcessor.GetTempFolderPath();
                preProcessor.ImagePreprocess(false, delegate(string s, string to) { ImageMods.ResizeImage(s, to, 1, 1); });
                preProcessor.ReplaceSlashToREVERSE_SOLIDUS();
                if (projInfo.SwapHeadword)
                {
                    preProcessor.SwapHeadWordAndReversalForm();
                }
                preProcessor.MovePictureAsLastChild(preProcessor.ProcessedXhtml);
                preProcessor.SetNonBreakInVerseNumber(preProcessor.ProcessedXhtml);
                preProcessor.ReplaceProcessForPrinceOutput(preProcessor.ProcessedXhtml);
                Common.ApplyXsltArgs = new XsltArgumentList();
                Common.ApplyXsltArgs.AddParam("avPath", string.Empty, new Uri(projInfo.ProjectPath).AbsoluteUri);
                Common.ApplyXslt(preProcessor.ProcessedXhtml, _pdfSymbols);
                Common.ApplyXsltArgs = null;
                RenameAudioVisual(projInfo.ProjectPath, Path.GetDirectoryName(preProcessor.ProcessedXhtml));

                preProcessor.MoveCallerToPrevText(preProcessor.ProcessedXhtml);
                string tempFolder = Path.GetDirectoryName(preProcessor.ProcessedXhtml);
                var    mc         = new MergeCss {
                    OutputLocation = tempFolder
                };

                if (projInfo.IsReversalExist && File.Exists(projInfo.DefaultRevCssFileWithPath))
                {
                    Common.CopyContent(projInfo.DefaultCssFileWithPath, projInfo.DefaultRevCssFileWithPath);
                }

                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");
                preProcessor.HandleNewFieldworksChangeInCss(mergedCSS);
                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 (projInfo.IsReversalExist && projInfo.IsLexiconSectionExist)
                {
                    var reversalFile = Path.GetDirectoryName(_processedXhtml);
                    reversalFile = Common.PathCombine(reversalFile, "FlexRev.xhtml");
                    Common.SetDefaultCSS(reversalFile, defaultCSS);
                }

                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
                    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 || Common.Testing;
            }
            //}
            //catch (Exception)
            //{
            //    success = false;
            //}
            return(success);
        }