C#
how we can create a pdf file from byte array?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jan 8, 2013, 5:33 AM EST
File.WriteAllBytes(@"C:\testpdf.pdf", byteArray);
Dont forget to add reference /name space System.IO
If you are using asp.net
then you can also try this to ask user to download instead of writing to a specific folder
private void ShowDocument(string fileName, byte[] fileContent)
{
//Split the string by character . to get file extension type
string[] stringParts = fileName.Split(new char[] { '.' });
string strType = stringParts[1];
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
//Set the content type as file extension type
Response.ContentType = strType;
//Write the file content
this.Response.BinaryWrite(fileContent);
this.Response.End();
}
Check my article for more http://www.c-sharpcorner.com/UploadFile/1a81c5/convert-file-to-byte-array-and-byte-array-to-files/
chellappan pandiarajan79 reputationPosted Jan 8, 2013, 5:37 AM EST
System.IO.File.WriteAllBytes("Sample.pdf", bytes);
Thanks,
Pandian