Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies within .NET ( C#, VB.NET, ASP.NET, .NET Core) application and Java (J2SE and J2EE) application.

Tue Aug 31, 2021 11:33 am

I'm trying parallel processing of unrelated documents to extract text with location, but it seems your library is sharing common resorurce without access control.

My test code is:

Code: Select all
    public static void TestPdf(string fName)
    {
      try
      {
        using (var doc = new PdfDocument(fName))
        {
          var list = new List<(int page, PointF position, string text)>();
          foreach (PdfPageBase page in doc.Pages)
          {
            var collection = page.FindAllText();
            list.AddRange(collection.Finds.Select(find => (find.SearchPageIndex, find.Position, find.SearchText)));
          }
        }
      }
      catch (Exception ex)
      {
        Diag.LogException(ex);
      }
    }

    public static void TestPdfParallel(params string[] files)
    {
      Parallel.ForEach(files, f => TestPdf(f));
    }


if I call TestPdfParallel with bunch of files, I get something like this in exception log:

31.08.21 13:09:44 [275] 04/38 8 System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at sprᯊ.ᜁ()
at sprᯊ.ᜋ()
at sprᯌ.ᜀ(spr⭖ A_0, sprᝨ A_1)
at sprᯌ.ᜀ()
at sprᯌ..ctor(PdfPageBase A_0, sprᯆ A_1, Boolean A_2)
at sprᯌ..ctor(PdfPageBase A_0)
at spr᧱.ᜀ(PdfPageBase A_0)
at Util.PdfUtilSpire.TestPdf(String fName) in C:\APL\Mulema\Util\PdfUtilSpire.cs:line 228
31.08.21 13:09:44 [275] 04/41 9 System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at sprᯊ.ᜁ()
at sprᯊ.ᜋ()
at sprᯌ.ᜀ(spr⭖ A_0, sprᝨ A_1)
at sprᯌ.ᜀ()
at sprᯌ..ctor(PdfPageBase A_0, sprᯆ A_1, Boolean A_2)
at sprᯌ..ctor(PdfPageBase A_0)
at spr᧱.ᜀ(PdfPageBase A_0)
at Util.PdfUtilSpire.TestPdf(String fName) in C:\APL\Mulema\Util\PdfUtilSpire.cs:line 228
31.08.21 13:09:44 [275] 04/40 10 System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at sprᯊ.ᜁ()
at sprᯊ.ᜋ()
at sprᯌ.ᜀ(spr⭖ A_0, sprᝨ A_1)
at sprᯌ.ᜀ()
at sprᯌ..ctor(PdfPageBase A_0, sprᯆ A_1, Boolean A_2)
at sprᯌ..ctor(PdfPageBase A_0)
at spr᧱.ᜀ(PdfPageBase A_0)
at Util.PdfUtilSpire.TestPdf(String fName) in C:\APL\Mulema\Util\PdfUtilSpire.cs:line 228

Is it possible to redesign your algorithms to allow parallel calls of TestPdf in above example?

Sicerely,
Brane

bbrodnik
 
Posts: 14
Joined: Sat Jan 09, 2021 10:38 am

Wed Sep 01, 2021 9:27 am

Hello,

Thank you for your inquiry.
I tested your code and found the behavior you mentioned. I have logged the issue into our Bug tracking system with the ticket number SPIREPDF-4614. Our development team will investigate and fix it. Once it is resolved, I will inform you. Sorry for the inconvenience caused.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 722
Joined: Wed Apr 07, 2021 2:50 am

Sat Oct 09, 2021 8:57 am

Hello,

Thanks for your patience.

Glad to inform you that we just released Spire.PDF Pack(Hot Fix) Version:7.10.0, which fixes the issue of ticket SPIREPDF-4614. Please download the new version from the following links for testing.

Website link: https://www.e-iceblue.com/Download/down ... t-now.html
NuGet link: https://www.nuget.org/packages/Spire.PDF/7.10.0

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 722
Joined: Wed Apr 07, 2021 2:50 am

Thu Oct 14, 2021 9:03 am

Hello,

Hope you are doing well!
Have you tried the new version of Spire.PDF? Is the issue resolved now? Any feedback will be greatly appreciated.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 722
Joined: Wed Apr 07, 2021 2:50 am

Tue Nov 02, 2021 8:07 am

I'm sorry to let you waiting so long. It would be convenient for copy of answer or notification to be sent over e-mail since I don't visit forum regularly to see answers on time.

But anyway, great, according to my test your fix seems to work, thank you.

Sincerely,
Brane

bbrodnik
 
Posts: 14
Joined: Sat Jan 09, 2021 10:38 am

Tue Nov 02, 2021 8:15 am

Hello,

You're welcome.
If you have other questions about using Spire.PDF in the future, please feel free to contact us.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 722
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.PDF