Skip to content

PDF

Updated

Shows the pages of a PDF document.

Type
ent-pdf
Script class
PDFEntity
Family
Media

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. With sizing: 'auto', each page instead fits inside width × height, so portrait and landscape pages take the same box.
  • controls: the prev/next pill. Turn it off when a script turns the pages.
  1. Add a PDF entity to the scene and name it, such as Handout.
  2. Set its src to a PDF file.
  3. Set width in metres, and page to the page it should open on.
  4. Keep controls on to let viewers turn pages, or turn it off for a script-driven deck.
  5. Add a Signal Emitter to hear PDF::ready, PDF::page and PDF::error in scripts.

Go forward and back through a slide deck with the arrow keys.

SlideKeys.jx
#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.page reads 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: false hides the built-in pill, since the keys now do its job.

Show “page 3 of 12” on a Text entity next to the document.

PageCounter.jx
#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::ready announces the document and its page count, pages; the first page is not announced again by PDF::page.
  • PDF::page arrives each time another page is shown, from the pill or a page change, with page and pages.
  • A Text entity shows the result; its text prop updates at once.

Advance one page every eight seconds and loop back to the start.

AutoSlides.jx
#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::ready to learn how many pages there are before it starts.
  • delay(next, 8000) calls next after eight seconds; next schedules itself again, so the deck keeps turning.
  • After the last page it goes back to page 1. Pending delay calls 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 no height, pages fit a square of width.

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-transform Required One Position, rotation and scale of the entity, with optional editor-only per-axis locks.
PDF 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

With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.

  • PDF::ready
  • PDF::error
  • PDF::page

Like every entity, it also reports: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.

Run it in the browser, read its scripts, and download it as an XR Creator project.

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.

PDFEntity.jx
#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 });
}