Merge PDF - font/ text getting corrupted and jumbled

Hi,

I'm using serverside PDF merging process. When I merged two or more PDF's sometimes, the text in the final merged PDF is getting jumbled / corrupted. I'm sure I'm missing something. Probably missing fonts or so. Please advise.


As shown in the below screenshots - 

Original PDF content - 

Image_5751_1710950993554

Merged PDF content -

Image_3992_1710951546179



Similarly some of the content is totally destroyed 

Original content - 

Image_8826_1710951672944


After merging - 

Image_2804_1710951722739




4 Replies 1 reply marked as answer

SN Sri Nistala March 20, 2024 06:59 PM UTC

I have tested this using .Net framework console app and Aspnetcore Razor pages project. 


Using .Net framework it works perfectly. but the same when I use it in the Aspnet core Razor pages, its failing with all junk characters. I'm attaching the sample solution here.


Is it possible to get this working using Aspnet core Razor pages project? 



Attachment: PdfSampleMerge_4fde742c.zip


JT Jeyalakshmi Thangamarippandian Syncfusion Team March 21, 2024 10:21 AM UTC

Hi Sri,

We were able to reproduce the reported issue with the provided details on our end and currently we are analyzing on this and will update the further details on March 25, 2024.

Regards,

Jeyalakshmi T




JT Jeyalakshmi Thangamarippandian Syncfusion Team March 25, 2024 02:08 PM UTC

Currently we are still analyzing on your requirement, and we will update further details on March 27th, 2024.



JT Jeyalakshmi Thangamarippandian Syncfusion Team March 27, 2024 01:51 PM UTC

On our further analysis of your code, we observed that you closed the loaded document instance before saving the newly merged document. When EnableMemoryOptimization is set to false, you should not close the loaded document instance. This approach is not appropriate. If you intend to close the document before saving it, you can set EnableMemoryOptimization to true.

//Get the folder path into DirectoryInfo

            DirectoryInfo directoryInfo = new DirectoryInfo("./wwwroot/Data");

            //Get the PDF files in folder path into FileInfo

            FileInfo[] files = directoryInfo.GetFiles("*.pdf");

            //Create a new PDF document

            PdfDocument document = new PdfDocument();

            //Set enable memory optimization as true

            //document.EnableMemoryOptimization = true;

            PdfMergeOptions mergeOptions = new PdfMergeOptions();

            //Enable the optimize resources option

            mergeOptions.OptimizeResources = false;

            mergeOptions.ExtendMargin = true;

            foreach (FileInfo file in files)

            {

                //Load the PDF document

                FileStream fileStream = new FileStream(file.FullName, FileMode.Open);

                PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream);

                //Merge PDF file

                PdfDocumentBase.Merge(document,mergeOptions, loadedDocument);

                //Close the existing PDF document

               

            }

            using (var fs = new FileStream("bundle1.pdf", FileMode.OpenOrCreate, FileAccess.Write))

            {

                document.Save(fs);

            }

            loadedDocument.Close(true);


Marked as answer
Loader.
Up arrow icon