This is a migrated thread and some comments may be shown as answers.

RadEditor ExportToPdf in HttpHandler

2 Answers 105 Views
Editor
This is a migrated thread and some comments may be shown as answers.
ITLackey
Top achievements
Rank 1
ITLackey asked on 27 Apr 2012, 09:05 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Rumen
Telerik team
answered on 30 Apr 2012, 10:20 AM
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.
0
ITLackey
Top achievements
Rank 1
answered on 30 Apr 2012, 09:45 PM
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!
Tags
Editor
Asked by
ITLackey
Top achievements
Rank 1
Answers by
Rumen
Telerik team
ITLackey
Top achievements
Rank 1
Share this question
or