Prerequisites
You need pdf.js available as external library on your Simplifier instance:
Step 1 – Client-side Business Object
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);
Step 2 – Application Editor: Add pdf.js As External Library
Add pdf.js as external library to your Simplifier app (Knowledge Base article):
Step 4 – Process Designer: Story
Create a story for the workflow:
- Subscribe to ‘search’-Button’s press event
- Extract file from FileUploader using a script block:
// 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);
- Use the ‘readFileAsDataUrl’ function call from the ‘SIMP_FileHelper’ BO to get the base64-String of the selected PDF document
- Use your client-side ‘fullTextSearch’ function call from Step 1 to get the result of the full-text search