This is a migrated thread and some comments may be shown as answers.

GlobalWorkerOptions error

6 Answers 896 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 11 Oct 2019, 09:24 AM

When i am follow the guide for show the pdf file, i am getting the error 'Cannot read property 'GlobalWorkerOptions' of undefined' ..

 

Am i missing some stuff in the code, to make it work?

 

6 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 15 Oct 2019, 07:03 AM

Hello Robert,

Could you please share which is the exact article you followed and at what point the error occurred? Generally, loading a file should only consist of setting up the Processor and provide a path to the file, as demonstrated in the PDFJS Processing documentation article and its demo:

Documentation: https://docs.telerik.com/kendo-ui/controls/PDF/PDFViewer/pdfjs-processing

Demo: https://demos.telerik.com/kendo-ui/pdfviewer/index

I am looking forward to your reply.

Regards,
Nencho
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Robert
Top achievements
Rank 1
answered on 15 Oct 2019, 07:17 AM

I have been using this one for demo: https://docs.telerik.com/aspnet-mvc/helpers/pdf/pdfviewer/pdfjs-processing..

 

0
Nencho
Telerik team
answered on 17 Oct 2019, 06:33 AM

Hello Robert,

For the testing purpose, I followed the exact steps, demonstrated in the referenced article and the PDFViewer properly loaded the specified pdf file. That's why I'm sending you the testing project with this reply. Please give it a try at your end and let me know if the issue still persists.

If any modifications of the project are needed to replicate the issue - please share the exact steps.

Regards,
Nencho
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Vladimir
Top achievements
Rank 1
answered on 07 Nov 2019, 03:58 PM

Hello Nencho,

I have exactly the same error message in my app.

In order to reproduce the error message I downloaded the test project above and did the following.

1 . Created a new view pdfViewer.cshtml and cut-pasted the following code from Index view:

<script>
        window.pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.2.2/pdf.worker.js';
</script>
 
@(Html.Kendo().PDFViewer()
        .Name("pdfviewer")
        .PdfjsProcessing(pdf => pdf
            .File(Url.Content("~/Content/web/sample.pdf"))
        )
        .Height(1200)
  )

 

2. Added the following code to HomeController:

public PartialViewResult pdfViewer()
        {
             return PartialView("pdfViewer");
        }

 

3. Added the following code to the Index View:

@(Html.Kendo().TabStrip()
    .Name("tabStrip")
    .Items(items =>
    {
        items.Add().Text("pdfViewer").LoadContentFrom("pdfViewer", "Home");
    })
)

 

4. Now I run the test app and get the error message as seen on the attached screenshot.

5. If replace the tabstrip with the partial view call, everything works as expected.

@Html.Action("pdfViewer", "Home")

 

Regards,

Vlad

 

0
Nencho
Telerik team
answered on 11 Nov 2019, 11:27 AM

Hello, Vladimir,

The reason for the error, in this case, is the fact that the Worker script is executed after the initialization of the PdfViewer itself. The ScriptRender in your Layout page is controlling this rendering.

In order to overcome this, you can place the Worker script in your Index.cshtml view, before the TabStrip initialization, as demonstrated below:

<script>
    window.pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.2.2/pdf.worker.js';
</script>

@(Html.Kendo().TabStrip()
    .Name("tabStrip")
    .Items(items =>
    {
        items.Add().Text("pdfViewer").LoadContentFrom("pdfViewer", "Home");
    })
)

Hope this would help.

Regards,
Nencho
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Vladimir
Top achievements
Rank 1
answered on 12 Nov 2019, 03:11 PM

TY Nencho, yes it helps.

The problem's gone as soon as I moved the pdfViewer's scripts up the stream.

 

Regards,

Vlad

Tags
PDFViewer
Asked by
Robert
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Robert
Top achievements
Rank 1
Vladimir
Top achievements
Rank 1
Share this question
or