We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Strange Issue with PDF Viewer when deployed to web server

Hi,

Got a strange problem when my application is deployed to my web server.
When opening the PDF Viewer I get the following Error:

ejs.interop.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.loadRequestHandler.onSuccess (https://cdn.syncfusion.com/ej2/17.4.39/dist/ej2.min.js:10:9101404)
    at e.successHandler (https://cdn.syncfusion.com/ej2/17.4.39/dist/ej2.min.js:10:9239995)
    at Object.ioSuccessHandler (https://cdn.syncfusion.com/ej2/17.4.39/dist/ejs.interop.min.js:1:20011)
    at https://dev.medco.awesomesource.dev/_framework/blazor.server.js:8:31421
    at new Promise (<anonymous>)
    at e.beginInvokeJSFromDotNet (https://dev.medco.awesomesource.dev/_framework/blazor.server.js:8:31390)
    at https://dev.medco.awesomesource.dev/_framework/blazor.server.js:1:19202
    at Array.forEach (<anonymous>)
    at e.invokeClientMethod (https://dev.medco.awesomesource.dev/_framework/blazor.server.js:1:19173)

I do not get this error when running on my development machine an debugging from Visual Studio. I am referencing the latest version of everything.
Any Ideas if I am perhaps missing a dependency on my web server - but I don't think I am as this did work with the previous version of Syncfusion.
 I am referencing the javascript files via your CDN

...
<link rel='nofollow' href="https://cdn.syncfusion.com/ej2/17.4.39/material.css" rel="stylesheet" />
<script src="https://cdn.syncfusion.com/ej2/17.4.39/dist/ej2.min.js"></script>
<script src="https://cdn.syncfusion.com/ej2/17.4.39/dist/ejs.interop.min.js"></script>
...


Code as follows: ViewPDF.Razor

@using Medco.Models
@using Medco.Models.ViewModels
@using Syncfusion.EJ2.Blazor.Calendars
@using Syncfusion.EJ2.Blazor.Popups
@using Syncfusion.EJ2.Blazor.DropDowns
@using Syncfusion.EJ2.Blazor.Inputs
@using Syncfusion.EJ2.Blazor.PdfViewerServer

@if (DocumentPath != null)
{
    <EjsPdfViewerServer DocumentPath="@DocumentPath" Width="100%" Height="850px"></EjsPdfViewerServer>
}

@code {
    [Parameter] public string DocumentPath { get; set; }

}


And the code which sets the DocumentPath parameter is as follows (it is a byte array converted to base 64 string) : ViewPDFDialog.razor

@using Medco.Models
@using Medco.Models.ViewModels
@using Syncfusion.EJ2.Blazor.Calendars
@using Syncfusion.EJ2.Blazor.Popups
@using Syncfusion.EJ2.Blazor.DropDowns
@using Syncfusion.EJ2.Blazor.Inputs
@using Syncfusion.EJ2.Blazor.PdfViewerServer

<EjsDialog @ref="DialogObj" Width="100%" Height="100%" ShowCloseIcon="true" IsModal="true" @bind-Visible="_dlgVisible">
    <DialogTemplates>
        <Header>@DialogTitle</Header>
        <Content>
            <ViewPDF DocumentPath="@DocumentPath"></ViewPDF>
        </Content>
    </DialogTemplates>
</EjsDialog>


@code {
    [Parameter] public AssignmentData AssignmentData { get; set; }
    public string DialogTitle { get; set; }
    public string DocumentPath { get; set; }
    private bool _dlgVisible = false;
    protected EjsDialog DialogObj;

    [Parameter] public EventCallback OnClose { get; set; }

    public void ShowDialog(byte[] pdfData, string dialogTitle)
    {
        DocumentPath = null;
        StateHasChanged();
        DialogTitle = dialogTitle;
        DocumentPath = "data:application/pdf;base64," + Convert.ToBase64String(pdfData);
        StateHasChanged();
        DialogObj.Show(true);
    }
}

As stated above, this works perfectly fine on my development machine, but throws the JS error when deployed to my web server.


25 Replies

AA Akshaya Arivoli Syncfusion Team December 20, 2019 09:42 AM UTC

Hi Matthew, 

Thank you for contacting Syncfusion support. 

We have tried deploying the sample with IIS but we are unable to reproduce the reported issue with the provided details. We have shared the sample in which we have tried to reproduce the issue in the below link, 


Please try this and revert us with the more details about your issue, modified sample with replication procedure and your hosting environment details if you are still facing the issue. These details will be helpful for us to investigate further and assist you better. 

Regards, 
Akshaya 



MA Matthew December 20, 2019 10:41 AM UTC

Hi Akshya,

I will give your sample a go - I'm pretty sure the issue is something to do with my hosting enironment, I was just hoping the error message may have pointed as to what is incorrect in my hosting environment.

Thanks


AA Akshaya Arivoli Syncfusion Team December 23, 2019 06:45 AM UTC

Hi Matthew, 
 
Thank you for your update. Please try with the provided sample in your hosting environment and revert us with more details about your issue, modified sample and the hosting environment details if you are still facing the issue. These details will be helpful for us to investigate further and assist you better. 
 
Regards, 
Akshaya 



MA Matthew December 23, 2019 11:24 AM UTC

Hi,

I've tried your sample and get the same result:


I have built and deployed your sample application with no changes.
You can see for yourself at https://pdftest.medco.awesomesource.dev

This is definitely a hosting environment issue - it's just a case of working out what's wrong.

It's Windows Server 2012 R2, IIS v8.5 and I have the .NetCore 3.1 SDK installed

If you want to know any more details about the environment, please let me know.


NC NKOUAMBIA CHIMENE January 16, 2020 08:27 PM UTC

Hi,
The same issue for me as Matthew on a Nginx Centos Server, on my dev post every thing work but nothing on server.

Thanks,
Chimène NK.


MA Matthew January 16, 2020 08:45 PM UTC

Hi Nkouabia,

The only thing I'd say is different for my deployment is that I am using Azure DevOps (MSBuild) for build & deploy. However it seems there is some dependceny somewhere missing, causing the problem. Something is missing in the nuget restore, or there is some MS Windows windows native dependency causing some kind of issue.


MS Mohan Selvaraj Syncfusion Team January 17, 2020 01:29 PM UTC

Hi Matthew,  

We are using Pdfium rendering engine for robust rendering in our PDF Viewer, it will generate the Pdfium dll during the run time (i.e, on loading the document). We suspect that due to the write access permission is denied in the production environment the reported issue may occurred and so can you please try copying the below provided pdfium.dll inside the folder(bin\Debugetcoreapp2.1) in the production environment to resolve the issue.  
 


Regards, 
Mohan S 



NC NKOUAMBIA CHIMENE January 20, 2020 05:36 PM UTC

Hello Team!
I apply the given solution but it not work, as i was saying on my dev post everything work well, but after deploy on my linux serveur(Nginx Centos) I have the error and nothing show.

On my dev post I have the file .\bin\Debugetcoreapp3.1\x64\pdfium.dll
but in the relase folder .\bin\Releaseetcoreapp3.1\linux-x64 the folder x64 or the dll doesn't exist, has the last answer said I try several thing but none of them works
1- Copy manually the x64 folder in my deploy folder on server 
2- Copy the pdfium.dll in the root folder
3- Create the folder bin\Debugetcoreapp2.1 and copy the dll into it (I also rename the folder bin\Debugetcoreapp3.1)
I always give the 777 right to folder and file but nothing change

Is ther any other thing I can Try? 

Thanks,
Chimène NK.


MA Matthew January 20, 2020 07:19 PM UTC

Hi,

I can confirm copying the pdfium.dll file to the deployment folder does not resolve the issue.

Thanks


AA Akshaya Arivoli Syncfusion Team January 21, 2020 01:54 PM UTC

Hi Matthew, 

We have found that in Linux docker container the library libpdfium.so does not refer correctly. We are working to resolve this by exposing the ReferencePath property to refer the location of libpdfium.so in our source and we will update you the details. Meantime, can you please check the below steps from your side and confirm whether the issue is resolved or not? 

STEP1: Download the libpdfium.so from the following link and include it in our PDF Viewer service project 

STEP2: Add the following Docker command in your docker file to copy the libpdfium.so files in the published directory  
              RUN cp -r "libpdfium.so" /app/publish 

Please let us know if you have any concerns about this. 

Thanks, 
Akshaya 



NC NKOUAMBIA CHIMENE January 23, 2020 02:23 PM UTC

Hello Team,

I'm not working with the Container so I try this step to include the files in my project but nothing work at all 
1- On my developpement post(Windows10) I copy the file libpdfium.so into the folder  MyApp\bin\Releaseetcoreapp3.1\linux-x64\libpdfium.so (I even copy it in the MyApp\bin\Debugetcoreapp3.1\libpdfium.so) I also copy the pdfium.dll in those folder just in case
2. I publish my project then I find out that the  libpdfium.so is not in release folder(even the pdfium.dll)
3. I copy it manually in the app folder on my linux server in but still have the same error
Just to remind every thing works on my developpement post

Have I missing something ?

Thanks,
Chimène NK.


AA Akshaya Arivoli Syncfusion Team January 24, 2020 12:03 PM UTC

Hi NKOUAMBIA , 

We have analyzed further on this and found that some library dependencies of libpdfium.so are missing in your linux environment. To resolve this issue, you have to execute the following command.  

RUN apt-get update \  
    && apt-get install -y --allow-unauthenticated \  
        libc6-dev \  
        libgdiplus \  
        libx11-dev \  
        curl \  
        vim \  
        supervisor \  
        procps  
  

Please let us know if you have any concerns about this.  

Regards, 
Akshaya 



MA Matthew replied to Akshaya Arivoli January 24, 2020 09:05 PM UTC

Hi Matthew, 

We have found that in Linux docker container the library libpdfium.so does not refer correctly. We are working to resolve this by exposing the ReferencePath property to refer the location of libpdfium.so in our source and we will update you the details. Meantime, can you please check the below steps from your side and confirm whether the issue is resolved or not? 

STEP1: Download the libpdfium.so from the following link and include it in our PDF Viewer service project 

STEP2: Add the following Docker command in your docker file to copy the libpdfium.so files in the published directory  
              RUN cp -r "libpdfium.so" /app/publish 

Please let us know if you have any concerns about this. 

Thanks, 
Akshaya 


Hi Akshaya,

I'm working on windows all the way. No Linux involved.
What I can tell you is that in my local build & deploy, pdfium.dll does get added to the x64 platform folder.