Prerequisites
You need pdf.js available as external library on your Simplifier instance:
You need pdf.js available as external library on your Simplifier instance:
Create a client-side Business Object (BO) function call for implementing the logic of the full-text search:
// input: 'base64' (String), 'searchValue' (String)
// output: 'result' (Boolean)
var base64 = oPayload.base64;
base64 = base64.replace("data:application/pdf;base64,", "");
var pdfData = atob(base64);
function searchPage(doc, pageNumber) {
return doc.getPage(pageNumber).then(function(page){
return page.getTextContent();}).then(function(content) {
var text = content.items.map(function(i) {return i.str;}).join('');
var re = new RegExp(oPayload.searchValue);
return re.test(text);});
}
var loading = pdfjsLib.getDocument({data: pdfData});
loading.promise.then(async function(doc) {
var result = false;
for (var i = 1; i <= doc.numPages; i++) {
result = await searchPage(doc, i);
if (result) {
break;
}
}
return result;}).then(function(searchResult) {
fnSuccess({
result: searchResult
})
}).catch(console.error);
Add pdf.js as external library to your Simplifier app (Knowledge Base article):
Create a story for the workflow:
// replace "FileUploader" with the ID of your FileUploader widget var uploaderInput = this.getView().byId("FileUploader"); if (uploaderInput.getValue() !== "") { var files = uploaderInput.oFileUpload.files; if (files.length === 1) { var file = files[0]; } } // create a global variable "uploaderFile" (String) to store the file this.getGlobals().setVar("uploaderFile", file);