Skip to content

Latest commit

 

History

History
68 lines (52 loc) · 1.86 KB

add-html-to-pdf-document.md

File metadata and controls

68 lines (52 loc) · 1.86 KB
title description type page_title slug position tags ticketid res_type
Add Html to a PDF document
Describes how you can add a HTML content to a RadFlowDocument and convert it to PDF
how-to
Add Html to a PDF document
add-html-to-pdf-document
1545269
kb

Environment

Product Version 2021.3.1109 Author
Product RadPdfProcessing Dimitar Karamfilov

Description

You have an HTML that needs to be converted to PDF or added to an existing document.

Solution

You can use the WordsProcessing library to convert the content to a RadFlowDocument and then insert it to the existing document along with other content.

C#

{{region kb-convert-html-to-pdf}}

HtmlFormatProvider provider = new HtmlFormatProvider();
var htmlConteont = provider.Import(File.ReadAllText(@"..\..\HtmlPage1.html"));

RadFlowDocument document = new RadFlowDocument();
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);

editor.InsertText("Sample Content");
editor.InsertParagraph();

var options = new InsertDocumentOptions();
options.ConflictingStylesResolutionMode = ConflictingStylesResolutionMode.UseTargetStyle;
editor.InsertDocument(htmlConteont, options);
 
editor.InsertText("Content After");

var pdfFProvider = new PdfFormatProvider();
var pdfBytes = pdfFProvider.Export(document);
File.WriteAllBytes("result.pdf", pdfBytes); 

{{endregion}}

See Also

  • [RadFlowDocumentEditor]({%slug radwordsprocessing-editing-radflowdocumenteditor%})
  • [Using HtmlFormatProvider]({%slug radwordsprocessing-formats-and-conversion-html-htmlformatprovider%})
  • [Using PdfFormatProvider]({%slug radwordsprocessing-formats-and-conversion-pdf-pdfformatprovider%})