Skip to content

Commit 077faac

Browse files
authored
feat: respect the user's max_width setting for the built-in PDF preloader (#2331)
1 parent f506849 commit 077faac

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

yazi-plugin/preset/plugins/pdf.lua

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,18 @@ function M:preload(job)
3030
return true
3131
end
3232

33+
-- stylua: ignore
3334
local output, err = Command("pdftoppm")
3435
:args({
36+
"-f", job.skip + 1,
37+
"-l", job.skip + 1,
3538
"-singlefile",
36-
"-jpeg",
37-
"-jpegopt",
38-
"quality=" .. PREVIEW.image_quality,
39-
"-f",
40-
job.skip + 1,
39+
"-jpeg", "-jpegopt", "quality=" .. PREVIEW.image_quality,
40+
"-tiffcompression", "jpeg",
41+
"-scale-to-x", PREVIEW.max_width, "-scale-to-y", "-1",
4142
tostring(job.file.url),
43+
tostring(cache),
4244
})
43-
:stdout(Command.PIPED)
4445
:stderr(Command.PIPED)
4546
:output()
4647

@@ -54,7 +55,12 @@ function M:preload(job)
5455
return true, Err("Failed to convert PDF to image, stderr: %s", output.stderr)
5556
end
5657

57-
return fs.write(cache, output.stdout)
58+
local ok, err = os.rename(string.format("%s.jpg", cache), tostring(cache))
59+
if ok then
60+
return true
61+
else
62+
return false, Err("Failed to rename `%s.jpg` to `%s`, error: %s", cache, cache, err)
63+
end
5864
end
5965

6066
return M

0 commit comments

Comments
 (0)