web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : PC6D22EDKIh+AvoZljtIUP
Power Pages - Design & Build
Unanswered

View a PDF file in Power Pages

Like (0) ShareShare
ReportReport
Posted on 30 Apr 2024 06:11:35 by 48

Hello everyone,

 

I have an issue that I hope someone can help with!

 

I would really like to be able to display a PDF file on my Power Pages. So far, I have uploaded my PDF as a Webfile under Power Pages Management.

marierasmu123_0-1714457184283.png

Then, I have tried to find a code for pdf.js and define this code, but without success. I have copied the link from this webfile and inserted it into the code.

marierasmu123_1-1714457458961.png

 

Can anyone help me with how to get my PDF displayed?

Categories:
I have the same question (0)
  • DubeDubeD0 Profile Picture
    2 on 02 May 2024 at 11:14:05
    Re: View a PDF file in Power Pages

    The simplest way to display a pdf is embed in HTML. Use the webfile path or any full url (just make sure CORS is configured).

     

    <embed src="/PowerPlatform.pdf" width="100%" height="1000px" type="application/pdf">

     


    You can do similar with Adobe Webforms (fillable PDFs) using simple embed codes.

     

    If you are looking to use PDF.js you just need to import it, then call it. You can test in console in dev tools extension to see how it reacts, put the canvas on the page somewhere:

     

    <canvas id="the-canvas"></canvas>

     

    Then Import in console: import('//mozilla.github.io/pdf.js/build/pdf.mjs') you would put the below in the head of your site if actually publishing:

    <script src="//mozilla.github.io/pdf.js/build/pdf.mjs" type="module"></script>

    Then run script by either publishing or running from devtools:

     

    // If absolute URL from the remote server is provided, configure the CORS
     // header on that server.
     var url = '/PowerPlatform.pdf';
    
     // Loaded via <script> tag, create shortcut to access PDF.js exports.
     var { pdfjsLib } = globalThis;
    
     // The workerSrc property shall be specified.
     pdfjsLib.GlobalWorkerOptions.workersrc='//mozilla.github.io/pdf.js/build/pdf.worker.mjs';
    
     // Asynchronous download of PDF
     var loadingTask = pdfjsLib.getDocument(url);
     loadingTask.promise.then(function(pdf) {
     console.log('PDF loaded');
    
     // Fetch the first page
     var pageNumber = 1;
     pdf.getPage(pageNumber).then(function(page) {
     console.log('Page loaded');
    
     var scale = 1.5;
     var viewport = page.getViewport({scale: scale});
    
     // Prepare canvas using PDF page dimensions
     var canvas = document.getElementById('the-canvas');
     var context = canvas.getContext('2d');
     canvas.height = viewport.height;
     canvas.width = viewport.width;
    
     // Render PDF page into canvas context
     var renderContext = {
     canvasContext: context,
     viewport: viewport
     };
     var renderTask = page.render(renderContext);
     renderTask.promise.then(function () {
     console.log('Page rendered');
     });
     });
     }, function (reason) {
     // PDF loading error
     console.error(reason);
     });

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

MS.Ragavendar – Community Spotlight

We are honored to recognize Ragavendar Swaminatha Subramanian as our September…

Leaderboard > Power Pages

#1
Jon Unzueta Profile Picture

Jon Unzueta 82 Super User 2025 Season 2

#2
Fubar Profile Picture

Fubar 55 Super User 2025 Season 2

#3
Shafiuddin Profile Picture

Shafiuddin 45

Last 30 days Overall leaderboard

Featured topics

Loading complete