Simplifier Makers ClubSimplifier Makers Club
  • Docs
  • Knowledge
  • F.A.Q
  • Forum
  • Courses
  • Marketplace
  • Pricing
  • Login
  • Try for free
  • German
  • English
  • Try for free
  • Docs
  • Knowledge
  • F.A.Q
  • Forum
  • Courses
  • Marketplace
  • Pricing
  • Login
  • Try for free
  • German
  • English
  • Try for free
home/Knowledge Base/How to's/Full-Text Search For PDF Documents

Full-Text Search For PDF Documents

Written by Christian Kleinschroth
April 19, 2021

Prerequisites

You need pdf.js available as external library on your Simplifier instance:

Please refer to this Knowledge Base article to learn how to integrate external libraries.

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 3 – UI Designer: User Input

Use the FileUploader (1) widget, so that the user can select a PDF document to analyze. In addition, add an Input (2) widget for entering the search value. With the ‘search’-Button (3) the user starts the full-text search.

Step 4 – Process Designer: Story

Create a story for the workflow:

  1. Subscribe to ‘search’-Button’s press event
  2. 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);
  3.  Use the ‘readFileAsDataUrl’ function call from the ‘SIMP_FileHelper’ BO to get the base64-String of the selected PDF document
    1. Input: ‘uploaderFile’ (global variable)
    2. Output: ‘base64’ (new global variable, String)
  4. Use your client-side ‘fullTextSearch’ function call from Step 1 to get the result of the full-text search
    1. Input: ‘base64’ (global variable),  search ‘value’ (input widget)
    2. Output: full-text search ‘result’

Step 4 – Result

To display the result you can use an ObjectStatus widget and specify the state and icon property with a condition shape in the process designer (1):

  1. status = ‘Success’ in case of a positive result (true) (2)
  2. status = ‘Error’ in case of a negative result (false) (3)
Tags:designerpdfUIscriptpagetextto

Was this article helpful?

Yes  No
Related Articles
  • How to handle files selected with the FileUploader
  • Fine-tuning and Running Custom AI Models in Simplifier
  • Using the Simplifier Teams App
  • How to integrate value help and suggestions in user inputs
  • How to integrate Simplifier in CI/CD pipelines
  • How to use Google reCAPTCHA v3 Essentials
Leave A Comment Cancel reply

You must be logged in to post a comment.

How to's
  • Full-Text Search For PDF Documents
  • How to integrate and use external libraries in Simplifier Apps
  • Working with Drag and Drop
  • Create Test Cases With The UI5 Test Recorder
  • Full-Text Search For Excel Files
  • How to Implement an Approval App in Simplifier
  • Create a PDF Template via Plugin
  • Generating a PDF with Simplifier via Plugin
  • How to use Query Options in ODataV2 Connector
  • How to use TimePicker widget
  • How to set Simplifier environment variables in Open Shift
  • How to send and receive Push Notifications
  • Dynamic where-clause and repeatable statement
  • Version and Release Management in Simplifier
  • Logs and Monitoring in Simplifier
  • Use the Adobe PDF Embed API in your Simplifier Application
  • PDF Templates: make the Header/Footer content dynamic
  • Converting Text to Speech with the Google TTS Connector
  • Authentication through another window
  • Creating a ChatBot Client for ChatGPT
  • How to use Simplifier Content Repository Plugin
  • How to use Google reCAPTCHA v3 Essentials
  • How to integrate Simplifier in CI/CD pipelines
  • How to integrate value help and suggestions in user inputs
  • Using the Simplifier Teams App
  • Fine-tuning and Running Custom AI Models in Simplifier
  • How to handle files selected with the FileUploader
Knowledgebase Categories
  • Getting Started 4
  • Best Practices 4
  • How to's 27
  • Layout & Design 4
  • Widgets 8
  • Cloud Services 6
  • Database Handling 1
  • Integrations 10
  • Plugins 6
  • Mobile Client 2

  Full-Text Search For Excel Files

Create Test Cases With The UI5 Test Recorder  

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.