Script - Cognitive PDF/A

Cognitive PDF/A is a powerful tool  Cognitive Forms which it makes PDF/A ISO standard documents from scanned document images. OpenKM integrate Compressimo transparently using automation or crontab utilities.

  • Input server folder where images are stored at systemFolder = "c:\\samples"
  • The cognitivePdf  variable is the Cognitive PDF/A server path.
  • The OpenKM path where compressimo files are imported String path = "/okm:root/imported" + "/" + uploadFile.getName()

import java.io.*;
import java.util.*;
import com.openkm.module.db.stuff.DbSessionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.openkm.bean.Document;
import com.openkm.api.OKMDocument;
 
String token = DbSessionManager.getInstance().getSystemToken();
String systemFolder = "c:\\samples";
String cognitivePdfa = "C:\\Users\\openkm\\Desktop\\cpdfa-1.4.4-dev-win32-1month\\cpdfa\\bin\\cpdfacli.exe splitdummy eng ";
Logger log = LoggerFactory.getLogger("com.openkm.compressimo");
 
// Loading files
log.info("***** Process BEGIN *****");
File folder = new File(systemFolder);
File[] listOfFiles = folder.listFiles();
 
for (int i=0; i<listOfFiles.length; i++) {
    File file = listOfFiles[i];
 
    if (file.isFile() && file.getName().toLowerCase().endsWith(".tif")) {
        // Converting tif file to pdf
        String tifFile =  systemFolder + "\\" + file.getName();
        String pdfFile =  systemFolder + "\\" + file.getName().toLowerCase().replace(".tif", ".pdf");
        log.info("Converting file:" + tifFile+" to:"+pdfFile);
        String command = cognitivePdfa + tifFile + " " + pdfFile;
        Process process = Runtime.getRuntime().exec(command);
 
        BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String line = null;
 
        while ((line=input.readLine()) != null) {
            log.info(line);
        }
 
        int exitVal = process.waitFor();
        log.info("Exit code " + exitVal);

        // Upload PDF file
        File uploadFile = new File(pdfFile);
        Document doc = new Document();
        String path = "/okm:root/imported" + "/" + uploadFile.getName();
        log.info("Importing file:"+ pdfFile + " to:"+path);
        doc.setPath(path);
        FileInputStream fis = new FileInputStream(uploadFile);
        doc = OKMDocument.getInstance().create(token, doc, fis);
        fis.close();

        // Deleting pdf File
        uploadFile.delete();
    }
}
 
log.info("***** Process END *****");

For more information:

Images

Scanned files

Red square remark initial document size.

Crontab compressimo Importer task

 

OpenKM log server output of the importer task execution

Imported files into OpenKM

PDF/A compliance

Search engine results by content