Saving / Retrieving PDF to/from Database into using Entity Framework

Dear All,

I require assistance regarding the following feature for a web application (written in NET4.8 using MVC). A background job downloads a spreadsheet. Next, I am reading the spreadsheet into a data table using Syncfusion.XlsIO. The data table created is used as data source for pdf file. I am using Syncfusion.Pdf and Syncfusion.Pdf.Tables for processing the data table. This has been working well so far and I managed to create a dummy report that is automatically downloaded, if the button on the dummy page is clicked (I am currently creating a working prototype).

Be that as it may, I need to save the report to a database, since it is required that users should be able to download reports from previous months/years etc. (cf. mock-up attached).

I am using EntityFramework. My current approach was to save the report as byte[] using the following model:

    public class Report

    {

        public int Id { get; set; }

        public byte[] Content { get; set; }

        public string FileName { get; set; }

        public DateTime ReportCreatedAt { get; set; }

        public DateTime FileDate { get; set; }

    }

However, I cannot figure out how to add the report created to the model for saving said model to the database for later retrieval. Of course, the model can be changed according to your suggestions. As previously mentioned, I am not sure how to handle the database part for the report (CRUD operations). Please do take a look at the code snippets attached.

Would be grand if you could help me out here. Looking forward to your suggestions. Please do get in touch if you require additional information

Thanks a mil in advance

 C.


Attachment: CodeSnippets_673d485d.zip

4 Replies 1 reply marked as answer

GK Gowthamraj Kumar Syncfusion Team April 26, 2021 11:51 AM UTC

Hi Chris, 
 
Thank you for contacting Syncfusion support. 
 
We are suggested you to refer the UG documentation to import data to the data table from the Excel document and use the data table as data source for PDF tables. Please refer the below link for more information, 
 
Kindly please explain your requirement to us with more details such as expected output, image to analyse in our end. So, that it will be helpful for us to analyze and assist you further on this. 
 
Regards, 
Gowthamraj K 



CR CR April 29, 2021 12:49 PM UTC

Dear Gowthamraj K, 

Thanks a mil for your reply and the link to the SF documentation. Sorry if my initial description was insufficient.

I already managed to apply the steps mentioned in the documentation. My issue is how to persist / save either the entire pdf document, spreadsheet or the data table (containing the data extracted from the spreadsheet) to a database. The reason being that there is a table in one of the views (cf. drawing attached when creating this post). Depending on which button the user clicks in one of the table rows, the report is generated. Since I did not wish to create the report from scratch each time the button is clicked, I thought I best save said reports to a database to retrieve them if required.

 It is true that the sample codes point out how to generate different file formats from different sources, but I am interested in how I could persist those files instead of generating them from scratch.

 I am currently storing the data table extracted from the spreadsheet into a byte array, which is then saved to a data table column. However, I am loosing the column headers when converting the byte array back to a  data table object. I have attached a code snippet outlining my approach.

To rephrase my requirement(s): How could I either save the complete PDF document, the spreadsheet or the data table extracted from said spreadsheet to a database for later retrieval / reuse without having to generate each report from scratch if users wish to download a report.

 Or would you suggest I'd rather not take this approach and generate the report from scratch each time?  Please do net hesitate to get back in touch if you require additional information. Thanks a mil in advance for your support.

 Looking forward to hearing from you.

 Kind regards

 Chris



PH Praveenkumar H Syncfusion Team April 30, 2021 10:51 AM UTC

Hi Chris, 
You can refer the below link to save and download files using Entity framework 
Please let us know if you need further assistance.  
Regards, 
Praveen 


Marked as answer

CR CR April 30, 2021 02:34 PM UTC

Dear Praveen,

Thank you very much for your reply and for providing the link. I took a look at the sample and it comes close to what I came up with in the end. I assumed there was another, a bit more elegant, way to achieve what I previously described, at least I remember having done something similar in the past, but not with pdf files. Since that does not seem to be the case, I stick to what I wrote and using some bits from the code from the sample you kindly provided.  

I'd say that the matter is closed, thanks a mil for helping out.

Kind regards
Chris 

Loader.
Up arrow icon