Aspose PDF- Size issue after merge

Hi

we are using the latest aspose PDF with license and we have a scenario like we need to split a PDF in to single page PDF and after that we need to merge them. we got a PDF with more than 300 pages and whose size is 1 MB, after split and merge the merged PDF became 20 MB as each individual PDF size is around 55 KB. we tried many thing like we first saved without any optimization and then open the file and applied optimization but no use .Please see the code below
var optimizationOptions = new Aspose.Pdf.Optimization.OptimizationOptions();
optimizationOptions.RemoveUnusedObjects = true;
optimizationOptions.RemoveUnusedStreams = true;
optimizationOptions.ImageCompressionOptions.CompressImages = true;
optimizationOptions.ImageCompressionOptions.ImageQuality = 60;
optimizationOptions.ImageCompressionOptions.ResizeImages = true;
optimizationOptions.ImageCompressionOptions.MaxResolution = 300;
mergedPDF.OptimizeResources(optimizationOptions);
mergedPDF.Optimize();

@sreenath2020

Can you please share the sample PDF document along with the code snippet that you are using to split and re-join the PDFs? We will test the scenario in our environment and address it accordingly.

Hi,
We cant provide the actual file due to policy issues.But here is a sample pdf which has size of 56 KB and contains 100 pages.But when we split and merge the pdf it produces a pdf of 176 kb.While splitting each page has a size of 3kb each
Attatching the file along with this
A100page47.pdf (55.7 KB)

Here is the code we used to split the pdf into single pages
using (Document pdfDocument = new Document(datadir + “SplitToPages.pdf”))
{

            int pageCount = 1;

            // Loop through all the pages
            foreach (Page pdfPage in pdfDocument.Pages)
            {
                using (Document newDocument = new Document())
                {
                    newDocument.Pages.Add(pdfPage);

                    var optimizeOptions = new Aspose.Pdf.Optimization.OptimizationOptions();
                    // Set CompressImages option
                    optimizeOptions.ImageCompressionOptions.CompressImages = true;
                    // Set ImageQuality option
                    optimizeOptions.ImageCompressionOptions.ImageQuality = 80;
                    // Set ResizeImage option
                    optimizeOptions.ImageCompressionOptions.ResizeImages = true;
                    // Set MaxResolution option
                    optimizeOptions.ImageCompressionOptions.MaxResolution = 300;
                    optimizeOptions.ImageCompressionOptions.Version = Aspose.Pdf.Optimization.ImageCompressionVersion.Fast;

                    newDocument.OptimizeResources(optimizeOptions);
                    newDocument.Save(datadir + "page_" + pageCount + "_out" + ".pdf");
                    Invoice1.Add(datadir + "page_" + pageCount + "_out" + ".pdf");
                    pageCount++;
                }
                
            }

        }

The code to merge the pdf we are not using the aspose component we are using a different component.

@sreenath2020

In a PDF document, the same resources are shared among different pages e.g. fonts, image streams, etc. When you split a PDF file into multiple documents by separating each page, embedded resources also get saved with the new copy of the PDF document. The new size of generated documents from individual pages can be understood by this phenomenon. After the merging process, the size of the final PDF is also expected to be increased due to duplicate resources which can be reduced by the optimization method provided by Aspose.PDF.

Can you please share the final merged PDF as well as information on the utility through which you created it? We will try to optimize it using Aspose.PDF and share our feedback with you accordingly.

@asad.ali

We used the PDF4NET Client to merge and here is the merged file which got created
samplemerge.pdf (175.6 KB)
We are happy to use the merge function with aspose pdf .Can you please provide the code for merging.
Can you please make sure that while merging not much memory is utilized as we got outofmemmory exception while using the aspose for merging.

Thanks and Regards

@sreenath2020

Did you get the exception while working with the same PDF that you have shared? Please check the code snippet to merge PDF files using Aspose.PDF in the API documentation:

Hi @asad.ali,
Should we use the above optimization code as well after we use the above merge code from aspose.Or just the merging code will solve the size issue?

Thanks and Regards,

@asad.ali

We have tried the Aspose Concatenate method to merge the pdf but the results are still the same
The input file we used consits of 101 pages and the size of the file is 56KB
File:A100page47.pdf (55.7 KB)

After Splitting Each page is splitted into size of 3KB Each

This is the files we got after splitting:SplittedPdfs.zip (131.0 KB)

After Merging using AsposePDF Concatenate method the file has a size of 139 KB
MergedPdf.pdf (138.6 KB)
And we optimized this file too then also we got the same file size.

Code For Splitting:
Split.zip (582 Bytes)

Code For Merging:
Merge.zip (538 Bytes)

@sreenath2020

We have noticed a similar issue while testing the case with 22.2 version of the API. Hence, an issue as PDFNET-51422 has been logged in our issue tracking system. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

Do we have any update for the issue?

@sreenath2020

Please note that the ticket has recently been logged in our issue management system and is pending for review. We will investigate and resolve it on a first come first serve basis and let you know as soon as it is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.