PDFViewer works on localhost but fails on deployed server

We are using the PDFviewer to show a document dynamically by calling

pdfViewer.Load("data:application/pdf;base64," + base64String, null);

this works on localhost but does not work when running on a deployed server

in the console we are getting the following errorsyncfusion-blazor-extended-91153b.min.js:1 Unexpected token T in JSON at position 0

SyntaxError: Unexpected token T in JSON at position 0

    at JSON.parse (<anonymous>)

    at e.pdfViewer.serverActionSettings.loadRequestHandler.onSuccess (https://oursite.com/_content/Syncfusion.Blazor.PdfViewer/scripts/pdfviewer-91153b.min.js:1:1251237)

    at e.successHandler (https://oursite.com/_content/Syncfusion.Blazor.PdfViewer/scripts/pdfviewer-91153b.min.js:1:1455552)

    at Object.ioSuccessHandler (https://oursite.com/_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor-extended-91153b.min.js:1:35778)

    at https://oursite.com/_framework/blazor.server.js:1:70369

    at new Promise (<anonymous>)

    at e.beginInvokeJSFromDotNet (https://oursite.com/_framework/blazor.server.js:1:70335)

    at https://oursite.com/_framework/blazor.server.js:1:26442

    at Array.forEach (<anonymous>)

    at e.invokeClientMethod (https://oursite.com/_framework/blazor.server.js:1:26412)



5 Replies

VS Vasugi Sivajothi Syncfusion Team May 11, 2022 09:19 AM UTC

Hi Michael,


We suspect that the “Unexpected token T in JSON at position 0” error occurs due to the missing of the pdfium dll in your environment. We will create the pdfium based on the operating system at the runtime. So, could you please try copying the below provided dll and paste it inside the folder into your project to resolve the issue or enable the write permission for that folder?



Pdfium.dll


For more information, please refer to the below UG link.


https://blazor.syncfusion.com/documentation/pdfviewer/how-to/unexpected-token


Kindly try this and let us know if the issue resolves or not.


Regards,

Vasugi.



MS Michael Salzlechner May 12, 2022 01:28 PM UTC

i tried copying the pdfium.dll file (from windows/x64 into the project folder with all the other dlls on the server. that did not seem to make a difference.

i looked at the link  you posted but not sure how i would set the ReferencePath with a blazor SfPdfViewerServer component

are there any other dependencies for pdfi



VS Vasugi Sivajothi Syncfusion Team May 13, 2022 12:50 PM UTC

Hi Michael,


We suspect that the reported issue is due to pdfium dll is not referred properly on your end. We suggest you refer to the pdfium dll in the published folder and If you host the application in the Linux service then you must install the Linux package (Syncfusion.Blazor.PdfViewerServer.Linux) to run the application. So, please confirm the hosting environment service. Kindly try this and let us know if the issue resolves or not. If not, please share the hosting environment details and package details. This will be helpful to investigate further and provide the solution at the earliest. Or we can set up a web meeting to check the issue in your environment and provide the solution. Please let us know your availability. We will make every effort to have this scheduled on a date and time of your convenience.


Regards,

Vasugi.



MS Michael Salzlechner May 14, 2022 10:05 AM UTC

we are hosting this on a Amazon AWS Elastic Beanstalk Environment in an EC2 Instance running  IIS 10.0 on 64bit Windows Server 2019

We are building the project in Visual Studio and publishing the project from Visual Studio to AWS using the Visual Studio AWS tools.

i saw the reference code in the sample for linux but am not sure how to add a reference to pdfium in a blazor SfPDFViewerServer component





VS Vasugi Sivajothi Syncfusion Team May 17, 2022 03:19 AM UTC

Hi Michael,


Thank you for the update. You can place the pdfium in your project in a folder called “Assets” and added this to .csproj file.

 

    <ItemGroup>

        <AssetsSourceFiles Include="Assets/**/*.*" />

    </ItemGroup>

    <Target Name="CopyCustomContent" AfterTargets="AfterPublish" Condition="'$(Configuration)'=='Release'">

        <Copy SourceFiles="@(AssetsSourceFiles)" DestinationFolder="$(PublishDir)" SkipUnchangedFiles="true" />

    </Target>

 


Kindly try this and let us know if the issue resolves or not.


Regards,

Vasugi.


Loader.
Up arrow icon