RadEditor ExportToPdf in HttpHandler

3 posts, 1 answers
  1. ITLackey
    ITLackey avatar
    9 posts
    Member since:
    Jan 2011

    Posted 27 Apr 2012 Link to this post

    I am trying to use the RadEditor to create a PDF of html that was saved earlier using an HttpHandler. No matter what I try I get a null reference exception.
    Is there any reason this should not work? If not, any ideas what I could be missing?

    Here is the code I am using currently. I just put this together for testing any help is much appreciated!
    public void ProcessRequest(HttpContext context)
          {
              var editor = new Telerik.Web.UI.RadEditor();
     
              editor.ContentFilters = Telerik.Web.UI.EditorFilters.DefaultFilters | Telerik.Web.UI.EditorFilters.PdfExportFilter;
     
              //editor.ExportContent += new Telerik.Web.UI.EditorExportContentEventHandler(editor_ExportContent);
     
              editor.ExportSettings.FileName = "cv";
     
              editor.ExportSettings.Pdf.Title = "TEST";
     
              editor.Content = "<b>HTML</b>";
     
              editor.ExportToPdf();
              
              context.Response.Write("H");
          }

  2. Answer
    Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 30 Apr 2012 Link to this post

    Hi,

    Here is an example:
    <%@ WebHandler Language="C#" Class="PdfExport" %>
        
    using System;
    using System.Web;
    using System.Web.UI;
    using Telerik.Web.UI;
    using System.Web.UI.HtmlControls;
        
    public class PdfExport : IHttpHandler
    {
        
        public string output;
        
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            Page pageHolder = new Page();
            HtmlForm f = new HtmlForm();
            pageHolder.Controls.Add(f);
        
            RadEditor editor = new RadEditor();
            editor.Content = "Hello World!";
            editor.RegisterWithScriptManager = false;
            editor.ExportContent += new EditorExportContentEventHandler(RadEditor_ExportContent);
            f.Controls.Add(editor);
            editor.ExportToPdf();
                
            System.IO.StringWriter writer = new System.IO.StringWriter();
            context.Server.Execute(pageHolder, writer, false);
        
            //here you use pdf output string
            byte[] buffer = System.Text.Encoding.GetEncoding(1252).GetBytes(this.output.ToString());
              
            context.Response.BinaryWrite(buffer);
        }
        
        protected void RadEditor_ExportContent(object sender, Telerik.Web.UI.EditorExportingArgs e)
        {
            //here you set the pdf output string
            this.output = e.ExportOutput;
        }
        
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

    All the best,
    Rumen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. ITLackey
    ITLackey avatar
    9 posts
    Member since:
    Jan 2011

    Posted 30 Apr 2012 Link to this post

    That appears to have done the trick! Now to just figure out where the bad html is coming from that blows everything up...

    Thank you very much for you help, this is exactlly what I was looking for!
Back to Top