1
I am developing an application to join several pdfs in one, I managed to do through two uploads, however, I would like in one upload to be able to select several and unify the pdfs. Could someone help me? Below is the code already made:
<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";
}
}
I don’t get it, you can do it with two, but you can’t do it with N?
– Leandro Angelo
exactly, I can join two pdfs files through 2 uploads. The idea would be in just 1 upload file, I can select several pdfs and unify them in one.
– Rafael Veloso