Skip to content

Commit

Permalink
add plugin exporting to filename derived from xopp
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandlo committed Jan 6, 2022
1 parent 7f3799e commit 7a8fc3e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
36 changes: 36 additions & 0 deletions plugins/Export/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
-- Register all Toolbar actions and intialize all UI stuff
function initUi()
app.registerUi({["menu"] = "Export to pdf", ["callback"] = "exportPdf", ["accelerator"] = "<Shift><Alt>p"});
app.registerUi({["menu"] = "Export to svg", ["callback"] = "exportSvg", ["accelerator"] = "<Shift><Alt>s"});
app.registerUi({["menu"] = "Export to png", ["callback"] = "exportPng", ["accelerator"] = "<Shift><Alt>n"});
end

local DEFAULT_PATH = "/tmp/temp" -- change this to get a different default path for xopp-files that have not been saved yet

function exportPdf()
local pdfName = getStem() .. "_export.pdf"
app.export({["outputFile"] = pdfName})
-- use the "range", "background" and "progressiveMode" fields for more customization
end

function exportSvg()
local svgName = getStem() .. "_export.svg"
app.export({["outputFile"] = svgName})
-- use the "range", "background" for more customization
end

function exportPng()
local pngName = getStem() .. "_export.png"
app.export({["outputFile"] = pngName})
-- use the "range", "background" and "pngDpi", "pngWidth" or "pngHeight" fields for more customization
end

function getStem()
local xoppName = app.getDocumentStructure()["xoppFilename"]
if (xoppName ~= "" and xoppName ~= nil) then
return xoppName:match("(.+)%..+$")
else
print("Exporting to default path. Consider saving the xopp-file before exporting! ")
return DEFAULT_PATH
end
end
15 changes: 15 additions & 0 deletions plugins/Export/plugin.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[about]
## Author / Copyright notice
author=Roland Lötscher

description=Export to pdf, svg and png.

## If the plugin is packed with Xournal++, use
## <xournalpp> then it gets the same version number
version=<xournalpp>

[default]
enabled=false

[plugin]
mainfile=main.lua

0 comments on commit 7a8fc3e

Please sign in to comment.