private SmeDoc CreateSmeDoc(string html, string pt, SpDocumentModel docInfo)
        {
            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(html);

            var res = DocConverter.DoDocConvert(htmlDoc, pt);

            if (res.Meta.IsConsolidatedEuLegislation && res.HasRecitals() == false)
            {
                var preambleWithRecitals = this.dbHelper.GetRecitalsPreambleForConsVersion(docInfo.DocLanguageId);
                if (String.IsNullOrEmpty(preambleWithRecitals) == false)
                {
                    var preambleWithRecitalsHtml = AkomaNtosoPreProcessor.ConvertToHtml(preambleWithRecitals, new AkomaNtosoPreProcessorConfig());
                    InsertRecitalsAtPreambleEnd(htmlDoc, preambleWithRecitalsHtml);
                    res = DocConverter.DoDocConvert(htmlDoc, pt);
                }
            }


            this.FillMetaFromDocRecord(res, docInfo);
            var filePath = @".\data\smedata.css";

            if (!string.IsNullOrEmpty(this.pathsProvider.BasePath))
            {
                filePath = System.IO.Path.Combine(this.pathsProvider.BasePath, filePath);
            }
            res.Head += System.IO.File.ReadAllText(filePath);
            return(res);
        }
        private SmeDoc CreateSmeDoc(SpDocumentModel docInfo, string searchText)
        {
            if (docInfo.DocLanguageId != -1)
            {
                var docText = this.dbHelper.GetDocumentTextByDocLangId(docInfo.DocLanguageId);
                if (this.IsBlob(docText, out string fileName))
                {
                    var smeDoc = new SmeDoc();
                    smeDoc.Meta            = DocConverter.GetSmeDocMeta(docText);
                    smeDoc.Meta.ShortTitle = smeDoc.Meta.ShortTitle; //must change when ShortTitle column is available in database
                    this.FillMetaFromDocRecord(smeDoc, docInfo);
                    smeDoc.Meta.IsBlob = true;

                    var filePath = $@"{this.pathsProvider.PdfPath}\{smeDoc.Meta.Idenitifier}\{fileName}";
                    if (System.IO.File.Exists(filePath))
                    {
                        smeDoc.Items = new List <SmeDocItem>();
                        var fileExt = System.IO.Path.GetExtension(filePath).ToLower();
                        if (fileExt == ".html")
                        {
                            var docContent = System.IO.File.ReadAllText(filePath);
                            smeDoc.Meta.IsBlob = false;
                            smeDoc.Items.Add(new SmeDocItem
                            {
                                Text = docContent,
                                Type = SmeDocItemType.Text
                            });
                        }
                        else
                        {
                            smeDoc.Items.Add(new SmeDocItem
                            {
                                Text = fileName,
                                Type = SmeDocItemType.Text
                            });
                        }
                    }
                    return(smeDoc);
                }
                else
                {
                    var html = AkomaNtosoPreProcessor.ConvertToHtml(docText, new AkomaNtosoPreProcessorConfig());
                    html = this.ReplaceImgUrls(html);

                    if (!string.IsNullOrEmpty(searchText))
                    {
                        html = this.ColorizeSearch(searchText, html, docInfo.LangId);
                    }

                    html = DocumentLinkRewrite.ReplaceNationalLegislation(html);

                    var res = this.CreateSmeDoc(html, docText, docInfo);
                    return(res);
                }
            }
            else
            {
                return(null);
            }
        }
 protected void DoConvert(object pathString)
 {
     PathString ps = (PathString)pathString;
     DocConverter converter = new DocConverter();
     converter.init(ps.sourceFile, ps.swfFile);
     bool isSuccess = false;
     int transferTimes = 5;
     do
     {
         isSuccess = converter.convertFunc();
     } while (transferTimes > 0 && !isSuccess);
     if (isSuccess)
     {
         string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MyDatabaseConnectionString"].ConnectionString;
         SqlConnection conn = new SqlConnection(connectionString);
         string sql = @"UPDATE Matter SET 附件swf相对路径='" + converter.swfShowName + "' WHERE 事项ID=" + ps.matterId;
         SqlCommand cmd = new SqlCommand(sql, conn);
         try
         {
             conn.Open();
             cmd.ExecuteNonQuery();
         }
         catch(Exception error)
         {
             Console.WriteLine(error.Message);
         }
         finally
         {
             conn.Close();
         }
     }
 }
Esempio n. 4
0
        public override async Task SaveToDocumentationFolderAsync()
        {
            var converter = new DocConverter();
            var blocks    = await converter.ConvertAsync(_document).ConfigureAwait(false);

            if (!blocks.Any())
            {
                return;
            }

            var builder = new StringBuilder();

            using (var writer = new StringWriter(builder))
                foreach (var block in blocks)
                {
                    await writer.WriteLineAsync(block.ToAsciiDoc()).ConfigureAwait(false);
                }

            var destination = CreateDocumentationLocation();

            // Now add Asciidoc headers, rearrange sections, etc.
            var document = AsciiDocNet.Document.Parse(builder.ToString());
            var visitor  = new GeneratedAsciidocVisitor(FileLocation, destination, _projects);

            document = visitor.Convert(document);

            // Write out document to file
            using (var writer = new StreamWriter(destination.FullName)) document.Accept(new AsciiDocVisitor(writer));
        }
Esempio n. 5
0
 // Turns the provided ECMA XML node into HTML and appends it to the current node on the rendered HTML
 public static void AppendEcmaNode(this IEditorWindow editorWindow, XElement ecmaXml)
 {
     if (editorWindow.CurrentObject != null)
     {
         var html = DocConverter.ToHtml(ecmaXml, "", editorWindow.CurrentObject.DocumentDirectory);
         editorWindow.RunJS("insertHtmlAfterCurrentNode", WebViewExtensions.EscapeHtml(html));
     }
 }
Esempio n. 6
0
 // Validates that the elements named in 'args' in WebKit can be converted
 // from HTML back into ECMA XML.
 //
 // Returns null on success, otherwise a string with the error details
 //
 public string ValidateElements(IWebView web, params string [] args)
 {
     foreach (var arg in args)
     {
         try {
             var str = web.Fetch(arg);
             DocConverter.ToXml(str, canonical: true);
             web.RunJS("postOk", arg);
         } catch (UnsupportedElementException e) {
             web.RunJS("postError", arg);
             return("Parsing error: " + e.Message);
         } catch (StackOverflowException e) {
             return("Exception " + e.GetType().ToString());
         }
     }
     return(null);
 }
Esempio n. 7
0
        //
        // Updates the target XElement with the edited text.
        // The first pass uses the provided xpath expression to remove all the nodes that match
        // this expression from the target (this cleans the nodes that we are about to replace)
        // then the named htmlElement is used to lookup the contents on WebKit and the results
        // are converted back to XML which is stashed in the target specified by xpath.
        //
        // Returns true on success
        public bool UpdateNode(IWebView webView, XElement target, string xpath, string htmlElement, out string error)
        {
            error = null;
            var node = target.XPathSelectElement(xpath);

            node.RemoveNodes();

            try {
                var str = webView.Fetch(htmlElement);
                foreach (var ret in DocConverter.ToXml(str, canonical: true))
                {
                    node.Add(ret);
                }
            } catch (UnsupportedElementException e) {
                error = e.Message;
                return(false);
            }
            return(true);
        }
        //Runs when item added to list
        private void HtmlToPdfItemAdded(SPRemoteEventProperties properties)
        {
            using (ClientContext clientContext =
                       TokenHelper.CreateRemoteEventReceiverClientContext(properties))
            {
                if (clientContext != null)
                {
                    try
                    {
                        clientContext.Load(clientContext.Web, w => w.Url);
                        List     listHtmlToPdf = clientContext.Web.Lists.GetByTitle(ListHtmlToPdf);
                        ListItem listItem      = listHtmlToPdf.GetItemById(properties.ItemEventProperties.ListItemId);
                        clientContext.Load(listItem);
                        clientContext.ExecuteQuery();
                        try
                        {
                            var pdfDoc = DocConverter.ConvertToPdfWithTags(listItem["HtmlToConvert"].ToString(), listItem["Title"] + "", listItem["ConversionOptions"] + "");

                            AddDocToLibrary(clientContext, pdfDoc, listItem["DocLibraryName"].ToString(),
                                            listItem["FolderName"].ToString(), listItem["DocFileName"].ToString(),
                                            listItem["DocMetaData"] + "");
                            listItem.DeleteObject();
                            clientContext.ExecuteQuery();
                        }
                        catch (Exception ex)
                        {
                            listItem["ErrorMessage"] = ex.ToString();
                            listItem.Update();
                            clientContext.ExecuteQuery();
                        }
                    }
                    catch (Exception oops)
                    {
                        System.Diagnostics.Trace.WriteLine(oops.Message);
                    }
                }
            }
        }
        private void btnConvertToPdf_Click(object sender, EventArgs e)
        {
            ofdAbrirArquivo.Multiselect = false;
            ofdAbrirArquivo.Filter      = string.Empty;

            DocConverter oDC = new DocConverter();

            if (string.IsNullOrEmpty(tbConvertPdf.Text))
            {
                if (ofdAbrirArquivo.ShowDialog() == DialogResult.OK)
                {
                    var result = oDC.ConvertToPDF(ofdAbrirArquivo.FileName, GetNewFileName(ofdAbrirArquivo.FileName, FileNameOptionEnum.Convert));

                    MessageBox.Show(result.DocConverterStatus.ToString());
                }
            }
            else
            {
                var result = oDC.ConvertToPDF(tbConvertPdf.Text, $"convert_{tbConvertPdf.Text}.pdf");

                MessageBox.Show(result.DocConverterStatus.ToString());
            }

            oDC = null;

            //var byteArrayFile = Teste(ofdAbrirArquivo.FileName);
            //MemoryStream msFile = new MemoryStream(byteArrayFile);

            //var result2 = oDC.ConvertToPDF(msFile, ToPDFFunction.FromTXT, out MemoryStream msResultFile);
            //MessageBox.Show(result.DocConverterStatus.ToString());

            //if (result.DocConverterStatus != DCDK.Results.DocConverterStatus.ConversionFailed)
            //{
            //  File.WriteAllBytes(GetFilePath(ofdAbrirArquivo) + "\\test_convert.docx", msResultFile.ToArray());
            //}
        }
Esempio n. 10
0
 public string GetHtmlForNode(XElement element, string xpath)
 {
     return(DocConverter.ToHtml(element.XPathSelectElement(xpath), Name.ToString(), DocumentDirectory));
 }
Esempio n. 11
0
 public string ToHtml(XElement root)
 {
     return(DocConverter.ToHtml(root, "inmemory", DocumentDirectory));
 }
Esempio n. 12
0
    static void Process(XDocument d, string path)
    {
        var elements = d.XPathSelectElements(path);

        foreach (var element in elements)
        {
            var str = element.ToString();
            //Console.WriteLine (str);
            var html = DocConverter.ToHtml(element, currentFile, Path.GetDirectoryName(path));
            var ret  = DocConverter.ToXml(html);

            var sb = new StringBuilder();
            foreach (var c in element.Nodes())
            {
                sb.Append(c.ToString());
            }
            var expected = sb.ToString();
            //estr = estr.Replace (" />", "/>");
            sb.Clear();
            foreach (var c in ret)
            {
                try {
                    if (c is XComment)
                    {
                        sb.Append((c as XComment).Value);
                    }
                    else
                    {
                        sb.Append(c.ToString());
                    }
                } catch (ArgumentException e) {
                    // An XML comment cannot end with "-" looks like a bug
                }
            }
            var result = sb.ToString();

            if (expected != result)
            {
                var diff      = new XmlDiff(XmlDiffOptions.IgnoreWhitespace);
                var xexpected = new XmlTextReader(new StringReader("<group>" + expected + "</group>"));
                var xresult   = new XmlTextReader(new StringReader("<group>" + result + "</group>"));

                var equal = diff.Compare(xexpected, xresult);                  //, new XmlTextWriter (Console.Out));


                if (!equal && expected != result)
                {
                    bool found = false;
                    for (int i = 0; i < expected.Length && i < result.Length; i++)
                    {
                        if (expected [i] != result [i])
                        {
                            Report(expected, result, i);

                            // We redo the steps above, purely as it is easier to debug what happened right after
                            // the error is reported.
                            html  = DocConverter.ToHtml(element, currentFile, Path.GetDirectoryName(path));
                            ret   = DocConverter.ToXml(html);
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        Report(expected, result, Math.Min(expected.Length, result.Length));
                    }
                }
            }
        }
    }