title: Error reading request body that contains a pdf in an Azure Function
body: <p>I had an azure function with blob trigger that I wanted to use in a Logic app. Then I realized that only HTTP trigger azure functions are supported in Logic apps. </p>
  
  <p>I migrated the code that was working fine in the blob triggered function to a new http triggered azure function. I replaced the stream received in the blob triggered function for the request body in the http triggered one, but I wasn't able to open the pdf created with that stream. </p>
  
  <p><strong>Blob trigger Function</strong></p>
  
  <pre><code>public static void Run([BlobTrigger("attachments/{name}", Connection = "")]Stream blobPdf, string name, ILogger log)
  {
      // Create MemoryStream
      var streamPdf = new MemoryStream();
      CopyStream(blobPdf, streamPdf);
      // Create PDF from MemoryStream
      var pdf = PdfReader.Open(streamPdf);
  }
  </code></pre>
  
  <p><strong>HTTP trigger Function</strong></p>
  
  <pre><code>public static async Task&lt;IActionResult&gt; Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log)
  {
          // Create MemoryStream
          var streamPdf = new MemoryStream();
          CopyStream(req.Body, streamPdf);
          // Create PDF from MemoryStream
          var pdf = PdfReader.Open(streamPdf);
  }
  </code></pre>
  
  <p>The error pops when it tries to open the pdf in last line.
  There's 2 errors depending on the pdf file. The first one is:</p>
  
  <pre><code>System.Private.CoreLib: Exception while executing function: ExtractTextFromPDF. PdfSharp: Invalid PDF file: no trailer found.
  </code></pre>
  
  <p>The second one is:</p>
  
  <pre><code>System.Private.CoreLib: Exception while executing function: ExtractTextFromPDF. PdfSharp: Unexpected token 'n' in PDF stream. The file may be corrupted. If you think this is a bug in PDFsharp, please send us your PDF file.
  </code></pre>