title: Blank PDF being generated from ActiveReports/WebAPI
body: <p>On a project I am working on, I'm building a feature that lets users generate a report - in my case, it will go on an envelope - on-demand from information stored in our database.  The problem I'm trying to solve, is that a blank PDF is being generated.</p>
  
  <p>I've tried some sanity checks.  First I set a breakpoint in Visual Studio and ensured that the models being passed to the report had fixed data; the reports were blank.  Next, I tried including a static label that's not tied to any data, to determine if it's a report data-binding issue - the static label is not appearing in the generated report either.</p>
  
  <p>More stymying, is that I've used similar code in the past without issue.  I have no idea why a blank PDF file would be generated in this case.</p>
  
  <p>I've read the 'Similar Questions' provided by StackOverflow, specifically <a href="https://stackoverflow.com/questions/26581784/how-to-a-pdf-stream-in-web-api-from-exporttostream-of-crystal-report">this question from one year ago</a>, but it had no answers, and thus nothing to learn from it.  I've also tried the requisite Google searches, but found nothing relevant.</p>
  
  <p>The only thing I cannot provide is the actual ActiveReport itself.  I've checked this for Silly Programmer Errors™ like having everything hidden, or transparent labels, or similar silly things.  <em>Unfortunately</em>, I've made no such errors.</p>
  
  <p><strong>Report Code:</strong></p>
  
  <pre><code>public partial class EnvelopeReport : SectionReport
  {
      public EnvelopeReport()
      {
          InitializeComponent();
      }
  
      internal void RunReport(IEnumerable&lt;PrintedAddress&gt; model)
      {
          if (model != null)
          {
              DataSource = model;
          }
  
          Run();
      }
  
      private void OnReportStart(object sender, EventArgs e)
      {
          Document.Printer.PrinterName = string.Empty;
          PageSettings.PaperKind = PaperKind.Number10Envelope;
  
          PageSettings.Margins.Top = 0.25f;
          PageSettings.Margins.Left = 0.5f;
          PageSettings.Margins.Right = 0.5f;
          PageSettings.Margins.Bottom = 0.25f;
      }
  }
  </code></pre>
  
  <p><strong>Web API Controller Code:</strong></p>
  
  <pre><code>    [HttpGet]
      public HttpResponseMessage EnvelopeReport(int addressId, string attentionTo, bool isConfidential)
      {
          Address address = AddressRepository.GetAddress(addressId, true);
          List&lt;PrintedAddress&gt; models = new List&lt;PrintedAddress&gt;
          {
              new PrintedAddress(address, attentionTo, isConfidential)
          };
  
          var report = new EnvelopeReport();
          report.RunReport(models);
  
          var pdfExporter = new ActiveReportsPdfExporter();
          var reportBytes = pdfExporter.ExportPdf(report);
  
          var response = Request.CreateResponse(HttpStatusCode.OK);
          response.Content = new ByteArrayContent(reportBytes, 0, reportBytes.Length);
          response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
          {
              FileName = "Envelope Report.pdf"
          };
  
          return response;
      }
  </code></pre>
  
  <p><strong>PDF Exporter:</strong></p>
  
  <pre><code>public class ActiveReportsPdfExporter
  {
      private readonly PdfExport _pdfExport;
  
      public ActiveReportsPdfExporter()
      {
          _pdfExport = new PdfExport();
      }
  
      public byte[] ExportPdf(SectionReport report)
      {
          using (var stream = new MemoryStream())
          {
              _pdfExport.Export(report.Document, stream);
              return stream.ToArray();
          }
      }
  
      public Stream ExportPdfToStream(SectionReport report)
      {
          var stream = new MemoryStream();
          _pdfExport.Export(report.Document, stream);
          return stream;
      }
  }
  </code></pre>
  
  <p><strong>Client Service (Angular):</strong></p>
  
  <pre><code>(function () {
      angular.module('app').factory('addressSvc', [
          '$http', addressSvc
      ]);
  
      function addressSvc($http) {
          var service = {
              printAddress: function(addressId, attentionTo, someFlag) {
                  var args = {
                      'addressId': thingId,
                      'attentionTo': attentionTo,
                      'isConfidential': isConfidential
                  };
  
                  return $http.get('/api/common/EnvelopeReport', { 'params': args });
              }
          };
  
          return service;
      }
  })();
  </code></pre>
  
  <p><strong>Client Controller (Angular):</strong></p>
  
  <pre><code>(function() {
      angular.module('app').controller('someCtrl', [
          '$window', 'addressSvc', controller
      ]);
  
      function controller($window, addressSvc) {
          var vm = this;
          vm.attentionTo = '';    // Bound to UI.
          vm.isConfidential = ''; // Also bound to UI.
          vm.address = {};        // Unimportant how we get this.
          vm.printAddress = printAddress;
  
          function printAddress() {
              addressSvc.printAddress(vm.address.id, vm.attentionTo, vm.isConfidential)
                  .then(function(result) {
                      var file = new Blob([result], {type: 'application/pdf'});
                      var fileURL = URL.createObjectURL(file);
  
                      if(window.navigator &amp;&amp; window.navigator.msSaveOrOpenBlob) {
                          window.navigator.msSaveOrOpenBlob(file, 'Envelope.pdf');
                      } else {
                          $window.open(fileURL);
                      }
                  });
          }
      }
  )();
  </code></pre>
  
  <p><strong>Question:</strong> Why is this code generating an empty PDF?  I've used the Report/API Controller structure successfully in the past to generate PDFs, but usually in the context of MVC, not Web API.  Another potential point of failure is the client code - I've not previously passed reports between server and client this way.</p>