Possible encoding problem in exportAsXFDFStr

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software

Post Reply
prosozial_schmitt
User
Posts: 52
Joined: Tue Dec 28, 2004 9:49 am

Possible encoding problem in exportAsXFDFStr

Post by prosozial_schmitt » Wed Jul 13, 2016 12:20 pm

Hello,

i want to use exportAsXFDFStr to export fieldvalues into a string. The returned string differs from the result of exportAsXFDF (into file). It seems, that the encoding of the result of exportAsXFDFStr is wrong?
See screenshot.

How can I use exportAsXFDFStr to get the fieldvalues as string without encoding-problem?
Which encoding do you use internaly in your javascript implementation?

Greetings
Hans-Peter
Attachments
Encoding problem.zip
Screenshot
(455.19 KiB) Downloaded 58 times

Lzcat - Tracker Supp
Site Admin
Posts: 712
Joined: Thu Jun 28, 2007 8:42 am

Re: Possible encoding problem in exportAsXFDFStr

Post by Lzcat - Tracker Supp » Wed Jul 13, 2016 3:01 pm

Hi Hans-Peter.
If you take a closer look at your screen-shot you will see an answer to your question it the first lines of returned string - encoding is UTF-8. So to get correct text you should convert it to other encoding you need (interpreting UTF-8 text as ASCII fails when non-ascii characters are used).
HTH.
Victor
Tracker Software
Project manager

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.

prosozial_schmitt
User
Posts: 52
Joined: Tue Dec 28, 2004 9:49 am

Re: Possible encoding problem in exportAsXFDFStr

Post by prosozial_schmitt » Thu Jul 14, 2016 6:37 am

Hello Lzcat,

i've tried this before posting in your blog - but this is not the problem.
The encoding of the returned string from exportAsXFDFStr is not UTF-8. The XML has only the information "UTF-8" in it's header. I've checked this with your sample application "VB.NET Full Demo".
Even this sample shows a not correct decoded JScript-result.

After researching and testing:
I seems that your .NET COM-Wrapper of the exportAsXFDFStr-implementation returns a "ISO-Latin1" encoded string. After reading "Adobe XML Forms Data Format Specification" in section "String encoding conventions": "Use ISO-Latin1 as the assumed encoding of the bytes in the PDF. For example, for the link annotation,
this applies to the Named Destination name and the file OriginalName.".

I've changed my code to:

Dim xfdfBinary = System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(jsResult)
return System.Text.Encoding.UTF8.GetString(xfdfBinary)

For this case, it seems to solve the problem.

But I have not expected to get an incorrect decoded string from your .NET COM-Wrapper methods of the RunJavaScript method only(?) in case of the "exportAsXFDFStr" javascript-implementation. A COM-Wrapper which converts a bstr in a .NET string should deliver a correct displayable string.
On the other way: if a not correct decoded .NET String is a "desired behaviour", a hint in your documentation would be nice.

Thank you for your answer
Hans-Peter

Ivan - Tracker Software
Site Admin
Posts: 3609
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Possible encoding problem in exportAsXFDFStr

Post by Ivan - Tracker Software » Thu Jul 14, 2016 9:09 pm

Can you send us your PDF with problematic form field value?
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.

prosozial_schmitt
User
Posts: 52
Joined: Tue Dec 28, 2004 9:49 am

Re: Possible encoding problem in exportAsXFDFStr

Post by prosozial_schmitt » Fri Jul 15, 2016 5:15 am

Hello Ivan,

I've attached the file.

Greetings
Hans-Peter
Attachments
PDF Formular Antrag auf ALG II.zip
(280.14 KiB) Downloaded 52 times

Ivan - Tracker Software
Site Admin
Posts: 3609
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Possible encoding problem in exportAsXFDFStr

Post by Ivan - Tracker Software » Tue Jul 19, 2016 5:45 pm

Thanks for the file. The issue is fixed now, and the fix will be available in next build of the Editor. Unfortunately, I cannot say exact date when this build will be available yet.
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.

Post Reply