Add Html to a PDF document
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.
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);