<commit_before>/* Copyright (c) 2013 The Tagspaces Authors. All rights reserved.
 * Use of this source code is governed by a AGPL3 license that
 * can be found in the LICENSE file. */

define(function(require, exports, module) {
  "use strict";

  console.log("Loading viewerPDF");

  exports.id = "viewerPDF"; // ID should be equal to the directory name where the ext. is located   
  exports.title = "PDF Viewer";
  exports.type = "viewer";
  exports.supportedFileTypes = ["pdf"];

  var TSCORE = require("tscore");

  var extensionDirectory = TSCORE.Config.getExtensionPath() + "/" + exports.id;

  exports.init = function(filePath, elementID) {
    console.log("Initalization Browser PDF Viewer...");
    $('#' + elementID).append($('<iframe>', {
      id: "iframeViewer",
      src: "libs/pdfjs/web/viewer.html?file=" + filePath,
      "nwdisable": "",
      "nwfaketop": ""
    }));
  };

  exports.viewerMode = function() {
    console.log("viewerMode not supported on this extension");
  };

  exports.setContent = function() {
    console.log("setContent not supported on this extension");
  };

  exports.getContent = function() {
    console.log("getContent not supported on this extension");
  };
});<commit_msg>Pdf to text merged from prev branch<commit_after>/* Copyright (c) 2013 The Tagspaces Authors. All rights reserved.
 * Use of this source code is governed by a AGPL3 license that
 * can be found in the LICENSE file. */

define(function(require, exports, module) {
  "use strict";

  console.log("Loading viewerPDF");

  exports.id = "viewerPDF"; // ID should be equal to the directory name where the ext. is located   
  exports.title = "PDF Viewer";
  exports.type = "viewer";
  exports.supportedFileTypes = ["pdf"];

  var TSCORE = require("tscore");
  var TSPRO = require("tspro");
  var extensionDirectory = TSCORE.Config.getExtensionPath() + "/" + exports.id;

  exports.init = function(filePath, elementID) {
    console.log("Initalization Browser PDF Viewer...");
    if (TSPRO.available) {
      exports.getTextContent(filePath, function(content) {
        TSPRO.saveTextContent(filePath, content);
      });
    }
    $('#' + elementID).append($('<iframe>', {
      id: "iframeViewer",
      src: "libs/pdfjs/web/viewer.html?file=" + filePath,
      "nwdisable": "",
      "nwfaketop": ""
    }));
  };

  exports.viewerMode = function() {
    console.log("viewerMode not supported on this extension");
  };

  exports.setContent = function() {
    console.log("setContent not supported on this extension");
  };

  exports.getContent = function() {
    console.log("getContent not supported on this extension");
  };

  var pdfToText = function(file) {

    PDFJS.workerSrc = 'libs/pdfjs/build/pdf.worker.js';
    return PDFJS.getDocument(file).then(function(pdf) {
      var pages = [];
      for (var i = 0; i < pdf.numPages; i++) {
        pages.push(i);
      }
      return Promise.all(pages.map(function(pageNumber) {
        return pdf.getPage(pageNumber + 1).then(function(page) {
          return page.getTextContent().then(function(textContent) {
            return textContent.items.map(function(item) {
              return item.str;
            }).join(' ');
          });
        });
      })).then(function(pages) {
        return pages.join("\r\n");
      });
    }, function(error) {
      console.log("Failed! " + error);
    });
  };

  exports.getTextContent = function(file, loaded) {
    pdfToText(file).then(function(result) {
      loaded(result);
    });
  };
});
{'fraction_non_alphanumeric': 0.14938937801760863, 'fraction_numerical': 0.003408122692416927, 'mean_word_length': 3.1338028169014085, 'pattern_counts': {'":': 4, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4799806', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1053, 'n_words': 263}