'Opening up a PDF with Adobe Lightbox Embed API through clicking a link

I'm fairly new to website development and I would like to know how to get this script to run after clicking a link on a page.

<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: "<YOUR_CLIENT_ID>"});
        adobeDCView.previewFile({
            content:{location: {url: "https://documentcloud.adobe.com/view-sdk-demo/PDFs/Summary.pdf"}},
            metaData:{fileName: "Summary.pdf"}
        }, {embedMode: "LIGHT_BOX"});
    });
</script>

The page would have several links to different PDF's so I know to alter the pdf link within the script accordingly. Any help would be greatly appreciated...



Solution 1:[1]

Don't add the code to the sdk.ready event, add it to a button click event instead.

document.getElementById("MyButton").addEventListener('click', function() 
{
    var adobeDCView = new AdobeDC.View(
        {
            clientId: "<YOUR_CLIENT_ID>"
        }
    );

    adobeDCView.previewFile(
        {
            content: {
                promise: Promise.resolve(arrayBuffer)
            },
            metaData: {
                fileName: "TheNameOfMyFile.pdf"
            }
        },
        {
            embedMode: "LIGHT_BOX"
        }
    );
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Steepho