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 -
Merged PDF content -
Similarly some of the content is totally destroyed
Original content -
After merging -
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?
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
Currently we are still analyzing on your requirement, and we will update further details on March 27th, 2024.
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); |