title: Return PDF documents
body: <p>I've tried implementing a custom formatter for returning PDF documents from ServiceStack. Without much luck, though. I've looked at the examples and pretty much copied the VCard sample, but replaced it with my code. My formatter looks something like this:</p>
  
  <pre><code>public class PdfFormatter
  {
      private const string PdfFormatContentType = "application/pdf";
  
      public static void Register(IAppHost appHost)
      {
          appHost.ContentTypeFilters.Register(PdfFormatContentType, SerializeToStream, (t, s) =&gt; { throw new NotImplementedException(); });
      }
  
      public static void SerializeToStream(IRequestContext requestcontext, object dto, Stream outputstream)
      {
          ...
      } 
  }
  </code></pre>
  
  <p>I've called Register from my AppHost and the Content Type Filter is added as expected. My problem is that SerializeToStream is only called when accessing the metadata for my methods. When I call the concrete method on servicestack, an HTML response is returned.</p>
  
  <p>The URL called is: <a href="http://mydomain.com/api/pdf/reply/GenerateDocument" rel="nofollow">http://mydomain.com/api/pdf/reply/GenerateDocument</a></p>
  
  <p>The request headers looks like this:</p>
  
  <pre><code>Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
  Accept-Encoding:gzip,deflate,sdch
  Accept-Language:en-US,en;q=0.8,da;q=0.6
  Cache-Control:max-age=0
  Connection:keep-alive
  Host:mydomain.com
  User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
  </code></pre>
  
  <p>The response headers look like this:</p>
  
  <pre><code>Cache-Control:private
  Connection:Close
  Content-Length:46
  Content-Type:application/pdf; charset=utf-8
  Date:Thu, 16 May 2013 19:59:27 GMT
  Server:ASP.NET Development Server/11.0.0.0
  X-AspNet-Version:4.0.30319
  X-Powered-By:ServiceStack/3,945 Win32NT/.NET
  </code></pre>
  
  <p>The response is actually PDF but the debugger doesn't break in SerializeToStream.</p>
  
  <p>Any help would be appreciated.</p>