I am developing an application to join several pdfs into one, I managed to do through two uploads, however, I would like in an upload to select multiple and unify the pdfs. can anybody help me? Here is the code already done:
<asp:FileUpload ID="file1" runat="server" AllowMultiple="true"></asp:FileUpload>
<asp:FileUpload ID="file2" runat="server" AllowMultiple="true"></asp:FileUpload>
protected void Merge(object sender, EventArgs e)
{
if (file1.HasFile && file2.HasFile)
{
PdfReader pdfReader1 = new PdfReader(file1.PostedFile.InputStream);
PdfReader pdfReader2 = new PdfReader(file2.PostedFile.InputStream);
List<PdfReader> readerList = new List<PdfReader>();
readerList.Add(pdfReader1);
readerList.Add(pdfReader2);
//Define a new output document and its size, type
Document document = new Document(PageSize.A4, 0, 0, 0, 0);
//Get instance response output stream to write output file.
PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream);
document.Open();
foreach (PdfReader reader in readerList)
{
for (int i = 1; i <= reader.NumberOfPages; i++)
{
PdfImportedPage page = writer.GetImportedPage(reader, i);
document.Add(iTextSharp.text.Image.GetInstance(page));
}
}
document.Close();
Response.AppendHeader("content-disposition", "inline; filename=OutPut.pdf");
Response.ContentType = "application/pdf";
}
}