We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Split PDF document into pieces and assemble again (from 29mb to 103mb)

Hi,
This question might seem kind of odd, but nevertheless its a functionality I need.

Problem:
I have a document of 999 pages. When I split this document into pieces of 1 - thereby having 999 documents instead of 1. After this I want to merge all of the 999 documents into 1 again (this is the worst case scenario - normally we would only have to merge 50% of the pages back into a single document again, but there can be scenarios where it is needed to merge all pages back into a single document again.

Ive tried a few things, but I end up with a document that goes from 29mb (before split into pieces) to 103mb when put back together. How can I fix this?

Code example:

Dim fil() As Byte = File.ReadAllBytes(“C:\Test\MJ\split1.pdf”)

Dim ms As New MemoryStream(fil)
Dim pdfDoc As New Aspose.Pdf.Document(ms)

'List to keep each document
Dim list As New List(Of Aspose.Pdf.Document)()

'Take one page at a time and add to “list”
For i As Integer = 1 To pdfDoc.Pages.Count
Dim tmpPdfDoc As New Aspose.Pdf.Document()
tmpPdfDoc.Pages.Add(pdfDoc.Pages(i))

list.Add(tmpPdfDoc)
Next

'Take all the individual docs and merge into one
Dim finalDoc As New Aspose.Pdf.Document()

For Each doc As Aspose.Pdf.Document In list
finalDoc.Pages.Add(doc.Pages)
Next

Dim resultStream As New MemoryStream()
finalDoc.Save(resultStream)

File.WriteAllBytes(“C:\Test\MJ\DAB2” + Guid.NewGuid().ToString() + “.pdf”, resultStream.ToArray())

'Same using Concatenate
Dim finalDoc2 As New Aspose.Pdf.Document()

Dim editor As New PdfFileEditor()
editor.Concatenate(list.ToArray(), finalDoc2)

Dim resultStream2 As New MemoryStream()
finalDoc2.Save(resultStream2)

File.WriteAllBytes(“C:\Test\MJ\DAB2” + Guid.NewGuid().ToString() + “.pdf”, resultStream2.ToArray())

'RESULT = BOTH 103mb (from 26mb)

I have added my “split1.pdf” to this post.

Hi Thomas,


Thanks
for using our API’s.
<o:p></o:p>

I
have tested the scenario and I am able to notice the same problem. For the sake
of correction, I have logged this problem as PDFNEWNET-37734 in
our issue tracking system. We will further look into the details of this
problem and will keep you updated on the status of correction. Please be
patient and spare us little time. We are sorry for this inconvenience.