Пример #1
0
        private string BuildHtml(PdfDocument doc)
        {
            var builder = new StringBuilder();
            var res     = new List <PdfResource>(doc.Resources)
            {
                new PdfResource(PdfSource.FromHtml(TableOverflowHeaderStyle), ResourcePlacement.Head,
                                ResourceType.StyleSheet)
            };

            builder.Append(Format(StartHtml, doc.BaseUrl, RenderResources(res)));

            foreach (var page in doc.Pages)
            {
                // Idea here is to split all pages with a empty page
                if (page != doc.Pages.First())
                {
                    // Split document pages by empty page to identify split
                    // Pages may overflow onto next page
                    builder.Append(PageBreak);
                    builder.Append(Format(AnchorHtml, SplitDocumentUri, '-'));
                    builder.Append(PageBreak);
                }

                var html = ResolveSource(page.Source);
                builder.Append(html);
            }

            builder.Append(CloseHtml);
            return(builder.ToString());
        }
Пример #2
0
        public PdfPage AddPage(PdfSource content, PdfSource header = null, PdfSource footer = null)
        {
            var page = new PdfPage
            {
                Source = content,
                Header = header,
                Footer = footer
            };

            this.Pages.Add(page);
            return(page);
        }
Пример #3
0
        private static string CreateJavascriptResource(PdfSource source)
        {
            switch (source)
            {
            case PdfSourceFile file:
                return(Format(ScriptLinkHtml, file.Path));

            case PdfSourceHtml content:
                return(Format(ScriptHtml, content.Html));

            default:
                return(null);
            }
        }
Пример #4
0
        private static string CreateCssResource(PdfSource source)
        {
            switch (source)
            {
            case PdfSourceFile file:
                return(Format(StyleLinkHtml, file.Path));

            case PdfSourceHtml html:
                return(Format(StyleHtml, html.Html));

            default:
                return(null);
            }
        }
Пример #5
0
        private string ResolveSource(PdfSource source)
        {
            switch (source)
            {
            case PdfSourceHtml html:
                return(html.Html);

            case PdfSourceFile file:
                return(File.ReadAllText(file.Path));

            default:
                return(null);
            }
        }
Пример #6
0
        private void BuildHeaderFooter(StringBuilder builder, PdfSource source, double height,
                                       IReadOnlyCollection <VariableReplace> vars)
        {
            builder.Append(Format(HeaderFootStart, height));
            var html = ResolveSource(source);

            if (!IsNullOrEmpty(html))
            {
                html = ReplaceHtmlWithVariables(html, vars);
                builder.Append(html);
            }

            builder.Append(HeaderFootClose);
        }
Пример #7
0
 public void AddJavascript(PdfSource content, ResourcePlacement placement = ResourcePlacement.EndOfDocument)
 {
     Resources.Add(new PdfResource(content, placement, ResourceType.Javascript));
 }
Пример #8
0
 public void AddCSS(PdfSource content, ResourcePlacement placement = ResourcePlacement.Head)
 {
     Resources.Add(new PdfResource(content, placement, ResourceType.StyleSheet));
 }