An Issue with PDF creation

Posted by Community Admin on 03-Aug-2018 12:47

An Issue with PDF creation

All Replies

Posted by Community Admin on 27-Oct-2015 00:00

Hello, we have a website where we have document upload doc/jpeg/pdf. We can successfully upload it to our DB and then we can view them in the Admin panel. We do however need to create a document download from the binary data that is in the Database. We are using MS SQL and the column containing the data is of "image" type. We use a store procedure to get the information from the data field into a byte array and for all the files everything is working fine except for the PDFs. We are using MVC and C#.  Can you give a tip how to save the file?

So far we have tried in the controller:

 return File(fileData.Data, System.Net.Mime.MediaTypeNames.Application.Pdf, fileData.Title);

 

And the fileData.Data is the byte array.

 

Thank you

Posted by Community Admin on 29-Oct-2015 00:00

Hi Gergana,

"file.Data.Title" most probably have only the title but not the file extension which should be ".pdf". So the code might be as follows:

return File(fileData.Data, System.Net.Mime.MediaTypeNames.Application.Pdf, fileData.Title +".pdf");


Following are the sample codes for an Sitefinity MVC Widget to download the PDF file (only one / first document) from the Document Library which is stored in the database:

Controller: 
public ActionResult DownloadPDF()
    var libraryManager = new LibrariesManager();
    var doc = libraryManager.GetDocuments().FirstOrDefault();
    var strm = libraryManager.Download(doc);
    byte[] byteArray = ConvertToBytes(strm);
     
    return File(byteArray, System.Net.Mime.MediaTypeNames.Application.Pdf, doc.Title +".pdf");
public static byte[] ConvertToBytes(Stream stream)
    using (MemoryStream ms = new MemoryStream())
    
        stream.CopyTo(ms);
        return ms.ToArray();
    


View:
@Html.ActionLink("Download PDF", "DownloadPDF", "MyWidget1", new action = "" )


Regards,
Arnob Makhlaqur
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 30-Oct-2015 00:00

It did have the extension for the pdf in the title - the value is "test.pdf".

And didn't solve the problem.

 

Posted by Community Admin on 02-Nov-2015 00:00

Hi Gergana,

An update has been provided to your support ticket, please check and provide more details to that support ticket (code for the controller and view and also model if related, also if you could send the pdf file you have uploaded and the corrupted file after downloaded) and once the case is resolved then share it with the community. 

Thanks.

Regards,
Arnob Makhlaqur
Telerik

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed