We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Syncfusion Essential pdf hangs up in multithreading environment during pdf files creation.

Thread ID:

Created:

Updated:

Platform:

Replies:

125256 Aug 3,2016 09:06 AM UTC Aug 4,2016 08:41 AM UTC ASP.NET Web Forms (Classic) 1
loading
Tags: PDF
Andrey
Asked On August 3, 2016 09:06 AM UTC

Hi, my company  is going to use your Syncfusion Essential pdf . Out task is to process a big amount of pdf forms in multithreading environmnet, but I came across a weird bug related to generating pdf files in multiple threads. Please see attachment console applicatation where I am trying to save 100 pdf files in one theead and 100 pdf files in multiple threads. One thead method works fine, but multiplethreading method hangs up without any exceptions. As far as I know to be able to work in multithreading environmnet I have to disable PdfDocument.EnableCache = false. I did it but it didn't help. Please provide me instructions how to work with pdf files via Syncfusion Essential pdf  in multithreading environment

Here is my source code:

 private static string PdfOutputPath = @"d:\Temp\1";

        private static string SourcePdfDocumentPath =
            Path.Combine(
                System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                @"Content\TestPdf.pdf");

        static void Main(string[] args)
        {
            PdfDocument.EnableCache = false; // to prevent exceptions im multithreading environment;

            OutputPdfFlattenOneThread(100);
            OutputPdfFlattenMultithreading(100);

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }

        private static void OutputPdfFlattenOneThread(int documentsCount)
        {
            Console.WriteLine("One thread generating pdf files:");
            Console.WriteLine();

            foreach (var index in Enumerable.Range(0, documentsCount))
            {
                PdfDocument outputDocument = new PdfDocument();
                outputDocument.Form.Flatten = true;

                FileStream sourceStream = new FileStream(SourcePdfDocumentPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                PdfLoadedDocument loadedDocument = new PdfLoadedDocument(sourceStream);
                foreach (PdfPageBase page in loadedDocument.Pages)
                {
                    outputDocument.ImportPage(loadedDocument, page);
                }

                outputDocument.Save(Path.Combine(PdfOutputPath, "oneThread", string.Concat(index, ".pdf")));

                loadedDocument.Close(true);
                outputDocument.Close(true);

                Console.WriteLine("{0}.pdf document has been created", index);
            }

            Console.WriteLine();
            Console.WriteLine();

        }

        private static void OutputPdfFlattenMultithreading(int documentsCount)
        {
            Console.WriteLine("Multiple threads generating pdf files:");

            Enumerable.Range(0, documentsCount).AsParallel().ForAll(index =>
            {
                Console.WriteLine("{0}.pdf document is creating", index);

                PdfDocument outputDocument = new PdfDocument();
                outputDocument.Form.Flatten = true;

                FileStream sourceStream = new FileStream(SourcePdfDocumentPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                PdfLoadedDocument loadedDocument = new PdfLoadedDocument(sourceStream);

                foreach (PdfPageBase page in loadedDocument.Pages)
                {
                    outputDocument.ImportPage(loadedDocument, page);
                }

                outputDocument.Save(Path.Combine(PdfOutputPath, "multipleThreads", string.Concat(index, ".pdf")));

                loadedDocument.Close(true);
                outputDocument.Close(true);
                sourceStream.Close();
            });

            Console.WriteLine();
            Console.WriteLine();
        }


Attachment: SyncFusionPdfFormFlattenBug_7779769e.zip

Karthik Krishnaraj [Syncfusion]
Replied On August 4, 2016 08:41 AM UTC

Hi Andrey, 
We were able to reproduce the issue and we have confirmed this as bug and logged a report on this. Also we have created a support incident under your account to track the status of this issue.                                                    
Please log on to our support website to check for further updates. 
Thanks, 
Karthik. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;