Free Support Forum - aspose.com

Issue with Merging PDFs

Hello,

We have Aspose Total License and we’re trying to merge 8 PDFs of sizes from 12 MB to 115 MBs. It is a console application. Here is the code.

Imports System.IO
Imports Aspose.Pdf
Imports Aspose.Pdf.Facades
Imports Aspose.Pdf.Operator
Imports Aspose.Pdf.Text

Module Module1
Public Const AsposeTotalLicense As String = “Aspose.Total.lic”
Sub Main()

    Dim folderpath As String
    Dim Path As String
    Dim fileStreams As New List(Of IO.Stream)
    Dim outStream As New IO.MemoryStream
    Dim tempInStream As FileStream
    Dim templateStream As New IO.MemoryStream
    folderpath = System.IO.Path.GetFullPath("..\..\") & "Files\"
    Dim _savePath As String = folderpath & "MergeResult_" + (DateTime.UtcNow).ToString("MMddyyhhmmss") + ".pdf"

    SetAsposeLicenses(folderpath)

    Dim filePaths As New List(Of String)

    Path = folderpath + "Schematics Final Design Review Doc_rev A.pdf"

    filePaths.Add(Path)

    tempInStream = New IO.FileStream(Path, IO.FileMode.Open, IO.FileAccess.Read)
    fileStreams.Add(tempInStream)

    Path = folderpath + "S-SPO-0104_CDRL_19-15_Integrated_Schematic_Drawing_Package.pdf"
    filePaths.Add(Path)
    tempInStream = New IO.FileStream(Path, IO.FileMode.Open, IO.FileAccess.Read)
    fileStreams.Add(tempInStream)

    Path = folderpath + "S-SPO-0284_CDRL_19-15_Integrated_Schematic_Drawing_Package_Rev_A5.pdf"
    filePaths.Add(Path)
    tempInStream = New IO.FileStream(Path, IO.FileMode.Open, IO.FileAccess.Read)
    fileStreams.Add(tempInStream)

    Path = folderpath + "TC3 REV A3.pdf"
    filePaths.Add(Path)
    tempInStream = New IO.FileStream(Path, IO.FileMode.Open, IO.FileAccess.Read)
    fileStreams.Add(tempInStream)

    Path = folderpath + "TC3 Rev A4.pdf"
    filePaths.Add(Path)
    tempInStream = New IO.FileStream(Path, IO.FileMode.Open, IO.FileAccess.Read)
    fileStreams.Add(tempInStream)

    Path = folderpath + "TC3 Rev A5.pdf"
    filePaths.Add(Path)
    tempInStream = New IO.FileStream(Path, IO.FileMode.Open, IO.FileAccess.Read)
    fileStreams.Add(tempInStream)

    Path = folderpath + "TCT3_RevA_Draft_14.pdf"
    filePaths.Add(Path)
    tempInStream = New IO.FileStream(Path, IO.FileMode.Open, IO.FileAccess.Read)
    fileStreams.Add(tempInStream)



    Try
        PDFConcat(filePaths, _savePath)
    Catch ex As Exception
    End Try

    'Save Physical File Path
    System.IO.File.WriteAllBytes(_savePath, outStream.ToArray)

End Sub

Public Sub PDFConcat(ByRef streams() As System.IO.Stream, ByRef outstream As System.IO.Stream)
    Dim pdfEditor As New Aspose.Pdf.Facades.PdfFileEditor
    pdfEditor.AllowConcatenateExceptions = True
    pdfEditor.Concatenate(streams, outstream)
End Sub

Public Sub PDFConcat(ByVal files As List(Of String), ByVal outputFile As String)
    Dim pdfEditor As New Aspose.Pdf.Facades.PdfFileEditor
    pdfEditor.Concatenate(files.ToArray(), outputFile)
End Sub

Public Sub SetAsposeLicenses(licensePath As String)
    Try
        Dim totalFilePath As String = FindAsposeLicense(licensePath, AsposeTotalLicense)

        ' Set the pdf license
        Dim pdfLicense As Aspose.Pdf.License = New Aspose.Pdf.License()
        pdfLicense.SetLicense(totalFilePath)
    Catch ex As Exception
        Throw ex
    End Try
End Sub
Private Function FindAsposeLicense(licensePath As String, fileName As String)
    Dim filePath As String = Path.Combine(licensePath, fileName)
    If File.Exists(filePath) Then
        Return filePath
    End If

    Throw New FileNotFoundException(String.Format("Aspose license file '{0}' was not found.", filePath))

End Function

End Module

The problem is it keeps running forever (i7 8th Gen + 8 gb + SSD and ran for some 21 mins). PDF that needed merging sized some 560MBs. Please let me know if there is some workaround for me.

Regards,

@NanduNairSigma,

Thanks for contacting support.

Can you please share source files to further investigate this issue so that we may help you out.

Hi Adnan,

Here you can download the code. PDF files to be merged are in the solution.

Regards,

@NanduNairSigma

I have observed your issue and like to inform that I have created investigation ticket with ID PDFNET-47885 in our issue tracking system to investigate and resolve this issue as soon possible.

Hello Support Team,

Can we have an update on this?

Thanks

@NanduNairSigma,

I like to inform this issue has been added recently in our issue tracking system and as per our company policy, the first priority for investigation is given to the Paid Support i.e. Enterprise and Priority Support on first come first serve basis. After that the issues from normal support forum are scheduled for investigation on first come first serve basis. I request for your patience and we will share good news with you soon.