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 |
Product Version | 2021.3.1109 | Author |
Product | RadPdfProcessing | Dimitar Karamfilov |
You have an HTML that needs to be converted to PDF or added to an existing document.
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.
{{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}}
- [RadFlowDocumentEditor]({%slug radwordsprocessing-editing-radflowdocumenteditor%})
- [Using HtmlFormatProvider]({%slug radwordsprocessing-formats-and-conversion-html-htmlformatprovider%})
- [Using PdfFormatProvider]({%slug radwordsprocessing-formats-and-conversion-pdf-pdfformatprovider%})