Ejemplo n.º 1
0
        private static void HandleHeaderBodyFooter(string path, string htmlContent, string idFooter, string idHeader = null)
        {
            _pathTempSaveFile = path;
            var htmlDocumentHelper = new HtmlDocumentHelper(htmlContent);

            //TODO: do not handle for Header.
            _headerContent = "Thao Header";

            if (!string.IsNullOrEmpty(_url))
            {
                htmlDocumentHelper.MergeUrlOnImage(_url);
            }


            if (!string.IsNullOrEmpty(idFooter))
            {
                _footerContent = htmlDocumentHelper.GetContentById(idFooter);
            }

            _bodyContent = htmlDocumentHelper.RemoveContentById(idFooter);
        }
Ejemplo n.º 2
0
        private static void _handleHeaderBodyFooter(string path, string htmlContent, string htmlFooter, string htmlHeader, string pagesShowHeader = null, string pagesShowFooter = null)
        {
            _pathTempSaveFile = path;
            var htmlDocumentHelper = new HtmlDocumentHelper(htmlContent);

            #region header
            if (!string.IsNullOrEmpty(htmlHeader) && !string.IsNullOrEmpty(htmlHeader.Trim()))
            {
                _headerContent = @"<!DOCTYPE html><html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
                <head>
                    <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>      
                    <style>
                    thead{display: table-header-group;}
                    tfoot {display: table-row-group;}
                    tr {page-break-inside: avoid;}
                    </style>
                    <script>
                        function subst() {
                            var vars={};
                            var x=document.location.search.substring(1).split('&');
                            for (var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
                            var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
                            for (var i in x) {
                                var y = document.getElementsByClassName(x[i]);
                                for (var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
                                ";
                if (!string.IsNullOrEmpty(pagesShowHeader))
                {
                    if (pagesShowHeader == "first")
                    {
                        _headerContent += @"if(vars['page'] != 1) { 
                                                    document.getElementById('header').style.display = 'none';
                                                }";
                    }
                    else
                    {
                        if (pagesShowHeader == "last")
                        {
                            _headerContent += @"if(vars['page'] != vars['topage']) { 
                                                    document.getElementById('header').style.display = 'none';
                                                }";
                        }
                        else
                        {
                            var arr = pagesShowHeader.Split(',');
                            if (arr.Length > 0)
                            {
                                for (var i = 0; i < arr.Length; i++)
                                {
                                    _headerContent += @"if(vars['page'] != " + arr[i] + @") { 
                                                    document.getElementById('header').style.display = 'none';
                                                }";
                                }
                            }
                        }
                    }
                }
                _headerContent += @"}
                        }
                        </script>
                    </head>
                    <body onload='subst()' style='overflow:hidden;padding:10px 0;'><div id='header'>" + htmlHeader + "</div></body></html>";
            }
            #endregion header
            #region footer
            if (!string.IsNullOrEmpty(htmlFooter) && !string.IsNullOrEmpty(htmlFooter.Trim()))
            {
                _footerContent = @"<!DOCTYPE html><html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
                                             <head>
                                            <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>                                           
                                            <script>
                                                function subst() {
                                                    var vars={};
                                                    var x=window.location.search.substring(1).split('&');
                                                    for (var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
                                                    var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
                                                    for (var i in x) {
                                                        var y = document.getElementsByClassName(x[i]);
                                                        for (var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
                                                        ";
                if (!string.IsNullOrEmpty(pagesShowFooter))
                {
                    if (pagesShowFooter == "first")
                    {
                        _footerContent += @"if(vars['page'] != 1) { 
                                                                                            document.getElementById('footer').style.display = 'none';
                                                                                        }";
                    }
                    else
                    {
                        if (pagesShowFooter == "last")
                        {
                            _footerContent += @"if(vars['page'] != vars['topage']) { 
                                                                                            document.getElementById('footer').style.display = 'none';
                                                                                        }";
                        }
                        else
                        {
                            var arr = pagesShowFooter.Split(',');
                            if (arr.Length > 0)
                            {
                                for (var i = 0; i < arr.Length; i++)
                                {
                                    _footerContent += @"if(vars['page'] != " + arr[i] + @") { 
                                                                                            document.getElementById('footer').style.display = 'none';
                                                                                        }";
                                }
                            }
                        }
                    }
                }

                _footerContent += @"}
                                                }
                                            </script>
                                             </head>
                                            <body onload='subst()'><div >" + htmlFooter + "</div></body></html>";
                // _footerContent = _footerContentFormat;
            }
            #endregion footer
            #region content
            if (!string.IsNullOrEmpty(htmlContent) && !string.IsNullOrEmpty(htmlContent.Trim()))
            {
                _bodyContent = @"<!DOCTYPE html><html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
                                             <head>
                                            <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>                                           
                                            <script>
                                            function subst() {
                                                var vars={};
                                                var x=window.location.search.substring(1).split('&');
                                                for (var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
                                                var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
                                                for (var i in x) {
                                                    var y = document.getElementsByClassName(x[i]);
                                                    for (var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
                                                }
                                            }
                                            </script>
                                             </head>
                                             <body onload='subst()'><div id='content'>" + htmlContent + "</div></body></html>";
            }
            #endregion content
        }