Skip to content

Commit d40d642

Browse files
991876: Updated UG Documentation for Resources Loaded
1 parent 35aebdb commit d40d642

File tree

6 files changed

+237
-106
lines changed

6 files changed

+237
-106
lines changed

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

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,47 @@ The resourcesLoaded event fires once the viewer finishes loading all required PD
2121
- Set the resourceUrl to a valid PDF Viewer assets path (CDN or your hosted path).
2222
- Listen to resourcesLoaded and call load inside the handler.
2323

24-
```cshtml
25-
@addTagHelper *, Syncfusion.EJ2
24+
{% tabs %}
25+
{% highlight cshtml tabtitle="Standalone" %}
2626

27-
<!-- Index.cshtml -->
28-
<div class="control-section">
27+
@page
28+
@model IndexModel
29+
@{
30+
ViewData["Title"] = "Home page";
31+
}
32+
33+
<div class="text-center">
2934
<ejs-pdfviewer
3035
id="pdfViewer"
36+
style="height:600px; display:block"
3137
resourceUrl="https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib"
32-
resourcesLoaded="onResourcesLoaded"
33-
style="height: 640px; display: block">
38+
resourcesLoaded="onResourcesLoaded">
3439
</ejs-pdfviewer>
3540
</div>
3641

3742
<script>
38-
// Sample sources to demonstrate both URL and Base64 loading
43+
// Choose one of the following load sources:
3944
var documentUrl = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
40-
var base64 = '';// supply your Base64 here when needed
45+
var base64 = ''; // put Base64 if you want to load from base64
4146

42-
// Called by the resourcesLoaded event
47+
// Called automatically when the PDF Viewer’s resources (worker/lib) are ready
4348
function onResourcesLoaded(args) {
4449
var viewer = document.getElementById('pdfViewer').ej2_instances[0];
4550

46-
// Choose ONE of the following load options:
47-
48-
// 1) Load by URL
49-
viewer.load(documentUrl, null);
51+
// 1) Load by URL (most common)
52+
viewer.load(documentUrl, '');
5053

51-
// 2) Load by Base64 (uncomment if you want to load Base64)
54+
// 2) Load by Base64 (uncomment if needed)
5255
// if (base64) {
53-
// viewer.load('data:application/pdf;base64,' + base64, null);
56+
// viewer.load(base64, '');
5457
// }
5558
}
5659
</script>
57-
```
5860

59-
[View Sample in GitHub]()
61+
{% endhighlight %}
62+
{% endtabs %}
63+
64+
[View Sample in GitHub](https://github.com/SyncfusionExamples/mvc-pdf-viewer-examples/tree/master/How%20to)
6065

6166
## Notes and best practices
6267

@@ -66,7 +71,7 @@ The resourcesLoaded event fires once the viewer finishes loading all required PD
6671

6772
## See also
6873

69-
- [Events in ASP.NET Core PDF Viewer](../events/#resourcesloaded)
74+
- [Events in ASP.NET Core PDF Viewer](../event/#resourcesloaded)
7075
- [Open PDF files](../open-pdf-files)
7176
- [Save PDF files](../save-pdf-files)
7277
- [Getting started](../getting-started)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
layout: post
3+
title: Load document after resources Loaded ASP.NET 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.
5+
platform: document-processing
6+
control: PDF Viewer
7+
documentation: ug
8+
domainurl: ##DomainURL##
9+
---
10+
11+
# Load a PDF only after PDFium resources are ready
12+
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.
14+
15+
## When does resourcesLoaded trigger?
16+
17+
The resourcesLoaded event fires once the viewer finishes loading all required PDFium assets. At this point, it is safe to call the load method to open a document (by URL or Base64).
18+
19+
## How to Load Document after resourcesLoaded
20+
21+
- Set the resourceUrl to a valid PDF Viewer assets path (CDN or your hosted path).
22+
- Listen to resourcesLoaded and call load inside the handler.
23+
24+
{% tabs %}
25+
{% highlight cshtml tabtitle="Standalone" %}
26+
@using Syncfusion.EJ2
27+
@{
28+
ViewBag.Title = "Home Page";
29+
}
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()
36+
</div>
37+
38+
<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+
}
53+
</script>
54+
{% endhighlight %}
55+
{% endtabs %}
56+
57+
[View Sample in GitHub](https://github.com/SyncfusionExamples/mvc-pdf-viewer-examples/tree/master/How%20to)
58+
59+
## Notes and best practices
60+
61+
- Always set a valid resourceUrl when using the Standalone PDF Viewer. If the path is incorrect or blocked by the network, the event cannot fire.
62+
- Load documents inside resourcesLoaded. This guarantees the PDFium runtime is ready and prevents intermittent errors on slower networks.
63+
- The event fires for the viewer’s asset load lifecycle, not for every document load. After it fires once, you can safely call load again later (for example, in response to user actions) without waiting for the event.
64+
65+
## See also
66+
67+
- [Events in ASP.NET MVC PDF Viewer](../event/#resourcesloaded)
68+
- [Open PDF files](../open-pdf-files)
69+
- [Save PDF files](../save-pdf-files)
70+
- [Getting started](../getting-started)

Document-Processing/PDF/PDF-Viewer/javascript-es5/how-to/load-document-after-resources-loaded.md

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,33 @@ The resourcesLoaded event fires once the viewer finishes loading all required PD
2121
- Set the resourceUrl to a valid PDF Viewer assets path (CDN or your hosted path).
2222
- Listen to resourcesLoaded and call load inside the handler.
2323

24-
```html
25-
<!-- index.html (snippet) -->
26-
<link href="https://cdn.syncfusion.com/ej2/31.2.2/material.css" rel="stylesheet">
27-
<script src="https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2.min.js"></script>
28-
29-
<div id="pdfViewer" style="height: 640px; display: block"></div>
30-
31-
<script>
32-
// Initialize the viewer in Standalone mode and point to the assets
33-
var viewer = new ej.pdfviewer.PdfViewer({
34-
resourceUrl: 'https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib',
35-
resourcesLoaded: onResourcesLoaded
36-
});
37-
viewer.appendTo('#pdfViewer');
38-
39-
// Sample sources to demonstrate both URL and Base64 loading
40-
var documentUrl = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
41-
var base64 = '';// supply your Base64 here when needed
42-
43-
// Called when PDFium runtime assets have finished loading
44-
function onResourcesLoaded(args) {
45-
// Choose ONE of the following load options:
46-
47-
// 1) Load by URL
48-
viewer.load(documentUrl, null);
49-
50-
// 2) Load by Base64 (uncomment if you want to load Base64)
51-
// if (base64) {
52-
// viewer.load('data:application/pdf;base64,' + base64, null);
53-
// }
54-
}
55-
</script>
24+
```js
25+
// Initialize the viewer in Standalone mode and point to the assets
26+
var viewer = new ej.pdfviewer.PdfViewer({
27+
resourceUrl: 'https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib',
28+
resourcesLoaded: onResourcesLoaded
29+
});
30+
viewer.appendTo('#pdfViewer');
31+
32+
// Sample sources to demonstrate both URL and Base64 loading
33+
var documentUrl = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
34+
// supply your Base64 here when needed
35+
const base64 = 'data:application/pdf;base64,JVBERi0xLjMNCiXi48..';
36+
// Called when PDFium runtime assets have finished loading
37+
function onResourcesLoaded() {
38+
// Choose ONE of the following load options:
39+
40+
// 1) Load by URL
41+
viewer.load(documentUrl, '');
42+
43+
// 2) Load by Base64 (uncomment if you want to load Base64)
44+
// if (base64) {
45+
// viewer.load(base64, '');
46+
// }
47+
}
5648
```
5749

58-
[View Sample in GitHub]()
50+
[View Sample in GitHub](https://github.com/SyncfusionExamples/javascript-pdf-viewer-examples/tree/master/How%20to)
5951

6052
## Notes and best practices
6153

@@ -65,7 +57,7 @@ The resourcesLoaded event fires once the viewer finishes loading all required PD
6557

6658
## See also
6759

68-
- [Events in JavaScript PDF Viewer](../events/#resourcesloaded)
60+
- [Events in JavaScript PDF Viewer](../event/#resourcesloaded)
6961
- [Open PDF files](../open-pdf-files)
7062
- [Save PDF files](../save-pdf-files)
7163
- [Getting started](../getting-started)

Document-Processing/PDF/PDF-Viewer/javascript-es6/how-to/load-document-after-resources-loaded.md

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,36 @@ The resourcesLoaded event fires once the viewer finishes loading all required PD
2121
- Set the resourceUrl to a valid PDF Viewer assets path (CDN or your hosted path).
2222
- Listen to resourcesLoaded and call load inside the handler.
2323

24-
```html
25-
<!-- index.html (snippet) -->
26-
<link href="https://cdn.syncfusion.com/ej2/31.2.2/material.css" rel="stylesheet">
27-
<div id="pdfViewer" style="height: 640px; display: block"></div>
28-
<script type="module">
29-
import { PdfViewer } from '@syncfusion/ej2-pdfviewer';
30-
31-
// Initialize the viewer in Standalone mode and point to the assets
32-
const viewer = new PdfViewer({
33-
resourceUrl: 'https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib',
34-
resourcesLoaded: onResourcesLoaded
35-
});
36-
viewer.appendTo('#pdfViewer');
24+
```ts
25+
import { PdfViewer, TextSelection, TextSearch, Print, Navigation, Toolbar, Magnification, Annotation, FormDesigner, FormFields, PageInfoModel } from '@syncfusion/ej2-pdfviewer';
26+
27+
// Inject required modules
28+
PdfViewer.Inject(TextSelection, TextSearch, Print, Navigation, Toolbar, Magnification, Annotation, FormDesigner, FormFields);
3729

38-
// Sample sources to demonstrate both URL and Base64 loading
30+
const viewer: PdfViewer = new PdfViewer({
31+
resourceUrl: "https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib",
32+
resourcesLoaded: onResourcesLoaded
33+
});
34+
viewer.appendTo('#PdfViewer');
35+
// Sample sources to demonstrate both URL and Base64 loading
3936
const documentUrl = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
40-
const base64 = '';// supply your Base64 here when needed
37+
const base64 ='data:application/pdf;base64,JVBERi0xLjMNCiX...';// supply your Base64 here when needed
4138

4239
// Called when PDFium runtime assets have finished loading
43-
function onResourcesLoaded(args) {
40+
function onResourcesLoaded() {
4441
// Choose ONE of the following load options:
4542

4643
// 1) Load by URL
47-
viewer.load(documentUrl, null);
44+
viewer.load(documentUrl, '');
4845

4946
// 2) Load by Base64 (uncomment if you want to load Base64)
5047
// if (base64) {
51-
// viewer.load(`data:application/pdf;base64,${base64}`, null);
48+
// viewer.load(base64, '');
5249
// }
5350
}
54-
</script>
5551
```
5652

57-
[View Sample in GitHub]()
53+
[View Sample in GitHub](https://github.com/SyncfusionExamples/typescript-pdf-viewer-examples/tree/master/How%20to)
5854

5955
## Notes and best practices
6056

@@ -64,7 +60,7 @@ The resourcesLoaded event fires once the viewer finishes loading all required PD
6460

6561
## See also
6662

67-
- [Events in JavaScript PDF Viewer](../events/#resourcesloaded)
63+
- [Events in JavaScript PDF Viewer](../event/#resourcesloaded)
6864
- [Open PDF files](../open-pdf-files)
6965
- [Save PDF files](../save-pdf-files)
7066
- [Getting started](../getting-started)

Document-Processing/PDF/PDF-Viewer/react/how-to/load-document-after-resources-loaded.md

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,46 @@ The resourcesLoaded event fires once the viewer finishes loading all required PD
2121
- Set the resourceUrl to a valid PDF Viewer assets path (CDN or your hosted path).
2222
- Listen to resourcesLoaded and call load inside the handler.
2323

24-
```tsx
25-
// App.tsx
24+
```js
25+
//index.js
2626
import React, { useRef, useCallback } from 'react';
27-
import { PdfViewerComponent, Toolbar, Magnification, Navigation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection, Annotation, FormDesigner, FormFields, PageOrganizer, Inject } from '@syncfusion/ej2-react-pdfviewer';
28-
29-
export default function App() {
30-
const viewerRef = useRef<PdfViewerComponent>(null);
27+
import { createRoot } from 'react-dom/client';
28+
import './index.css';
29+
30+
import {
31+
PdfViewerComponent,
32+
Toolbar,
33+
Magnification,
34+
Navigation,
35+
LinkAnnotation,
36+
ThumbnailView,
37+
BookmarkView,
38+
TextSelection,
39+
Annotation,
40+
FormDesigner,
41+
FormFields,
42+
PageOrganizer,
43+
Inject
44+
} from '@syncfusion/ej2-react-pdfviewer';
45+
46+
function App() {
47+
const viewerRef = useRef(null);
3148

3249
const onResourcesLoaded = useCallback(() => {
3350
// Choose ONE of the following load options:
3451

35-
// 1) Load by URL
36-
viewerRef.current?.load('https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf', '');
52+
// 1) Load by URL (recommended for your case)
53+
viewerRef.current?.load(
54+
'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf',
55+
''
56+
);
57+
58+
// 2) Load by Base64 (uncomment if needed)
59+
// supply your Base64 string
60+
// const base64 ='data:application/pdf;base64,JVBERi0xLjMNCiXi48...';
3761

38-
// 2) Load by Base64 (uncomment if you want to load Base64)
39-
// const base64 = '';// supply your Base64 here when needed
4062
// if (base64) {
41-
// viewerRef.current?.load(`data:application/pdf;base64,${base64}`, '');
63+
// viewerRef.current?.load(base64, '');
4264
// }
4365
}, []);
4466

@@ -51,14 +73,33 @@ export default function App() {
5173
resourcesLoaded={onResourcesLoaded}
5274
style={{ display: 'block', height: '100%' }}
5375
>
54-
<Inject services={[Toolbar, Magnification, Navigation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection, Annotation, FormDesigner, FormFields, PageOrganizer]} />
76+
<Inject
77+
services={[
78+
Toolbar,
79+
Magnification,
80+
Navigation,
81+
LinkAnnotation,
82+
ThumbnailView,
83+
BookmarkView,
84+
TextSelection,
85+
Annotation,
86+
FormDesigner,
87+
FormFields,
88+
PageOrganizer
89+
]}
90+
/>
5591
</PdfViewerComponent>
5692
</div>
5793
);
5894
}
95+
96+
// Mount (make sure you have <div id="sample"></div> in index.html)
97+
const container = document.getElementById('sample');
98+
const root = createRoot(container);
99+
root.render(<App />);
59100
```
60101
61-
[View Sample in GitHub]()
102+
[View Sample in GitHub](https://github.com/SyncfusionExamples/react-pdf-viewer-examples/tree/master/How%20to)
62103
63104
## Notes and best practices
64105

0 commit comments

Comments
 (0)