+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / An Issue with PDF creation

An Issue with PDF creation

4 posts, 0 answered
  1. Gergana
    Gergana avatar
    2 posts
    Registered:
    31 Aug 2015
    27 Oct 2015
    Link to this post

    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

  2. Arnob Makhlaqur
    Arnob Makhlaqur avatar
    41 posts
    Registered:
    29 Sep 2016
    29 Oct 2015
    Link to this post
    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
     
  3. Gergana
    Gergana avatar
    2 posts
    Registered:
    31 Aug 2015
    30 Oct 2015
    Link to this post

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

    And didn't solve the problem.

     

  4. Arnob Makhlaqur
    Arnob Makhlaqur avatar
    41 posts
    Registered:
    29 Sep 2016
    02 Nov 2015
    Link to this post
    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
     
4 posts, 0 answered