Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2. ' Creamos una lista de archivos para concatenar
  3. Dim Lista As New List(Of String)
  4. ' Identificamos los documentos que queremos unir
  5. Dim sFile1 As String = “C:\Users\Lap\Documents\Visual Studio 2015\Projects\PDF\Cotizacion.pdf”
  6. Dim sFile2 As String = “C:\Users\Lap\Documents\Visual Studio 2015\Projects\PDF\Cotizacion.pdf”
  7. ' Los añadimos a la lista
  8. Lista.Add(sFile1)
  9. Lista.Add(sFile2)
  10. ' Nombre del documento resultante
  11. Dim sFileJoin As String = “C:\Users\Lap\Documents\Visual Studio 2015\Projects\PDF\\DocumentoJoin.pdf”
  12. Dim Doc As New Document()
  13.  
  14. Try
  15. Dim fs As New FileStream(sFileJoin, FileMode.Create, FileAccess.Write, FileShare.None)
  16. Dim copy As New PdfCopy(Doc, fs)
  17. Doc.Open()
  18. Dim Rd As PdfReader
  19. Dim n As Integer 'Número de páginas de cada pdf
  20.  
  21. For Each file In Lista
  22. Rd = New PdfReader(file)
  23. n = Rd.NumberOfPages
  24. Dim page As Integer = 0
  25. Do While page < n
  26. page += 1
  27. copy.AddPage(copy.GetImportedPage(Rd, page))
  28. Loop
  29. copy.FreeReader(Rd)
  30. Rd.Close()
  31. Next
  32.  
  33. Catch ex As Exception
  34. MsgBox(ex.Message, vbExclamation, “Error uniendo los pdf”)
  35. Finally
  36. ' Cerramos el documento
  37. Doc.Close()
  38. End Try
  39. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement