PDFRasterizer.NET 4.0 is now available. Supports .NET Core. Renders pixel-perfectly.

Write Document to HttpResponse

In PDFKit.NET 5.0 we decided to remove the Document.Write(HttpResponse) because it required the client to add a reference to System.Web even if this overload was not used. For example in a console or WPF application. The compiler needed a reference to System.Web to select the right overload at compile time.

If you are upgrading from 4.0 to 5.0, you may get a compile error because of this. The following extension method solves this:

using TallComponents.PDF;
using System.Web;

namespace YourCompany.PDF
{
  public static class DocumentExtensions
  {
    public static void Write(this Document document, HttpResponse response)
    {
      if (null == response) throw new ArgumentNullException(nameof(response));
      if (!response.IsClientConnected) throw new ArgumentException("Client is not connected.", nameof(response));
         
      response.Clear();
      response.ContentType = "application/pdf";
      response.ContentEncoding = new System.Text.UTF8Encoding();     

      document.Write(response.OutputStream);   

      // Flush requires full trust
      response.Flush(); // make sure all data is sent.
        
      // preventing further writing to the stream should be done by calling HttpApplication.CompleteRequest.
      // do not call response.End(), this will throw a ThreadAbortException.
      // do not call response.Close(), this will break Chrome support
    }
  }   
}

Usage

Document document;
HttpResponse response;

document.Write(response);
Download PDFKit.NET 5.0
We will send you a download link

  • This field is for validation purposes and should be left unchanged.
Why do we ask your email address?
We send tips that speed up your evaluation
We let you know about bug fixes
You can always unsubscribe with one click
We never share your address with a 3rd party
Thank you for your download

We have sent an email with a download link.