A Simple tool to convert pdf pages on images quickly on markdown document.
pdf.nvim
is a NeoVim plugin designed to convert PDF files to images within NeoVim. It provides a convenient way to process PDF files directly from your editor, leveraging pdftoppm
for conversion.
- NeoVim (0.9 or later)
- plenary.nvim
pdftoppm
command-line utility that is included inpoppler
software Poppler
{
"paysancorrezien/pdf.nvim",
ft = "markdown",
dependencies = {
"nvim-lua/plenary.nvim",
},
config = function()
require("pdf").setup({
pdf_path = "~/Obsidian/Vault/Files/",
image_path = "~/Obsidian/Vault/Images/",
pdftoppm_path = "/usr/bin/pdftoppm",
link_pattern = "(.-)%[(.-)%]%((.-)%.pdf#page=(%d+)%)",
new_link_format = function(prefix, text, generated_image_file)
return prefix .. "[" .. text .. "](" .. generated_image_file .. ")"
end,
-- Add any other configuration options here
})
end,
}
All the configuration options are configured on previous setup
pdf_path
: The path to your PDF files. Default:"/path/to/pdf/"
image_path
: The path where the converted images should be stored. Default:"/path/to/images/"
pdftoppm_path
: The path to thepdftoppm
utility. Default:"/usr/bin/pdftoppm"
link_pattern
: The Lua pattern used to identify PDF links in your files. Default:"(.-)%[(.-)%]%((.-)%.pdf#page=(%d+)%)"
new_link_format
: A function to format the new link after conversion. Acceptsprefix
,text
, andgenerated_image_file
as arguments.
Once configured, you can use the following command in NeoVim to convert a PDF link to an image on the current line:
When you are on a line with a link like this [apdf](pdfname.pdf#page=10)
:ConvertPdfToImg
This will convert the specific page to an image, put it in defined directory and replace the pdf link with the image link.
To check that the settings are correctly applied :
:lua require('pdf').conf()