6 Answers, 1 is accepted
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
I have been using this one for demo: https://docs.telerik.com/aspnet-mvc/helpers/pdf/pdfviewer/pdfjs-processing..
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
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
src
=
"https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.2.2/pdf.js"
></
script
>
<
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
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
TY Nencho, yes it helps.
The problem's gone as soon as I moved the pdfViewer's scripts up the stream.
Regards,
Vlad