public string CreatePreview() { Debug.Assert(ParentForm != null); if (inProcess) { return string.Empty; } inProcess = true; var cr = ParentForm.Cursor; ParentForm.Cursor = Cursors.WaitCursor; Debug.Assert(!string.IsNullOrEmpty(Param.Value[Param.CurrentInput]), "The given key was not present in the dictionary."); var xhtml = Param.Value[Param.CurrentInput]; if (string.IsNullOrEmpty(xhtml) || !File.Exists(xhtml)) return string.Empty; string PreviewCSSPath = Param.StylePath(Sheet); var mergedCss = new MergeCss(); string cssCombine = mergedCss.Make(PreviewCSSPath, "Temp1.css"); var returnXhtml = CreatePreviewFile(xhtml, cssCombine, "preview", true); var pdf = new Pdf(returnXhtml, cssCombine); var outName = Common.PathCombine(Param.Value[Param.OutputPath], Path.GetFileNameWithoutExtension(xhtml) + ".pdf"); try { pdf.Create(outName); } catch (Pdf.MISSINGPRINCE) { LocDB.Message("errInstallPrinceXML", "PrinceXML must be downloaded and installed from www.PrinceXML.com", null, LocDB.MessageTypes.Error, LocDB.MessageDefault.First); ParentForm.Cursor = cr; inProcess = false; return string.Empty; } ParentForm.Cursor = cr; inProcess = false; return outName; }
/// <summary> /// Combines all css files into one and adds expected css to beginning /// </summary> /// <param name="outputFullName">Name used to calculate default css name</param> /// <param name="outDir">where results will be stored</param> /// <param name="cssFullName">name and path of css file</param> /// <returns></returns> public string GetFluffedCssFullName(string outputFullName, string outDir, string cssFullName) { var mc = new MergeCss(); string fluffedCssFullName; try { if (!File.Exists(cssFullName)) { var layout = Param.Value[Param.LayoutSelected]; cssFullName = Param.StylePath(Param.StyleFile[layout]); } string myCss = Common.PathCombine(outDir, Path.GetFileName(cssFullName)); if (cssFullName != myCss) File.Copy(cssFullName, myCss, true); var expCss = Path.GetFileNameWithoutExtension(outputFullName) + ".css"; string expCssLine = "@import \"" + expCss + "\";"; Common.FileInsertText(myCss, expCssLine); string outputCSSFileName = "merged" + expCss; var tmpCss = mc.Make(myCss, outputCSSFileName); fluffedCssFullName = Common.PathCombine(outDir, Path.GetFileName(tmpCss)); File.Copy(tmpCss, fluffedCssFullName, true); File.Delete(tmpCss); Common.StreamReplaceInFile(fluffedCssFullName, "string(verse) ' = '", "string(verse) ' '"); //TD-1945 } catch (Exception) { fluffedCssFullName = string.Empty; } return fluffedCssFullName; }
private static MergeCss _mc; // When mc is disposed it also deletes the merged file //public Exportepub(string epub3Path) //{ // //this.epub3Path = epub3Path; //} private static string MergeAndFilterCss(PreExportProcess preProcessor, string tempFolder, string cssFullPath) { var tempFolderName = Path.GetFileName(tempFolder); _mc = new MergeCss { OutputLocation = tempFolderName }; var mergedCss = _mc.Make(cssFullPath, "book.css"); preProcessor.RemoveDeclaration(mergedCss, "@top-"); preProcessor.RemoveDeclaration(mergedCss, "@bottom-"); preProcessor.RemoveDeclaration(mergedCss, "@footnote"); preProcessor.RemoveDeclaration(mergedCss, "@page"); preProcessor.RemoveStringInCss(mergedCss, "string-set:"); preProcessor.RemoveStringInCss(mergedCss, "-moz-column-"); preProcessor.RemoveStringInCss(mergedCss, "column-fill:"); preProcessor.RemoveStringInCss(mergedCss, "-ps-outline-"); preProcessor.RemoveStringInCss(mergedCss, "float:"); preProcessor.RemoveStringInCss(mergedCss, "-ps-fixed-line-height:"); preProcessor.RemoveStringInCss(mergedCss, "content: leader("); preProcessor.ReplaceStringInCss(mergedCss); preProcessor.SetDropCapInCSS(mergedCss); preProcessor.InsertCoverPageImageStyleInCSS(mergedCss); preProcessor.InsertSectionHeadID(); return mergedCss; }
/// <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(); } }
public void OutputLocationTest() { MergeCss target = new MergeCss(); // TODO: Initialize to an appropriate value string expected = string.Empty; // TODO: Initialize to an appropriate value string actual; target.OutputLocation = expected; actual = target.OutputLocation; Assert.AreEqual(expected, actual, "OutputLocationTest failed"); }
public void MakeTest4() { MergeCss target = new MergeCss { OutputLocation = "Preprocess" }; var workDir = Common.PathCombine(Path.GetTempPath(), "Preprocess"); if (Directory.Exists(workDir)) Directory.Delete(workDir, true); string css = Common.PathCombine(_inputBasePath, "MergeFile7.css"); // TODO: Initialize to an appropriate value string actual = target.Make(css, "Temp1.css"); string expected = Common.PathCombine(_expectBasePath, "MergeBottomImportFile.css"); // TODO: Initialize to an appropriate value TextFileAssert.AreEqual(expected, actual, "Make Funtion test failed"); }
public void MakeTest2() { MergeCss target = new MergeCss(); // TODO: Initialize to an appropriate value string css = Common.PathCombine(_inputBasePath, "MergeFile5.css"); // TODO: Initialize to an appropriate value string actual = target.Make(css, "Temp1.css"); string expected = Common.PathCombine(_expectBasePath, "MergeMissingFile.css"); // TODO: Initialize to an appropriate value TextFileAssert.AreEqual(expected, actual, "Make Funtion missing file test failed"); }
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; }