iTextSharp + FileStream = Corrupt PDF file

前端 未结 5 1706
有刺的猬
有刺的猬 2020-12-05 16:04

I am trying to create a pdf file with iTextSharp. My attempt writes the content of the pdf to a MemoryStream so I can write the result both into file and a database BLOB. Th

5条回答
  •  温柔的废话
    2020-12-05 16:46

    I had similar issue. My file gets downloaded but the file size will be 13Bytes. I resolved the issue when I used binary writer to write my file

    byte[] bytes = new byte[0];
    //pass in your API response into the bytes initialized
    
    using (StreamWriter streamWriter = new StreamWriter(FilePath, true))
    {
       BinaryWriter binaryWriter = new BinaryWriter(streamWriter.BaseStream);
       binaryWriter.Write(bytes);
    }
    

提交回复
热议问题