Skip to main content
Participating Frequently
February 19, 2021
Question

Displaying Multiple PDFs on the Same Page

  • February 19, 2021
  • 3 replies
  • 3595 views

I have a page containing five policies, each one a PDF, and I want to display them in an accordion where expanding each one brings up the corresponding embedded PDF using PDF Embed API.  I've tried changing the name of the variable and the ID of the div, but only the first PDF shows, and the rest are blank.

 

How is this accomplished?

    This topic has been closed for replies.

    3 replies

    Participating Frequently
    June 17, 2021

    Surely there is a way to pass it dynamically instead of having to create one for every pdf? What if there are many pdfs on a page..in my case I wanted to have a list of pdfs that will open in a modal when clicked, but not have to create this code for each one.  I'm not sure how to pass the pdf url..but I'm thinking there must be some way to do it.

    Participant
    February 12, 2023

    Button to trigger the popup of a modal.

     

     

    <button type="button" class="btn btn-success" onclick="openModal('http://example.com/sample.pdf', 'sample.pdf');">

     

     

    Use a looping logic in the HTML view to load multiple buttons for multiple file support.

     

    On click event of one of the buttons, pass the URL endpoint, and the File name of the PDF document as arguments to openModal method

     

     

     

    <script>
        var viewer;
    
        function openModal(endpoint, name) {
            // Show the modal
            document.getElementById("modal_id").style.display = "block";
    
            viewer = new AdobeDC.View({
                clientId: 'XXX-XXX-XXX,
                divId: "adobe-dc-view"
            });
    
            // Load the PDF document into the viewer
            viewer.previewFile({
                content: {
                    location: {
                        url: endpoint
                    }
                },
                metaData: {
                    fileName: name
                }
            }, {
                embedMode: "SIZED_CONTAINER",
                showFullScreen: true
            });
        }
    
        function closeModal() {
          // Hide the modal
          document.getElementById("modal_id").style.display = "none";
    
          // Destroy the viewer
          viewer.destroy();
        }
      </script>

     

     

    The function initializes the Adobe Document Cloud View SDK, loads the PDF document into the viewer, and displays the modal. When you click the "Close" button in the modal, the closeModal method is called, which hides the modal and destroys the viewer

    Adobe Employee
    March 25, 2021

    Hi, Thanks for trying out PDF Embed API. Ideally, it should work by creating a new object of AdobeDC.View for each of the PDFs. It would be great for us to debug if you can share your snippet or website.

    FWSBethAuthor
    Participating Frequently
    March 25, 2021

    I'm using the standard recommended code:

    <div id="adobe-dc-view" style="width: 100%;"></div>
    <p><script src="https://documentcloud.adobe.com/view-sdk/main.js"></script> <script type="text/javascript">
      document.addEventListener("adobe_dc_view_sdk.ready", function(){ 
        var adobeDCView = new AdobeDC.View({clientId: "--client id removed-", divId: "adobe-dc-view"});
        adobeDCView.previewFile({
          content:{location: {url: "<span id="tb-shortcode-6" data-tb-shortcode-id="6" class="tb-fields-and-text-shortcode-render tb-fields-and-text-shortcode-render-types"><!-- TBINNERSTART 6 -->Loading…<!-- TBINNEREND 6 --></span>"}},
          metaData:{fileName: "Committee File"}
        }, {embedMode: "IN_LINE"});
      });
      </script>

    I just need to know how to manipulate the code to make multiple iterations work on one page.  How do I create a new object?

     

    Thanks for your help. 

    Thebeefeater
    Participant
    March 25, 2021

    Did you figure this out?

    FWSBethAuthor
    Participating Frequently
    March 25, 2021

    No, I had to use a different PDF embedder.  Shame because Adobe's is so nice.  Wish someone would help a girl out lol.