@@ -0,0 +1,2197 @@
+package org.cbsa.api.controller.search;%0A%0Aimport java.io.File;%0Aimport java.io.FileInputStream;%0Aimport java.io.IOException;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport org.apache.pdfbox.cos.COSDocument;%0Aimport org.apache.pdfbox.io.RandomAccessBuffer;%0Aimport org.apache.pdfbox.pdfparser.PDFParser;%0Aimport org.apache.pdfbox.pdmodel.PDDocument;%0Aimport org.apache.pdfbox.pdmodel.PDPage;%0Aimport org.apache.pdfbox.text.PDFTextStripper;%0Aimport org.cbsa.api.model.PageCard;%0Aimport org.cbsa.api.model.ResultCard;%0A%0Apublic class PageByPageSearch %7B%0A%0A    public List%3CResultCard%3E findpages(String path,%0A            List%3CString%3E searchKeywordList) throws IOException %7B%0A%0A        int i; // page no.%0A        boolean hasKeywords = false;%0A%0A        PDDocument finalDocument = new PDDocument();%0A        List%3CPDPage%3E pageList = new ArrayList%3CPDPage%3E();%0A%0A        File file = new File(path);%0A        PDFParser parser = new PDFParser(new RandomAccessBuffer(%0A                new FileInputStream(file)));%0A        parser.parse();%0A%0A        COSDocument cosDoc = parser.getDocument();%0A        PDFTextStripper reader = new PDFTextStripper();%0A        PDDocument doc = new PDDocument(cosDoc);%0A%0A        List%3CResultCard%3E list = new ArrayList%3CResultCard%3E();%0A%0A        for (i = 0; i %3C= doc.getNumberOfPages(); i++) %7B%0A            reader.setStartPage(i);%0A            reader.setEndPage(i);%0A            hasKeywords = true;%0A%0A            for (String keyword : searchKeywordList) %7B%0A%0A                if (!reader.getText(doc).contains(keyword)) %7B%0A                    hasKeywords = false;%0A                    break;%0A                %7D%0A            %7D%0A%0A            if (hasKeywords) %7B%0A%0A                ResultCard result = new PageCard();%0A                result.setFileContent(reader.getText(doc));%0A                result.setFilePath(path);%0A                result.setPageNumber(i);%0A                list.add(result);%0A                pageList.add(doc.getPage(i));%0A            %7D%0A%0A        %7D%0A%0A        for (PDPage page : pageList) %7B%0A            finalDocument.addPage(page);%0A        %7D%0A%0A        finalDocument.save(%22/opt/dataset/results/final.pdf%22);%0A        finalDocument.close();%0A        System.out.println(%22Saved%22);%0A%0A        return list;%0A%0A    %7D%0A%7D%0A

Split and Merge combined to PageByPage Content Search