Updated
Shows the pages of a PDF document.
- Type
ent-pdf- Script class
PDFEntity- Family
- Media
Overview
Section titled “Overview”A PDF entity shows the pages of a PDF document on a plane in the world: a menu on a stand, a handout, a slide deck you page through. It shows one page at a time, and for documents with more than one page a small prev/next pill under the page lets viewers turn pages. The pill works in the editor too, so you can pick the starting page while authoring.
By default the plane is width metres wide and as tall as the page’s shape makes it: a portrait A4 page at width 1.2 is about 1.7 tall. The page is drawn unlit and visible from both sides.
Pick a sibling when it fits better: an Image for a single picture, or Text for short words that change from a script.
The props that matter most, on its PDF component (PDFComponent in scripts):
src: the document, as a URL or an asset from your project.page: the page shown, counted from 1. Setting it turns the page; a value past the end shows the last page.width: the plane’s width in metres. Withsizing: 'auto', each page instead fits insidewidth×height, so portrait and landscape pages take the same box.controls: the prev/next pill. Turn it off when a script turns the pages.
Set it up
Section titled “Set it up”- Add a PDF entity to the scene and name it, such as
Handout. - Set its
srcto a PDF file. - Set
widthin metres, andpageto the page it should open on. - Keep
controlson to let viewers turn pages, or turn it off for a script-driven deck. - Add a Signal Emitter to hear
PDF::ready,PDF::pageandPDF::errorin scripts.
Examples
Section titled “Examples”Turn pages with the keyboard
Section titled “Turn pages with the keyboard”Go forward and back through a slide deck with the arrow keys.
#pragma lifecycle(startup, update)
// Scene: a PDF entity "Slides".let slides;
function startup() { slides = findEntity('Slides').getComponent(PDFComponent); slides.setProps({ page: 1, controls: false });}
function update() { const page = slides.props.page; if (Input.keyboard.isKeyReleased(Key.ArrowRight)) slides.setProps({ page: page + 1 }); if (Input.keyboard.isKeyReleased(Key.ArrowLeft) && page > 1) slides.setProps({ page: page - 1 });}How it works:
slides.props.pagereads the current page;setProps({ page })shows another one.- Past the last page, the value is stored as the last page, so pressing right at the end does nothing harmful. The script keeps the page at 1 or above itself.
controls: falsehides the built-in pill, since the keys now do its job.
A page counter
Section titled “A page counter”Show “page 3 of 12” on a Text entity next to the document.
#pragma lifecycle(startup)
// Scene: a PDF entity "Handout" with a Signal Emitter on the signal 'handout',// and a Text entity "Page Label".let label;
function show(page, pages) { label.setProps({ text: `Page ${page} of ${pages}` });}
function startup() { label = findEntity('Page Label').getComponent(TextComponent);
on('handout', (event) => { if (event.eventType === EventType.PDF.Ready) { show(findEntity(event.entityId).getComponent(PDFComponent).props.page, event.data.pages); } else if (event.eventType === EventType.PDF.Page) { show(event.data.page, event.data.pages); } else if (event.eventType === EventType.PDF.Error) { label.setProps({ text: 'Document unavailable' }); } });}How it works:
PDF::readyannounces the document and its page count,pages; the first page is not announced again byPDF::page.PDF::pagearrives each time another page is shown, from the pill or apagechange, withpageandpages.- A Text entity shows the result; its
textprop updates at once.
A self-running presentation
Section titled “A self-running presentation”Advance one page every eight seconds and loop back to the start.
#pragma lifecycle(startup)
// Scene: a PDF entity "Deck" with a Signal Emitter on the signal 'deck'.let deck;let pages = 1;
function next() { const page = deck.props.page < pages ? deck.props.page + 1 : 1; deck.setProps({ page: page }); delay(next, 8000);}
function startup() { deck = findEntity('Deck').getComponent(PDFComponent);
on('deck', (event) => { if (event.eventType !== EventType.PDF.Ready) return; pages = event.data.pages; delay(next, 8000); });}How it works:
- The script waits for
PDF::readyto learn how many pages there are before it starts. delay(next, 8000)callsnextafter eight seconds;nextschedules itself again, so the deck keeps turning.- After the last page it goes back to page 1. Pending
delaycalls stop when the script stops.
- The pill writes the new page into
page, so the page is saved, and with a Networkable on the entity everyone in the room sees the same page. - With
sizing: 'auto'and noheight, pages fit a square ofwidth.
Components
Section titled “Components”What a new PDF is made of. Required components are always present and cannot be removed; the others can. Per entity says whether an entity can hold one of that component or several. Layer, Lock and Enable are on every placed entity, and Transform holds its position, rotation and scale.
| Component | Type | Role | Per entity | What it does |
|---|---|---|---|---|
| Layer | comp-layer |
Required | One | Puts the entity on a render/raycast layer so cameras and rays can include or skip it. |
| Lock | comp-lock |
Required | One | Editor-only flag that stops the entity from being selected or moved. |
| Enable | comp-enable |
Required | One | Turns the entity and its children on or off: hides them and stops their behavior. |
| Transform | comp- |
Required | One | Position, rotation and scale of the entity, with optional editor-only per-axis locks. |
comp-pdf |
Required | One | Shows the pages of a PDF document. |
You can also add 18 optional components, such as Animation Graph, Animation Timeline, Attribution, Billboard, Enable On Signal, Follow Target.
The settings of a new entity, as the runtime creates it. Change them in the Properties panel of XR Creator, or from a script with getComponent(…).setProps({ … }).
| Prop | Default | Range |
|---|---|---|
width |
1.2 |
0 ≤ x ≤ 10000 |
page |
1 |
1 ≤ x ≤ 9007199254740991 |
controls |
true |
Events
Section titled “Events”With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.
PDF::readyPDF::errorPDF::page
Like every entity, it also reports: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.
Live example
Section titled “Live example”Run it in the browser, read its scripts, and download it as an XR Creator project.
A presenter's screen shows a PDF slide deck; the left and right arrow keys turn its pages, stopping at the first and last, with the page count read from the PDF::ready event.
Click the view, then press the right and left arrow keys to turn the pages. The arrow keys do not move the camera here; drag to orbit, scroll to zoom.
From a script
Section titled “From a script”Find the entity by its name, check its class, and work with its components. Name the entity in the Hierarchy first; this example expects My PDF.
#pragma lifecycle(startup)
function startup() { // Find the entity by the name it has in the Hierarchy. const entity = findEntity('My PDF'); if (!(entity instanceof PDFEntity)) return;
// Its PDF component holds the settings listed under Props. const component = entity.getComponent(PDFComponent); log('width is', component.props.width); component.setProps({ width: 1.8 });}