title: vb.net code that will export / convert multiple selected files in to one pdf file
body: <p>I am trying to create a code that will convert multiple selected files to one pdf file . Currently the code exports the selected files in to a zip file. But I want to open all the selected files in one single pdf file .</p>
  
  <p>For your assistance I am providing the code that exports all files into one zip file.</p>
  
  <p>In the code below there are two table mentioned. one is document and another is vacancyapplication. In the document table all the files are stored  guid is the unique id in the document table.</p>
  
  <pre><code>Imports System
  Imports System.Web
  Imports System.IO
  Imports System.Collections.Generic
  Imports Ionic.Zip
  Imports System.Linq
  Imports NLog
  
  Public Class download_bulk_cv : Implements IHttpHandler
  
  Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
      Dim _logger As Logger = LogManager.GetCurrentClassLogger()
      Dim vacancy = New Vacancy(context.Request("v"))
      context.Response.Clear()
      context.Response.ContentType ="application/zip"
      context.Response.AddHeader("content-disposition", "attachment; filename=" &amp; vacancy.Title.Replace(" ", "_") &amp; "_" &amp; Now.ToString("yyyy-MMM-dd-HHmmss") &amp; ".zip")
  
      Dim files = New List(Of String)()
      For Each docPath As String In From row As DataRow In DB.GetData("select guid, originalfilename from document where id in (select candidatecvid from vacancyapplication where id in (" &amp; context.Request("a").ToString() &amp; "))").Rows Let guid = row.Item("guid").ToString() Select HttpContext.Current.Server.MapPath("~/documents") &amp; "\" &amp; Left(guid, 1) &amp; "\" &amp; Right(guid, 1) &amp; "\" &amp; guid &amp; "." &amp; System.IO.Path.GetExtension(row.Item("originalfilename")).ToLower().Substring(1)
          If File.Exists(docPath) Then
              files.Add(docPath)
              '_logger.Info(docPath)
          End If
      Next
      Using zip As New ZipFile()
          zip.AddFiles(files.ToArray(), "CVs") '.AddFile(docPath, "CVs")
          zip.AddEntry("info.txt", files.Count.ToString.ToString() &amp; "CVs archived", Encoding.Default)
          zip.Save(context.Response.OutputStream)
  
      End Using
  
      context.Response.End()
  
  End Sub
  End Class
  </code></pre>
  
  <hr>
  
  <p>i have written the following code to merge the pdf documents  but its not working</p>
  
  <hr>
  
  <p>Edited code</p>
  
  <hr>
  
  <pre><code>Public Class preview_bulk_cv : Implements IHttpHandler
  ''Implements IDisposable
  
  
  Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
      Dim _logger As Logger = LogManager.GetCurrentClassLogger()
      Dim vacancy = New Vacancy(context.Request("v"))
  
      Dim files = New List(Of String)()
      Dim sourceFiles = New List(Of String)()
      Dim directorypath As String = HttpContext.Current.Server.MapPath("~/documents") &amp; "\download\" &amp; Now.ToString("yyyy-MMM-dd") &amp; "\" &amp; vacancy.Title.Replace(" ", "_") &amp; "\"
  
      Dim pdf_document As iTextSharp.text.Document = Nothing
      Dim pdf_copier As iTextSharp.text.pdf.PdfCopy = Nothing
  
      context.Response.Clear()
      context.Response.ContentType = "application/pdf"
      context.Response.AddHeader("content-disposition", "attachment; filename=" &amp; vacancy.Title.Replace(" ", "_") &amp; "_" &amp; Now.ToString("yyyy-MMM-dd-HHmmss") &amp; ".pdf")
  
      For Each docPath As String In From row As DataRow In DB.GetData("select guid, originalfilename from document where id in (select candidatecvid from vacancyapplication where id in (" &amp; context.Request("a").ToString() &amp; "))").Rows Let guid = row.Item("guid").ToString() Select HttpContext.Current.Server.MapPath("~/documents") &amp; "\" &amp; Left(guid, 1) &amp; "\" &amp; Right(guid, 1) &amp; "\" &amp; guid &amp; "." &amp; System.IO.Path.GetExtension(row.Item("originalfilename")).ToLower().Substring(1)
  
          Dim epath As String = HttpContext.Current.Server.MapPath("~/documents") &amp; "\download\" &amp; Now.ToString("yyyy-MMM-dd") &amp; "\" &amp; vacancy.Title.Replace(" ", "_") &amp; "\" &amp; Now.ToString("yyyy-MMM-dd-HHmmss") &amp; ".pdf"
          Converter.ConvertDocument(docPath, epath)
  
          If File.Exists(epath) Then
              sourceFiles.Add(epath)
          End If
  
          If File.Exists(docPath) Then
              files.Add(docPath)
              '_logger.Info(docPath)
          End If
      Next
  
      Dim all_source_files As String() = sourceFiles.ToArray()
  
  
      Dim docs As PdfDocument() = New PdfDocument(all_source_files.Length - 1) {}
  
      For i As Integer = 0 To all_source_files.Length - 1
  
          Dim reader As New PdfReader(all_source_files(i))
  
       ' Using reader As New iTextSharp.text.pdf.PdfReader(all_source_files(i))
  
          Dim finalpdf As String = HttpContext.Current.Server.MapPath("~/documents") &amp; "\download\" &amp; Now.ToString("yyyy-MMM-dd") &amp; "\" &amp; vacancy.Title.Replace(" ", "_") &amp; "\finalcv.pdf"
  
          If i = 0 Then
              pdf_document = New iTextSharp.text.Document(reader.GetPageSizeWithRotation(1))
              pdf_copier = New iTextSharp.text.pdf.PdfCopy(pdf_document, New IO.FileStream(finalpdf, IO.FileMode.Create))
              pdf_document.Open()
          End If
  
          For page_num As Integer = 1 To reader.NumberOfPages
              pdf_copier.AddPage(pdf_copier.GetImportedPage(reader, page_num))
          Next
  
        ' End Using
  
      Next
  
      pdf_copier.Close()
  
  
  End Sub
  
  Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
      Get
          Return False
      End Get
  End Property
  
  End Class     
  </code></pre>
  
  <hr>
  
  <p>I am new with vb.net . I appreciate your kind assistance. </p>