The article shows how to automatically import on Page_Load HTML content in RadEditor from an external HTML file and export it to PDF with the help of HtmlFormatProvider and PdfFormatProvider providers part of the Progress RadPdfProcessing library.
usingTelerik.Windows.Documents.Flow.Model;publicpartialclassDefault2:System.Web.UI.Page{protectedvoidPage_Load(object sender,EventArgs e){
RadEditor1.Content = File.ReadAllText(Server.MapPath("~/HTML_content_for_RadEditor.html"));string htmlContent = RadEditor1.Content;string path = Server.MapPath("~/Converted_to_PDF_content.pdf");string filename = Path.GetTempFileName();Telerik.Windows.Documents.Flow.FormatProviders.Html.HtmlFormatProvider htmlProvider =newTelerik.Windows.Documents.Flow.FormatProviders.Html.HtmlFormatProvider();// Create a document instance from the content. RadFlowDocument document = htmlProvider.Import(htmlContent);Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider pdfProvider =newTelerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();using(Stream output = File.OpenWrite(path)){// Export the document. The different overloads enables you to export to a byte[] or to a Stream.
pdfProvider.Export(document, output);}}}
VB
Imports Telerik.Windows.Documents.Flow.Model
PublicPartialClass Default2
InheritsSystem.Web.UI.Page
ProtectedSub Page_Load(ByVal sender AsObject,ByVal e As EventArgs)
RadEditor1.Content = File.ReadAllText(Server.MapPath("~/HTML_content_for_RadEditor.html"))Dim htmlContent AsString= RadEditor1.Content
Dim path AsString= Server.MapPath("~/Converted_to_PDF_content.pdf")Dim filename AsString= Path.GetTempFileName()Dim htmlProvider As Telerik.Windows.Documents.Flow.FormatProviders.Html.HtmlFormatProvider =New Telerik.Windows.Documents.Flow.FormatProviders.Html.HtmlFormatProvider()Dim document As RadFlowDocument = htmlProvider.Import(htmlContent)Dim pdfProvider As Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider =New Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider()UsingoutputAsStream= File.OpenWrite(path)
pdfProvider.Export(document,output)EndUsingEndSub