0

I am using visual studio 2012 c# asp.net, and I am looking for a way to make the user merge PDF or image files through a web application, I created a code below to upload multiple files through web application, and I need to know if its possible to use my code with iText(Sharp) ? or it only works with exe applications

Web.aspx:

<form id="form1" runat="server"  enctype="multipart/form-data">
      <div>
            <asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true" />
            <asp:Button ID="btnUpload" Text="Upload" runat="server" OnClick ="UploadMultipleFiles" accept ="image/gif, image/jpeg" />
            <hr />
            <asp:Label ID="lblSuccess" runat="server" ForeColor ="Green" />
      </div>
</form>

Web.aspx.cs:

protected void UploadMultipleFiles(object sender, EventArgs e)
{
   foreach (HttpPostedFile postedFile in FileUpload1.PostedFiles)
   {

      string fileName = Path.GetFileName(postedFile.FileName);
      postedFile.SaveAs(Server.MapPath("~/Uploads/") + fileName);
   }

   lblSuccess.Text = string.Format("{0} files have been uploaded  successfully.", FileUpload1.PostedFiles.Count);
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
user3891365
  • 71
  • 1
  • 4
  • 13

1 Answers1

0

The below iTextSharp codes merges mutlitple pdf files into a single file and Refer the so question for more info

public static void CombineMultiplePDFs(string[] fileNames, string outFile)
{
// step 1: creation of a document-object
Document document = new Document();

// step 2: we create a writer that listens to the document
PdfCopy writer = new PdfCopy(document, new FileStream(outFile, FileMode.Create));
if (writer == null)
{
    return;
}

// step 3: we open the document
document.Open();

foreach (string fileName in fileNames)
{
    // we create a reader for a certain document
    PdfReader reader = new PdfReader(fileName);
    reader.ConsolidateNamedDestinations();

    // step 4: we add content
    for (int i = 1; i <= reader.NumberOfPages; i++)
    {                
        PdfImportedPage page = writer.GetImportedPage(reader, i);
        writer.AddPage(page);
    }

    PRAcroForm form = reader.AcroForm;
    if (form != null)
    {
        writer.CopyAcroForm(reader);
    }

    reader.Close();
}

// step 5: we close the document and writer
writer.Close();
document.Close();

}

giri-webdev
  • 525
  • 10
  • 20