# Can I set a limit on initial page rendering?

**URL:** <https://pdfjs.community/t/can-i-set-a-limit-on-initial-page-rendering/2971>\
**Category:** Technical Support\
**Created:** [November 30, 2023, 7:16am UTC](https://pdfjs.community/t/can-i-set-a-limit-on-initial-page-rendering/2971 "2023-11-30T07:16:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dev1](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@dev1](https://pdfjs.community/u/dev1)\
**Post date:** [November 30, 2023, 7:16am UTC](https://pdfjs.community/t/can-i-set-a-limit-on-initial-page-rendering/2971/1 "2023-11-30T07:16:35Z")

</div>

**Which product are you using?**  
PDF.js Express Plus

**PDF.js Express Version**  
8.7.4

**Detailed description of issue**  
Can I set a limit on initial page rendering? This is to speed up the initial rendering.

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [November 30, 2023, 8:13pm UTC](https://pdfjs.community/t/can-i-set-a-limit-on-initial-page-rendering/2971/3 "2023-11-30T20:13:01Z")

</div>

Hi there,

Thanks for contacting pdf.js express forums,

I believe you are looking for the setPreRenderLevel API:  
[https://pdfjs.express/api/Core.html#.SetPreRenderLevel\_\_anchor](https://pdfjs.express/api/Core.html#.SetPreRenderLevel__anchor)

Best regards,  
Kevin Kim

---

<div class="post-metadata">

**Author:** ![dev1](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@dev1](https://pdfjs.community/u/dev1)\
**Post date:** [December 1, 2023, 2:11am UTC](https://pdfjs.community/t/can-i-set-a-limit-on-initial-page-rendering/2971/4 "2023-12-01T02:11:59Z")

</div>

> [@kkim](#):
>
> setPreRenderLevel API

@kkim thanks.  
I have a few questions.

1. What do the numbers in the setPreRenderLevel API parameters mean? Is it the number of pages?
2. Does setting the parameter to 0 speed up the initial display?
3. What is the disadvantage of setting the parameter to 0?
4. What is the disadvantage of setting the parameter to 10?

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [December 1, 2023, 3:33pm UTC](https://pdfjs.community/t/can-i-set-a-limit-on-initial-page-rendering/2971/5 "2023-12-01T15:33:19Z")

</div>

Hi there,

This is based on our guide:

> **[PDF.js Express Viewer Events | Documentation](https://pdfjs.express/documentation/learn-more/events.8#documentviewer.pagecomplete)**

```javascript
A few extra pages may be prerendered at lower priority, so pageComplete may be called for pages that are not currently visible. You can set the prerender level with the SetPreRenderLevel function.

```

Prerender level to 0 will disable pre-rendering  
Prerender level to 10 can increase memory usage because more pages are being stored in the cache. This could potentially lead to performance issues on devices with limited resources.

It’s recommended to test different pre-render levels to find the optimal balance between performance and memory usage for your specific use case and target devices.

Best regards,  
Kevin Kim

---

<div class="post-metadata">

**Author:** ![dev1](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@dev1](https://pdfjs.community/u/dev1)\
**Post date:** [December 4, 2023, 7:52am UTC](https://pdfjs.community/t/can-i-set-a-limit-on-initial-page-rendering/2971/6 "2023-12-04T07:52:09Z")

</div>

> [@kkim](#):
>
> Prerender level to 0 will disable pre-rendering  
> Prerender level to 10 can increase memory usage because more pages are being stored in the cache. This could potentially lead to performance issues on devices with limited resources.
> 
> It’s recommended to test different pre-render levels to find the optimal balance between performance and memory usage for your specific use case and target devices.

@kkim sorry, I have Questions.

1. Does this mean it only works for PDFs with multiple pages?  
Or does pre-rendering increase the initial display speed for PDFs with only one page?
2. For PDFs that have been loaded once, are they permanently cached to speed up the display?
3. Where is the cache stored?
4. Why didn’t the initial display speed change when I changed the value in the setPreRenderLevel API?

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [December 4, 2023, 3:39pm UTC](https://pdfjs.community/t/can-i-set-a-limit-on-initial-page-rendering/2971/7 "2023-12-04T15:39:02Z")

</div>

Hi there,

setPrerenderLevel will only affect rendering pages before and ahead of the current page.

Any additional loading speed is handled by the pdf.js library:

> [@Can we render pages as soon as loaded from the PDF?](https://pdfjs.community/t/can-we-render-pages-as-soon-as-loaded-from-the-pdf/1409/3):
>
> Hello, I’m Ron, an automated tech support bot robot While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages: Guides: [Best practices for PDF.js Express - Linearize PDF files](https://pdfjs.express/documentation/learn-more/best-practices#linearize-pdf-files)[Core engine for WebViewer - Creating your own UI using WebViewer Core](https://pdfjs.express/documentation/ui-customization/core.8#creating-your-own-ui-using-webviewer-core)[Events for PDF.js Express - Document and annotation rendering - DocumentViewer.pageComplete](https://pdfjs.express/documentation/learn-more/events.8#documentviewer.pagecomplete) APIs: [Core.Document - isLinearized()](https://pdfjs.express/api/Core.Document.html#isLinearized__anchor)[Utils - setCanvasMultiplier(value)](https://pdfjs.express/api/7.0/utils.html#setCanvasMultiplier__anchor)[CoreControls…](https://pdfjs.express/api/7.0/CoreControls.DocumentViewer.html#refreshAll__anchor)

Best regards,  
Kevin Kim
