Rank: Newbie
Groups: Registered
Joined: 1/29/2018(UTC) Posts: 4 
|
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
|
|
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 1/29/2018(UTC) Posts: 4 
|
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).
|
|
|
|
|
|
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#id00700352. 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);
}
|
|
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 1/29/2018(UTC) Posts: 4 
|
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
|
|
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,138
Thanks: 10 times Was thanked: 133 time(s) in 130 post(s)
|
|
|
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 1/29/2018(UTC) Posts: 4 
|
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...
|
|
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,138
Thanks: 10 times Was thanked: 133 time(s) in 130 post(s)
|
|
|
|
|
|
|
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.
Important Information:
The Patagames Software Support Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close