Xournal Plugins for Students

Plugins I've written for using Xournal to study

#Lua#Projects

Xournal

Xournal++ is a program for handwriting notes, available for PC and mobile. I enjoy using it for annotating PDFs and lecture slides, doing homework that requires writing or maths and taking mock exams. But while doing so, I have found I'm missing some features that I would like to see in Xournal. Luckily, Xournal has an interface for writing plugins in Lua and makes it easy to install and use them. Xournal is also open source, but so far, the plugin interface is sufficient for my purposes.

My Plugins

Here are the Plugins I have written for myself and am still using:

Batch Toggle Grid

Xournal lets you change the background of your PDF, for example to checkered or lined paper. For studying, I am either using the checkered or blank paper. Sometimes I want to switch between these two. However, I have only found a built-in way to change the background of one page at a time instead of all pages of my document. Now, I can do this with my plugin.

-- Register all Toolbar actions and intialize all UI stuff function initUi() ref = app.registerUi({["menu"] = "Batch Toggle Grid", ["callback"] = "exampleCallback", ["accelerator"] = "<Control>b"}); print("Example plugin registered\n"); end local toggleState = false -- Callback if the menu item is executed function exampleCallback() --- result = app.msgbox("Test123", {[1] = "Yes", [2] = "No"}); --- print("result = " .. result) local docStructure = app.getDocumentStructure() local numPages = #docStructure["pages"] local page = docStructure["currentPage"] local background = "a" if toggleState == true then background = "graph"; else background = "plain"; end toggleState = not toggleState for i=1, numPages do app.setCurrentPage(i) app.changeCurrentPageBackground(background); end app.setCurrentPage(page) --- result = app.msgbox(app.getStrokes(), {[1] = "Yes", [2] = "No"}); end

Batch Horizontal

The same goes for rotating the page 180 degrees. Sometimes, I need more horizontal space while writing but created a portrait oriented document. If I want to rotate my pages by 90 degrees, I have to do so for each page. Here comes my plugin.

-- Register all Toolbar actions and intialize all UI stuff function initUi() ref = app.registerUi({["menu"] = "Batch Horizontal", ["callback"] = "exampleCallback", ["accelerator"] = "<Control>t"}); end -- Callback if the menu item is executed function exampleCallback() --- result = app.msgbox("Test123", {[1] = "Yes", [2] = "No"}); --- print("result = " .. result) local docStructure = app.getDocumentStructure() local numPages = #docStructure["pages"] local page = docStructure["currentPage"] local width = docStructure["pages"][page]["pageWidth"] local height = docStructure["pages"][page]["pageHeight"] for i=1, numPages do app.setCurrentPage(i) app.setPageSize(height, width) end app.setCurrentPage(page) -- app.uiAction({["action"]="ACTION_TOOL_SELECT_RECT"}) --- result = app.msgbox(app.getStrokes(), {[1] = "Yes", [2] = "No"}); end

Page Progress Plugin

Studying can be a pain in the ass, especially if you have merged all your lecture slides or worksheets for a subject and you're trying to wrestle through a thousand page long document. It's useful to see how far you've come and want to know how much you've progressed in the document. Therefore, I've written a plugin that calculates the percentage of slides you've already scrolled through.

-- Register all Toolbar actions and intialize all UI stuff function initUi() print("Hello from Example: Plugin initUi called\n"); ref = app.registerUi({["menu"] = "Print Progress", ["callback"] = "printProgress", ["accelerator"] = "<Control>l"}); print("Menu reference:"); end local filename = ".xppbm" -- Callback if the menu item is executed function printProgress() --- print("result = " .. result) local docStructure = app.getDocumentStructure() local numPages = #docStructure["pages"] local page = docStructure["currentPage"] result = app.msgbox("Page " .. tostring(page) .. "/" .. tostring(numPages) .. ", " .. tostring((page/numPages)*100) .."%", {[1] = "Ok"}); end

Bookmark Pages

I'm not sure if this is a bug or intended behaviour, but on my device, Xournal does not remember the current page when I close and reopen a document. (This is very annoying in said long documents.) I've written a plugin that lets you bookmark the current page and gives you the option to jump to it, even after reopening the document.

-- Register all Toolbar actions and intialize all UI stuff function initUi() ref = app.registerUi({["menu"] = "Save Current Page", ["callback"] = "onW", ["accelerator"] = "<Control>w"}); ref = app.registerUi({["menu"] = "Go To Bookmarked Page", ["callback"] = "onI", ["accelerator"] = "<Control>i"}); end local filename = ".xppbm" -- Callback if the menu item is executed function exampleCallback() result = app.msgbox("Test123", {[1] = "Yes", [2] = "No"}); --- print("result = " .. result) local docStructure = app.getDocumentStructure() local numPages = #docStructure["pages"] local page = docStructure["currentPage"] while( true ) do os.execute("timeout " .. tonumber(3)) --result = app.msgbox("Hallo!", {[1] = "Yes", [2] = "No"}); end saveCurrentPage() scrollToSavedPage() end function onW() local docStructure = app.getDocumentStructure() if docStructure["currentPage"]~=1 then saveCurrentPage() else scrollToSavedPage() end end function onI() local filereader, err = (io.open(filename, "r")) filereader:close() if filereader then scrollToSavedPage() else saveCurrentPage() end end function scrollToSavedPage() local filereader, err = (io.open(filename, "r")) if filereader then local t = filereader:read("*all") local loadedpagenumber = tonumber(t) app.scrollToPage(loadedpagenumber) end filereader:close() end function saveCurrentPage() local docStructure = app.getDocumentStructure() local f, err = (io.open(filename, "w")) local page = docStructure["currentPage"] f:write(tostring(page)) f:close() end

Comments

Feel free to leave your opinion or questions in the comment section below.