File size: 1,685 Bytes
be53a00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function initUi()
  app.registerUi({["menu"] = "Xournal++ HTR", ["callback"] = "run", ["accelerator"] = "<Control>F1"});
end

function save_file(path)
  if path:len() > 0 then

    -- Read settings: I use this (https://stackoverflow.com/a/41176958). An
    -- alternative could have been https://stackoverflow.com/a/41176826. Both
    -- found using G"lua read settings file".
    local config = require "config"

    config.filename = '"' .. app.getDocumentStructure()['xoppFilename'] .. '"'
    config.output_file = '"' .. path .. '"'

    command = config.python_executable .. " " .. config.xournalpp_htr_path
              .. " -if " .. config.filename
              .. " -of " .. config.output_file
    if config.debug_HTR_command then
      print(command)
    else
      os.execute(command)
    end

  end
end

function run()

  document_structure = app.getDocumentStructure()

  if document_structure['xoppFilename']:len() == 0 then
    app.openDialog('Please save document prior to exporting it as searchable PDF!', {"Ok"}, "", true)
  else
    app.fileDialogSave("save_file", "untitled.pdf")
  end

end

-- TODO: Think of workflow to maximise usability for user
-- TODO: How to store settings? Ideally permanently?
-- TODO: Interesting code from example plugins:
--   - Get filename: https://github.com/xournalpp/xournalpp/blob/master/plugins/Export/main.lua#L29
--   - Toggle logic: https://github.com/xournalpp/xournalpp/blob/master/plugins/HighlightPosition/main.lua#L5
--   - UI: https://github.com/xournalpp/xournalpp/blob/master/plugins/MigrateFontSizes/main.lua
--   - OS interaction: https://github.com/xournalpp/xournalpp/blob/master/plugins/QuickScreenshot/main.lua