Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">

# office.yazi
# office.yazi (gk fix)
### A plugin to preview office documents in <a href="https://github.com/sxyazi/yazi">Yazi <img src="https://github.com/sxyazi/yazi/blob/main/assets/logo.png?raw=true" alt="a duck" width="24px" height="24px"></a>

<img src="https://github.com/macydnah/office.yazi/blob/assets/preview_test.gif" alt="preview test" width="88%">
Expand Down
30 changes: 20 additions & 10 deletions main.lua → init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,40 @@ end
function M:doc2pdf(job)
local tmp = "/tmp/yazi-" .. ya.uid() .. "/" .. ya.hash("office.yazi") .. "/"

--[[ For Future Reference: Regarding `libreoffice` as preconverter
--[[ For Future Reference: Regarding `libreoffice` as preconverter
1. It prints errors to stdout (always, doesn't matter if it succeeded or it failed)
2. Always writes the converted files to the filesystem (so no Mario|Bros|Piping|Magic|To>stdout) --]]

local libreoffice = Command("libreoffice")
:args({
"--headless",
"--convert-to",
"pdf:draw_pdf_Export:{" ..
"\"PageRange\":{" ..
"\"type\":\"string\"," ..
"\"value\":" .. "\"" .. job.skip + 1 .. "\"" ..
"}" ..
"}",
"pdf:draw_pdf_Export",
"--convert-to",
"pdf:draw_pdf_Export:{"
.. '"PageRange":{'
.. '"type":"string",'
.. '"value":'
.. '"'
.. job.skip + 1
.. '"'
.. "}"
.. "}",
"--outdir",
tmp,
tostring(job.file.url)
tostring(job.file.url),
})
:stdin(Command.NULL)
:stdout(Command.PIPED)
:stderr(Command.NULL)
:output()

if not libreoffice.status.success then
ya.err(libreoffice.stdout:match("LibreOffice .+"):gsub("%\n.*", "") .. " " .. libreoffice.stdout:match("Error .+"):gsub("%\n.*", ""))
ya.err(
libreoffice.stdout:match("LibreOffice .+"):gsub("%\n.*", "")
.. " "
.. libreoffice.stdout:match("Error .+"):gsub("%\n.*", "")
)
return nil, Err("Failed to preconvert `%s` to a temporary PDF", job.file.name)
end

Expand Down