Is it possible to add a preview of a document in the Plumsail Form connected to a document library?
Dear @Pieter,
It's very easy to do for PDF files as browser's can render them effortlessly, but not so easy to do for Word, and other Microsoft documents.
Which ones do you need?
Dear @Pieter,
As I've said, the PDF one is super easy - the rendering of a PDF document all handled by the browser. Simply add an HTML control with the following code to the form:
<iframe id='fd_docview' width='1366px' height='623px' frameborder='0'></iframe>
Then, add the following JavaScript to JS editor (change Document Library title to match yours):
fd.spRendered(function() {
var library = pnp.sp.web.lists.getByTitle("Documents");
library.items.select("FileLeafRef", "FileRef").filter("Id eq " + fd.itemId).get().then(function(items) {
$("#fd_docview").attr("src", items[0].FileRef);
});
});
Here's the result:
As for MS Office documents - this will be trickier!
Our developers will have to research this question, and most likely spend some time to write the code. If you're interested and would consider paid support for this feature, write us at support@plumsail.com, we'll estimate the hours needed to make this possible.
Hi, did you manage to release updates to the product enabling preview of office files? I.e. Excel file?
Dear @SamirPateluk,
No such updates and no plans for it in the near future. If there's demand, we might be able to offer paid support, contact us at support@plumsail.com as mentioned above.
Thank you, I will discuss and follow your instructions if needed.
Hi Samir,
i have a solution.
- Set a “Html” Control on the Form. (Name = fd.docview)
- Take this code to JavaScript-Editor an set the right name of the library.
fd.spRendered(function () {
// lokale Variable fĂĽr das iframe-Element
var docViewFrame = document.getElementById("fd_docview");
if (!docViewFrame || !fd.itemId) {
return;
}
var library = pnp.sp.web.lists.getByTitle("Datenschutzdokumente");
library.items
.select("FileRef")
.filter("Id eq " + fd.itemId)
.get()
.then(function (items) {
if (!items || items.length === 0) return;
var fileUrl = items[0].FileRef;
// WOPI-Preview-URL zusammensetzen
var previewUrl =
_spPageContextInfo.webAbsoluteUrl +
"/_layouts/15/WopiFrame.aspx" +
"?sourcedoc=" + encodeURIComponent(fileUrl) +
"&action=embedview";
// iframe src setzen
docViewFrame.src = previewUrl;
});
});




