Click here to Skip to main content
15,897,187 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Issue when creat send email.... Pin
DaveAuld15-Jan-10 4:53
professionalDaveAuld15-Jan-10 4:53 
GeneralRe: Issue when creat send email.... Pin
Golden Jing15-Jan-10 21:14
Golden Jing15-Jan-10 21:14 
GeneralRe: Issue when creat send email.... Pin
DaveAuld16-Jan-10 0:15
professionalDaveAuld16-Jan-10 0:15 
GeneralRe: Issue when creat send email.... Pin
Golden Jing17-Jan-10 15:57
Golden Jing17-Jan-10 15:57 
QuestionMerge two pdf files into one Pin
C#Coudou14-Jan-10 20:52
C#Coudou14-Jan-10 20:52 
AnswerRe: Merge two pdf files into one Pin
dan!sh 14-Jan-10 20:56
professional dan!sh 14-Jan-10 20:56 
AnswerRe: Merge two pdf files into one Pin
Richard MacCutchan14-Jan-10 21:36
mveRichard MacCutchan14-Jan-10 21:36 
AnswerRe: Merge two pdf files into one Pin
Steven J Jowett15-Jan-10 1:38
Steven J Jowett15-Jan-10 1:38 
I am feeling very good today.

Download iText Sharp .NET library[^] to start with.

The you will want this to wrap around it.

Imports iTextSharp.text
Imports iTextSharp.text.pdf

Public Class PDFMerge

#Region "Fields"
    Private _sourcefolder As String
    Private _destinationfile As String
    Private _fileList As IList = New ArrayList()
#End Region

#Region "Properties"
    ''' 
    ''' Gets or Sets the SourceFolder 
    ''' 
    Public Property SourceFolder() As String
        Get
            Return _sourcefolder
        End Get
        Set(ByVal value As String)
            _sourcefolder = value
        End Set
    End Property

    ''' 
    ''' Gets or Sets the DestinationFile 
    ''' 
    Public Property DestinationFile() As String
        Get
            Return _destinationfile
        End Get
        Set(ByVal value As String)
            _destinationfile = value
        End Set
    End Property
#End Region

#Region "Public Methods"

    ''' 
    ''' Add a new file, together with a given docname to the fileList and namelist collection 
    ''' 
    Public Sub AddFile(ByVal pathnname As String)
        _fileList.Add(pathnname)
    End Sub

    ''' 
    ''' Generate the merged PDF 
    ''' 
    Public Sub Execute()
        MergeDocs()
    End Sub

    Public Sub Execute(ByVal Destination As String)
        DestinationFile = Destination
        MergeDocs()
    End Sub

#End Region

#Region "Private Methods"

    ''' 
    ''' Merges the Docs and renders the destinationFile 
    ''' 
    Private Sub MergeDocs()

        'Step 1: Create a Docuement-Object 
        Dim document As New Document()
        Try
            'Step 2: we create a writer that listens to the document 
            Dim writer As PdfWriter = PdfWriter.GetInstance(document, New System.IO.FileStream(DestinationFile, System.IO.FileMode.Create))

            'Step 3: Open the document 
            document.Open()

            Dim cb As PdfContentByte = writer.DirectContent
            Dim page As PdfImportedPage

            Dim n As Integer = 0
            Dim rotation As Integer = 0

            'Loops for each file that has been listed 
            For Each filename As String In _fileList
                'The current file path 
                Dim filePath As String = SourceFolder + filename

                ' we create a reader for the document 
                Dim reader As New PdfReader(filePath)

                'Gets the number of pages to process 
                n = reader.NumberOfPages

                Dim i As Integer = 0
                While i < n
                    i += 1
                    document.SetPageSize(reader.GetPageSizeWithRotation(1))
                    document.NewPage()

                    'Insert to Destination on the first page 
                    If i = 1 Then
                        Dim fileRef As New Chunk(" ")
                        fileRef.SetLocalDestination(filename)
                        document.Add(fileRef)
                    End If

                    page = writer.GetImportedPage(reader, i)
                    rotation = reader.GetPageRotation(i)
                    If rotation = 90 OrElse rotation = 270 Then
                        cb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, _
                        reader.GetPageSizeWithRotation(i).Height)
                    Else
                        cb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, _
                        0)
                    End If
                End While
            Next
        Catch e As Exception
            Throw e
        Finally
            document.Close()
        End Try
    End Sub

#End Region

End Class


Use the Destination property to set the merged PDF location and name
Use the Add method to add the PDF files you want to merge together, in the order you want them merging.
Call the Execute method to perform the merge.

Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.

GeneralRe: Merge two pdf files into one Pin
C#Coudou15-Jan-10 13:51
C#Coudou15-Jan-10 13:51 
QuestionCreating desktop Icon ! Pin
jeshra27914-Jan-10 17:49
jeshra27914-Jan-10 17:49 
AnswerRe: Creating desktop Icon ! Pin
Dave Kreskowiak14-Jan-10 18:14
mveDave Kreskowiak14-Jan-10 18:14 
QuestionHow to Decrypt an MD5'd password using a textbox and a button... Pin
thebiostyle14-Jan-10 11:20
thebiostyle14-Jan-10 11:20 
AnswerRe: How to Decrypt an MD5'd password using a textbox and a button... Pin
EliottA14-Jan-10 11:29
EliottA14-Jan-10 11:29 
AnswerRe: How to Decrypt an MD5'd password using a textbox and a button... Pin
DaveAuld14-Jan-10 11:46
professionalDaveAuld14-Jan-10 11:46 
AnswerRe: How to Decrypt an MD5'd password using a textbox and a button... Pin
Dave Kreskowiak14-Jan-10 13:00
mveDave Kreskowiak14-Jan-10 13:00 
AnswerRe: How to Decrypt an MD5'd password using a textbox and a button... Pin
Luc Pattyn14-Jan-10 13:27
sitebuilderLuc Pattyn14-Jan-10 13:27 
GeneralRe: How to Decrypt an MD5'd password using a textbox and a button... Pin
thebiostyle14-Jan-10 13:57
thebiostyle14-Jan-10 13:57 
GeneralRe: How to Decrypt an MD5'd password using a textbox and a button... Pin
Luc Pattyn14-Jan-10 14:01
sitebuilderLuc Pattyn14-Jan-10 14:01 
GeneralRe: How to Decrypt an MD5'd password using a textbox and a button... Pin
Dave Kreskowiak14-Jan-10 18:09
mveDave Kreskowiak14-Jan-10 18:09 
GeneralRe: How to Decrypt an MD5'd password using a textbox and a button... Pin
Smithers-Jones15-Jan-10 0:40
Smithers-Jones15-Jan-10 0:40 
JokeRe: How to Decrypt an MD5'd password using a textbox and a button... Pin
JHizzle22-Jan-10 3:19
JHizzle22-Jan-10 3:19 
GeneralRe: How to Decrypt an MD5'd password using a textbox and a button... Pin
Jörgen Andersson15-Jan-10 9:47
professionalJörgen Andersson15-Jan-10 9:47 
QuestionVB Script in word 2007 Pin
Niungareamit13-Jan-10 22:10
Niungareamit13-Jan-10 22:10 
AnswerRe: VB Script in word 2007 Pin
Dalek Dave13-Jan-10 22:32
professionalDalek Dave13-Jan-10 22:32 
GeneralRe: VB Script in word 2007 Pin
Niungareamit13-Jan-10 22:35
Niungareamit13-Jan-10 22:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.