logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
FSI  
#1 Posted : Monday, January 29, 2018 2:31:24 AM(UTC)
FSI

Rank: Newbie

Groups: Registered
Joined: 1/29/2018(UTC)
Posts: 4
Germany

Hi all,

we are interested in licencing Pdfium.Net SDK and are currently using the trial version to investigate whether all our use cases can be covered by Pdfium.Net SDK.

Right now, we are encountering a problem when trying to set a form field's value which is coupled to some javascript code. In detail, we try to set a date value in one field and another field parses it, adds two weeks to it and should show this newly calculated date.
However, when executing the following javascript line

Code:

var formatted = date.toLocaleDateString('de-DE');


we get a "Unhandled Exception: System.AccessViolationException : attempted to read or write protected" and our whole system crashes, printing the hint

Code:

#
# Fatal error in , line 0
# Failed to create ICU date format, are ICU data files missing?
#


Do you know how to resolve this error?

If not, we would at least want to be able to catch an exception instead of letting our whole system crash. Could this system crash be anyhow prevented (assuming that the javascript code can not be altered)?

Regards
FSI  
#2 Posted : Tuesday, January 30, 2018 1:57:30 AM(UTC)
FSI

Rank: Newbie

Groups: Registered
Joined: 1/29/2018(UTC)
Posts: 4
Germany

Attached you can find the VS solution, including the test pdf file. The pdfium.dlls are not included due to the large zip file size (they are the ones of version 3.12.5.2704).

Thanks for your help.

PatagamesForumSolution_without_pdfiumDLLs.zip (261kb) downloaded 22 time(s).
Paul Rayman  
#3 Posted : Tuesday, January 30, 2018 4:03:44 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Looks like there is a bug inside V8 engine (open source JavaScript engine used by Pdfium).
Most likely a workaround exists, but you will need to change the JavaScripts code.
In any case, Google gives a lot of information about this V8 bug

Also you can catch AccessViolationException to prevent the crash.
You have at least two options.
1. You may add a line to your application's config file under the configuration/runtime element:
Code:

<legacyCorruptedStateExceptionsPolicy enabled="true|false"/>

I did not check this, but it should work according to this article http://msdn.microsoft.co.../dd419661.aspx#id0070035

2. You may decorate the method you want to catch AccessViolation exceptions in with the HandleProcessCorruptedStateExceptions attribute.
I have tested it with your code. It's works
Code:

        [HandleProcessCorruptedStateExceptions]
        public static void Main(string[] args)
        {
            PdfCommon.Initialize();

            var forms = new PdfForms();
            var origDoc = PdfDocument.Load(@"text_form_multiple.pdf", forms);

            foreach (var field in forms.InterForm.Fields)
            {
                var fieldFullName = field.FullName;

                try
                {
                    if (fieldFullName == "created")
                    {
                        try
                        {
                            field.Value = "26.01.2018";
                        }
                        catch(AccessViolationException ex)
                        {
                            Console.WriteLine("catched" + ex.Message);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }

            var path = @"text_form_multiple_mod.pdf";
            origDoc.Save(path, SaveFlags.NoIncremental, 14);
            Console.WriteLine("Saved pdf at " + path);
        }

FSI  
#4 Posted : Friday, February 2, 2018 10:01:09 AM(UTC)
FSI

Rank: Newbie

Groups: Registered
Joined: 1/29/2018(UTC)
Posts: 4
Germany

Hi Paul,

thanks for your reply, the way to catch the AccessViolationException was a valuable hint of you, now the application does not crash any more.

However, the interesting thing is that the initial javascript execution after loading the pdf document does not lead to a crash/exception.
The crash only happens if a field's value is set.
This can be reproduced by changing the code's first line in the field "createdInTwoWeeks": instead of reading the value of "created", just begin with
Code:
 
var created = "26.01.2018";

If I now just print every field's value, no crash/exception happens (the German locale is not respected and the date is formatted in English though, but that is not as severe as the crash/exception).
Is there any difference in how the javascript is executed when loading a pdf document and when setting a field's value?

Moreover, if an AccessViolationException is catched, the PdfDocument is not disposable anymore (I suppose because of the corrupted form fill environment) which leads to another AccessViolationException.
This also can be catched in the application of course, but makes the further use of the library in the application not possible any more as further load requests of the application to the library do not work any more.
Is there a somehow more robust way to catch the Exception and to continue using the library?

Regards
Paul Rayman  
#5 Posted : Monday, February 5, 2018 4:35:29 PM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
To fix ICU error you should place icudt.dll to the same folder where your exe file is located.
You can download icudt.dll file here
https://pdfium.patagames...files/helpdesk/icudt.zip

Also we will add this file to the distribution packages.

Edited by user Monday, February 5, 2018 4:40:12 PM(UTC)  | Reason: Not specified

FSI  
#6 Posted : Monday, February 5, 2018 11:18:51 PM(UTC)
FSI

Rank: Newbie

Groups: Registered
Joined: 1/29/2018(UTC)
Posts: 4
Germany

Great, placing this dll next to the exe works, thank you very much!

I tried placing several icudt.dlls next to the exe but I guess I tried the wrong ones...
Paul Rayman  
#7 Posted : Tuesday, February 6, 2018 12:08:13 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.