TMSFNCWXPDFViewer with WebCore LoadFromBase64 error

I'm trying TMSFNCWXPDFViewer inside a webcore app consuming an xdata API implementation to retrieve PDF in base64
Value is well retrieve and content is checked from a memo with Base64 to PDF | Base64 Decode | Base64 Converter | Base64
Base64 string content a well formated PDF
But when I'm trying to load base64 inside TMSFNCWXPDFViewer with LoadFromBase64 I get an error

Uncaught TypeError: this.executeScriptB02C57F2E7E8D26202E07D8A6E42A2DA is not a function | TypeError: this.executeScriptB02C57F2E7E8D26202E07D8A6E42A2DA is not a function at eval (eval at functionFromString (http://localhost:8000/ecopdf_client/ecopdf_client.js:73084:28), :3:32) at mainfunc (http://localhost:8000/ecopdf_client/ecopdf_client.js:73093:24) at Object.ExecuteJavascript (http://localhost:8000/ecopdf_client/ecopdf_client.js:73097:19) at Object.ExecuteJavaScript (http://localhost:8000/ecopdf_client/ecopdf_client.js:626:38) at Object.ExecuteJavaScript (http://localhost:8000/ecopdf_client/ecopdf_client.js:73560:28) at Object.ShowPDFFile (http://localhost:8000/ecopdf_client/ecopdf_client.js:75106:12) at Object.LoadFromBase64 (http://localhost:8000/ecopdf_client/ecopdf_client.js:75572:14) at Object.XDataWebClientLoad (http://localhost:8000/ecopdf_client/ecopdf_client.js:83698:33) at Object.cb [as FOnLoad] (http://localhost:8000/ecopdf_client/ecopdf_client.js:242:19) at Object.DoLoad (http://localhost:8000/ecopdf_client/ecopdf_client.js:83016:42)
at http://localhost:8000/ecopdf_client/ecopdfclient.html [3:32]

Any idea about cause of error ?



Is the PDF prefix (data:application/pdf;base64,) part of your base64 string? If yes, then you'll need to remove that first and only pass the raw base64 data to the component.

I decoded BASE64 Text (w and the begining doesn't contains prefix you mention

2 0 obj
<</Length 3 0 R/Filter/FlateDecode>>
xM=-ׯ�y-av�9@AZ3Z|; oupؚDQEQN;k{_w-+7WǯZT֯~~O_y0z~O/ow^(?~#s3ԯϛw_loß1~߿F5ƛA/yïQ߼t0oŏoe͌9ঢw?ةWzқcǚuHmv6%we>Su?ݽgo:Moz|}]<ԭ?m�-5Qj{.}G緻[k^0yO/fWyTbL1咶r[HɴƮ|9T;r[6\&6zOaKVn\C:Ձ727*9[i>,(}DG>>8vD͞3s!Xӕ+vpA=̩<odK+uzF$e2|!j{V1&b |_쌕OqF붾ݍߊ O+4^g0<ECg�CSʑhVfcT({02&*쾤"(d6

By converting stream with NetEncoding

TNetEncoding.Base64.Decode( InStream, OutStream );

The saved file works fine.

I tried with VLC app and I don't get any exception but display stay empty with


Loading the same base64 converted file works fine


So I guess there is something during conversion which isn't working here.

The decoded text won't contain the prefix, this prefix is part of the base64 string. Does the base64 represented PDF you get through XData start with data:application/pdf;base64,?

In other words, what does your sBase64_render variable look like?

Base64 part is collected from a JSON as an xData answer

    "$id": 1,
    "success": "true",
    "error_messsage": "",
    "filename": "report.pdf",
    "PDFbase64": "JVBERi0xLjYKJcOkw7zDt...."

string PDFbase64 is collected and sent directly to LoadFromBase64
Same string copy paste and decoded by is displayed perfectly

That indeed seems to be the correct representation that should be passed to the TTMSFNCWXPDFViewer. If you take a look at the WEB Core demo of the TTMSFNCPDFViewer, you'll see it shows a base64 represented PDF when the application starts.

Can you save your XData response to a text file and attach it here so we can investigate what goes wrong with the loading of your specific PDF?

Please find the xData response with value of base 64 data (81.5 KB)

In the example you sent, there are multiple \r\n instances in your base64. Is this something added when you were saving the JSON to a file or was it part of it before? If it is part of it then most likely that is the problem because the string will be cut off at the newlines leaving you with an incomplete base64 string.

Other than that, we've seen when you add a TMS FNC WX component to your web form, an extra empty script tag is added to your project.html.

Make sure to remove this extra empty script tag, we'll investigate why it gets added in the first place.

It was part of base64 data provided by service (
It's well decoded by all tests I did but it seems pdf.js b64 decoder doesn't work fine with it.

Thanks for tips about empty script line in project. It solves the other ticket

Depending on how you extract the PDFbase64 from the incoming JSON, it's possible the \r and \n values are replaced by CR and LF. When a string that contains CR/LF is being sent to the embedded browser that hosts the PDF viewer the string is cut off at the first newline instance.

This is a possible explaination as why it was not working for you in VCL but was fine when saving to a file and loading it back. When it's being loaded form a file, the component handles the base64 conversion, and it won't have any CR/LF.

You could try something like

TMSFNCWXPDFViewer1.LoadFromBase64(StringReplace(sBase64_render, #13#10, '', [rfReplaceAll]));

You are right, presence of CR LF in base64 disturbs pdf.js decoder.
I removed them by a simple string replace in Win64 app and it's work.

cleaned_base64 := StringReplace(result_base64,#13#10,'',[rfReplaceAll, rfIgnoreCase]);

This works fine too with web app version