title: Creating Multipage TIFF with Magick.NET
body: <p>I'm using Magick.NET and trying to create multipage-TIFF-files. My input is a PDF-file. But writing the result to a MemoryStream or getting it as byte-array results in an error:</p>
  
  <blockquote>
    <p><em>iisexpress.exe: Error flushing data before directory write. `TIFFWriteDirectorySec' @ error/tiff.c/TIFFErrors/551</em></p>
  </blockquote>
  
  <p>But when I write the result to a file on the harddisk there is no error and the file is fine. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>var outputStream = new MemoryStream();
  using (var inputPdf = new MagickImageCollection())
  {
      inputPdf.Read(rawData, settings);
  
      using (var tif = new MagickImageCollection())
      {
          foreach (var pdf in inputPdf)
          {
              pdf.Depth = 8;
              pdf.Format = MagickFormat.Tif;
              tif.Add(pdf);
          }
  
          if (debug)
          {
              // Writing the data to a file is successful!
              tif.Write(pathImage);
          }
  
          // But writing it to a stream results in the error!
          //tif.Write(outputStream);
  
          // Same as getting the data as byte-array!
          var outputData = tif.ToByteArray(MagickFormat.Tif);
          outputStream.Write(outputData, 0, outputData.Length);
      }
  }
  </code></pre>