diff --git a/src/Docfx.App/PdfBuilder.cs b/src/Docfx.App/PdfBuilder.cs index ff2a7a3a676..437e821c0c3 100644 --- a/src/Docfx.App/PdfBuilder.cs +++ b/src/Docfx.App/PdfBuilder.cs @@ -186,8 +186,8 @@ IResult TocPage(string url) Task PrintHeaderFooter(Outline toc, int pageNumber, int totalPages) { - var headerTemplate = ExpandTemplate(toc.pdfHeaderTemplate, pageNumber, totalPages); - var footerTemplate = ExpandTemplate(toc.pdfFooterTemplate ?? DefaultFooterTemplate, pageNumber, totalPages); + var headerTemplate = ExpandTemplate(GetHeaderFooter(toc.pdfHeaderTemplate), pageNumber, totalPages); + var footerTemplate = ExpandTemplate(GetHeaderFooter(toc.pdfFooterTemplate) ?? DefaultFooterTemplate, pageNumber, totalPages); return headerFooterCache.GetOrAdd((headerTemplate, footerTemplate), _ => PrintHeaderFooterCore()); @@ -222,6 +222,13 @@ static string ExpandTemplate(string? pdfTemplate, int pageNumber, int totalPages .Replace("", $"{totalPages}") .Replace("", $"{totalPages}"); } + + static string? GetHeaderFooter(string? template) + { + return File.Exists(template) + ? File.ReadAllText(template) + : template; + } } }