I've been requested to prepare a form to fill some field when uploading a pdf on a document library.
Added a text field and marked as mandatory do the tricks pretty well, but I need to display the uploaded pdf as well.
I thought to add an iframe to do this. If I simply add an iframe with static pdf in a script editor webpart this is working, but when I try to do in a dynamic way I started to face several issues. the edit form is giving me the id while iframe needs the path.
I'm pretty new in javascript, and searching around I assembled from other sources the following code that does the trick and displays the pdf, but it is hiding the fields. (I think because it is loading another page). Is there a way to accomplish what I need without installing office web apps?
If not I'm going to build a custom webapp. Thank you in advance.
<script language="javascript" type="text/javascript">
JSRequest.EnsureSetup();
var q = JSRequest.QueryString["ID"];
var requestUri = _spPageContextInfo.webAbsoluteUrl +
"/_api/web/lists/getByTitle('Documents')/items?$select=EncodedAbsUrl&$filter=Id eq " + q;
var requestHeaders = {
"accept": "application/json;odata=verbose"
}
$.ajax({
url: requestUri,
type: 'GET',
dataType: 'json',
headers: requestHeaders,
success: function (data)
{
$.each(data.d.results, function(i,result) {
var path = result.EncodedAbsUrl;
var extension = path.toLowerCase().slice(-3);
if (extension == "pdf"){
document.write('<iframe frameBorder="0" width="530" height="700" src="' + path + '" /></iframe>');
}
});
},
error: function ajaxError(response) {
alert(response.status + ' ' + response.statusText);
}
});
</script>