The RTF to PDF Converter renders the running header and footer of the RTF document on the PDF pages, with the page number and page count fields they contain and with a different first page when the document has one. The feature is controlled by the RtfToPdfDocumentOptionsUseHeaderFooterFromRtf property, which is true by default.
The RtfToPdfDocumentOptions object is exposed through the RtfToPdfConverterPdfDocumentOptions property.
When UseHeaderFooterFromRtf is true the header and the footer defined in the RTF document appear on the generated pages. When it is false the pages are generated without them.
rtfToPdfConverter.PdfDocumentOptions.UseHeaderFooterFromRtf = true;A header set in RtfToPdfDocumentOptionsPdfHtmlHeader takes the place of the document header and a footer set in RtfToPdfDocumentOptionsPdfHtmlFooter takes the place of the document footer. The document header can be kept while the footer is replaced, or the other way round. The header and footer options are described in the HTML Header and Footer with Page Numbers documentation section.
rtfToPdfConverter.PdfDocumentOptions.PdfHtmlFooter.Html = footerHtml;
rtfToPdfConverter.PdfDocumentOptions.PdfHtmlFooter.HtmlBaseUrl = footerHtmlBaseUrl;
rtfToPdfConverter.PdfDocumentOptions.PdfHtmlFooter.AutoSizeContentHeight = true;// Use EVO PDF Namespace
using EvoPdf.Next;
public byte[] ConvertRtfToPdfWithDocumentHeaders(byte[] inputRtfBytes, bool useHeaderFooterFromRtf,
string headerHtml, string footerHtml, string htmlBaseUrl)
{
// Set the license key received after purchase to use the library in licensed mode; leave it commented for demo mode
// Licensing.LicenseKey = "your-license-key";
// Create a RTF to PDF converter object with default settings
RtfToPdfConverter rtfToPdfConverter = new RtfToPdfConverter();
// Render the header and the footer of the RTF document on the PDF pages, with the page
// number and page count fields they contain and with a different first page when the
// document has one. A HTML header or footer set in the converter takes the place of the
// document one
rtfToPdfConverter.PdfDocumentOptions.UseHeaderFooterFromRtf = useHeaderFooterFromRtf;
if (!string.IsNullOrEmpty(headerHtml))
{
// A HTML header set in the converter takes the place of the document header
rtfToPdfConverter.PdfDocumentOptions.PdfHtmlHeader.Html = headerHtml;
rtfToPdfConverter.PdfDocumentOptions.PdfHtmlHeader.HtmlBaseUrl = htmlBaseUrl;
rtfToPdfConverter.PdfDocumentOptions.PdfHtmlHeader.AutoSizeContentHeight = true;
}
if (!string.IsNullOrEmpty(footerHtml))
{
// A HTML footer set in the converter takes the place of the document footer
rtfToPdfConverter.PdfDocumentOptions.PdfHtmlFooter.Html = footerHtml;
rtfToPdfConverter.PdfDocumentOptions.PdfHtmlFooter.HtmlBaseUrl = htmlBaseUrl;
rtfToPdfConverter.PdfDocumentOptions.PdfHtmlFooter.AutoSizeContentHeight = true;
}
// The buffer to receive the generated PDF document
byte[] outPdfBuffer = rtfToPdfConverter.ConvertToPdf(inputRtfBytes);
return outPdfBuffer;
}