I am trying to use a combination of scripts to achieve this task, and I am really close to the solution I think. The idea is to have a web page for newsletters that uses Adobe View SDK as the pdf viewer, and to control the correct document to load in the viewer with a button click. The effect can be viewed on my test web page Here When you click on the image under May 4, 2020, it invokes my function called “changeDoc” and sends the string value for “docName”, which is the part that needs to be changed for each different newsletter. My function also changes the display style of my modal element to “block” and my instance of the View SDK is in the content of the modal. This brings the viewer onto the screen the way I want it to.
I have added a footer to my modal for testing purposes, that shows the value of the docName variable after the button click, and this proves that the string value is being changed properly. (Footer appears on lower left of the modal window.) Also for testing purposes I have added a line into the View SDK script to assign a string value to the variable “newDoc” and altered the url in the content of the script to use this variable, and the viewer works and loads the correct document…
My challenge is - I have not been able to get the variable value assigned with my onclick event to the variable referenced in the View SDK script. With my limited grasp of javascript I just don’t know the right process and syntax to use in order to get this to happen. Here is the code that is used in the link I referenced above:
<button id="CSS-050420" onclick="changeDoc('Newsletter_050420');"></button>
<script type="text/javascript">
function changeDoc(docName) {
document.getElementById("showstring").innerHTML = docName;
document.getElementById('viewerModal').style.display='block';
}
</script>
And here is the code for the View SDK with my changes for the “newName” variable:
<script type="text/javascript">
document.addEventListener("adobe_dc_view_sdk.ready", function(){
var newName = "Newsletter_050420";
var adobeDCView = new AdobeDC.View({clientId: "06179511ab964c9284f1b0887eca1b46", divId: "adobe-dc-view"});
adobeDCView.previewFile({
content:{location: {url: "https://www.shcsfarmington.org/" + newName + ".pdf"}},
metaData:{fileName: "Newsletter_050420.pdf"}
}, {embedMode: "FULL_WINDOW", defaultViewMode: "FIT_WIDTH"});
});
</script>
So the goal is to pass my string variable “docName” and assign it to the “newName” variable in the viewer script. I have tried several ways, but none have been successful. All help will be appreciated. Thanks.