Reputation: 15121
I have a requirement where I need to upload some PDF files from an ASP.NET page. This upload action is done by admin user. These files which are selected using individual fileupload controls should merge and get stored in a SQL Server database. Now the normal user should be able to login to an asp.net page where a link should be displayed to open the file stored in the database and view it using adobe reader.
I see the following challenges:
If I select multiple pdf files, how can I store it in the database in a merged format.
Since the file is stored in the database how can I create a link and point the file stored in the database
First of all, is this doable. I know about storing a file in a database, but how can I merge and store a file in a database?
Upvotes: 1
Views: 1751
Reputation:
iTextSharp is a free PDF library that will allow you to merge the PDFs. Here's a code sample doing just that.
Retrieving the file from SQL server is a simple matter. This discussion thread has an example.
Code from thread:
byte[] data = TheMethodToReadTheFieldFromDB();
using (Stream st = new MemoryStream(data))
{
long dataLengthToRead = st.Length;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + theFileName + "\"");
while (dataLengthToRead > 0 && Response.IsClientConnected)
{
Int32 lengthRead = st.Read(buffer, 0, blockSize);
Response.OutputStream.Write(buffer, 0, lengthRead);
Response.Flush();
dataLengthToRead = dataLengthToRead - lengthRead;
}
Response.Flush();
Response.Close();
}
Response.End();
Upvotes: 3
Reputation: 42023
Merging PDF files is a task that needs to be handled by a PDF manipulation/image processing library. For example Atalasoft DotImage. There may be free alternatives too.
To link to a file in the database, you'd need to create a handler or page (e.g. .ashx HttpHandler) which, given an id in a query string for example, will transmit the page to the client. You'll need to set the correct MIME type on the response.
Upvotes: 1