Skip to content

Commit da7778a

Browse files
991876: Updated proper code-snippet for MVC resources Loaded
1 parent 7458eb0 commit da7778a

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

Document-Processing/PDF/PDF-Viewer/asp-net-mvc/how-to/load-document-after-resources-loaded.md

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: post
33
title: Load document after resources Loaded MVC PDF Viewer | Syncfusion
4-
description: Learn here how to load a PDF only after assets are ready in the Syncfusion ASP.NET Core PDF Viewer (Standalone) using the resourcesLoaded event.
4+
description: Learn here how to load a PDF only after assets are ready in the Syncfusion ASP.NET MVC PDF Viewer (Standalone) using the resourcesLoaded event.
55
platform: document-processing
66
control: PDF Viewer
77
documentation: ug
@@ -10,7 +10,7 @@ domainurl: ##DomainURL##
1010

1111
# Load a PDF only after PDFium resources are ready
1212

13-
In Standalone mode, the ASP.NET Core PDF Viewer downloads its PDFium runtime assets (scripts/wasm) from the location specified in the resourceUrl property. Attempting to load a document before those assets are available can cause errors. Use the resourcesLoaded event to defer document loading until all required assets are ready.
13+
In Standalone mode, the ASP.NET MVC PDF Viewer downloads its PDFium runtime assets (scripts/wasm) from the location specified in the resourceUrl property. Attempting to load a document before those assets are available can cause errors. Use the resourcesLoaded event to defer document loading until all required assets are ready.
1414

1515
## When does resourcesLoaded trigger?
1616

@@ -23,34 +23,29 @@ The resourcesLoaded event fires once the viewer finishes loading all required PD
2323

2424
{% tabs %}
2525
{% highlight cshtml tabtitle="Standalone" %}
26-
@using Syncfusion.EJ2
26+
2727
@{
2828
ViewBag.Title = "Home Page";
2929
}
30-
31-
<div class="control-section">
32-
@Html.EJS().PdfViewer("pdfViewer")
33-
.ResourceUrl("https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib")
34-
.ResourcesLoaded("onResourcesLoaded")
35-
.Render()
30+
@Html.EJS().ScriptManager()
31+
<div>
32+
<div style="height:500px;width:100%;">
33+
@Html.EJS().PdfViewer("pdfviewer").ResourceUrl("https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib").Render()
3634
</div>
37-
35+
</div>
36+
3837
<script>
39-
var documentUrl = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
40-
var base64 = 'data:application/pdf;base64,JVBERi0xLjMNCiXi48...'; //Update Base64 here
41-
42-
function onResourcesLoaded(args) {
43-
var viewer = document.getElementById('pdfViewer').ej2_instances[0];
44-
45-
// Load by URL
46-
viewer.load(documentUrl, '');
47-
48-
// Or Base64
49-
// if (base64) {
50-
// viewer.load('data:application/pdf;base64,' + base64, '');
51-
// }
52-
}
38+
window.onload = function() {
39+
var viewer = (document.getElementById('pdfviewer')).ej2_instances[0];
40+
viewer.resourcesLoaded = function () {
41+
viewer.load(base64, ''); //viewer.load(documnetUrl,'') to load via document Url
42+
}
43+
}
44+
var documentUrl = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
45+
46+
var base64 = 'data:application/pdf;base64,JVBERi0xLjMNCiXi48....'; //Update Base64 here
5347
</script>
48+
5449
{% endhighlight %}
5550
{% endtabs %}
5651

0 commit comments

Comments
 (0)