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);
}
{
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);
}
Marvin ReidPosted Mar 21, 2023, 5:08 PM
You can take your byte data and convert it into a PDF using the DocumentConverter class. Here is an example you can build on:
https://www.leadtools.com/help/sdk/tutorials/dotnet-convert-files-with-the-document-converter.html
Mageshwaran RPosted Nov 7, 2019, 8:47 AM
Rupesh KahanePosted Nov 1, 2019, 12:09 AM
Jaimin ShethiyaPosted Nov 1, 2019, 12:00 AM
Can you please check with the below code.
Thanks
Salman BegPosted Oct 31, 2019, 10:16 PM
Rahul PrasadPosted Oct 31, 2019, 8:27 PM