Md Akmal

Md Akmal

  • NA
  • 354
  • 19.3k

hot convert byte into pdf file

Oct 31 2019 2:07 PM
Hello
 
i tried to convert byte (which is store in table )into pdf file(download pdf file)
 
here is my code in mvc
 
pdf is genrated but not loaded
 
what is wrong in code
 
 
public FileResult DownloadPDF(string Id)
        {
            AttachFileSC mAttachFileSC = null;
            DataSet mDataSet = null;
            MemoryStream pdfStream = new MemoryStream();
            string FileName = string.Empty;
            try
            {
                mAttachFileSC = new AttachFileSC();
                FileManagerBLL mFileManagerBLL = new FMS.Models.BLL.FileManagerBLL();
                mDataSet = mFileManagerBLL.DownloadPDF(Id, UserObj.UserId);
                foreach (DataRow mDataRow in mDataSet.Tables[0].Rows)
                {
                    mAttachFileSC.FileName = mDataRow["FileName"].ToString();
                    mAttachFileSC.FileSize = mDataRow["FileSize"].ToString();
                    mAttachFileSC.FileExt = mDataRow["FileExt"].ToString();
                    mAttachFileSC.FileByte = (byte[])mDataSet.Tables[0].Rows[0]["FileByte"];
                }
                FileName = (mAttachFileSC.FileName).Replace(mAttachFileSC.FileExt, ".pdf");
                pdfStream.Write(mAttachFileSC.FileByte, 0, mAttachFileSC.FileByte.Length);
                pdfStream.Position = 0;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return File(pdfStream, System.Net.Mime.MediaTypeNames.Application.Octet, FileName);
          

        }

Answers (6)