Display Pdf in XR mode


Is it possible to display a pdf file in an object texture in XR mode ?


You may use PDF.js to convert PDF to canvas and use it as dynamic texture.

1 Like

Thanks labri for you answer.

It works fine in normal mode but it doesn’t work during a XR session.

Do you now why ?

So the question now is how to make dynamic texture work in XR, am I right?

Yes, if you think that the problem is the dynamic texture :wink:
The use of dynamic texture is different un XR mode ?

I can only make assumptions based on infromation you provided :slight_smile:
If converting PDF to canvas works fine for you but it doesn’t work in XR I suppose there may be some problem with dynamic texture.
In this case you may try to test in XR some simple examples with dynamic textures first.

1 Like

Hi labris,

Below the code that I use.

If I execute this code before entering in VR mode, it works fine and the pdf is displayed when I enter in VR mode.
But when I enter in VR mode and execute this code after it doesn’t work and my mesh disapear…
I suppose that the problen is in the function “page.render”…

Any idea ?

openPdf : function(urlPdf)
	pdfjsLib.getDocument(urlPdf).then((pdf) => {

		pdf.getPage(indexPage).then((page) => {

		var pdfPlane = BABYLON.MeshBuilder.CreatePlane("ground", {width: 0.7, height: 1}, gScene);			

		var viewport = page.getViewport(this.pdfState.zoom);
		var pdfMat = new BABYLON.BackgroundMaterial("pdfMat", gScene);    				
		var pdfTexture = new BABYLON.DynamicTexture("dynamic texture", {width:viewport.width, height:viewport.height}, gScene);
		pdfMat.diffuseTexture = pdfTexture;

		var ctxPdf = pdfTexture.getContext();
		var canvasPdf = pdfTexture.canvas;

		pdfMat.opacityFresnel = false;
		pdfPlane.material = pdfMat;
			canvasContext: ctxPdf,
			viewport: viewport