PDFview.nvim is a Neovim plugin designed for users who want to open, view, and navigate PDF documents directly within Neovim. It is particularly useful for those who want to integrate their workflow with Obsidian or other note-taking systems, allowing you to quickly open PDFs, extract text, and navigate through pages, all from within Neovim.
- Open PDF Files: Use Telescope to quickly search and open PDF files.
- Extract Text: Extract the text from a PDF using
pdftotext
for easy reading or note-taking. - Pagination: Navigate through the document using next/previous page commands.
- Customizable Pagination: Set how many lines per page should be displayed.
- Virtual Text Display: See page numbers displayed in the buffer.
- Neovim version 0.5 or higher
- Telescope.nvim: The plugin uses Telescope to search for PDF files.
- pdftotext: This plugin relies on the
pdftotext
command-line tool to extract text from PDFs. Installpdftotext
using the following command:sudo apt install poppler-utils
To install PDFview.nvim
using LazyVim, add the following configuration to your Neovim setup:
{
"basola21/PDFview",
lazy = false,
dependencies = { "nvim-telescope/telescope.nvim" }
}
You can add the following key mappings to your Neovim configuration for easy navigation through the PDF pages:
-- Navigate to the next page in the PDF
map("n", "<leader>jj", "<cmd>:lua require('pdfview.renderer').next_page()<CR>", { desc = "PDFview: Next page" })
-- Navigate to the previous page in the PDF
map("n", "<leader>kk", "<cmd>:lua require('pdfview.renderer').previous_page()<CR>", { desc = "PDFview: Previous page" })
-
Opening a PDF File
Use the following command to open a PDF:require('pdfview').open()
This will open Telescope's file finder, allowing you to search for PDF files in your project or system.
-
Navigating Pages
Use the defined key mappings to navigate between pages:<leader>jj
for the next page.<leader>kk
for the previous page.
-
Extracting Text from a PDF
When you select a PDF using Telescope, the plugin extracts the text usingpdftotext
and displays it in a buffer, allowing for easy reading or note-taking. -
Adding Autocmd
Add these lines in your nvim config to open pdf's with PDFview:vim.api.nvim_create_autocmd("BufReadPost", { pattern = "*.pdf", callback = function() local file_path = vim.api.nvim_buf_get_name(0) require("pdfview").open(file_path) end, })
The default lines per page are set to 50
. You can change this value by modifying the lines_per_page
variable in the renderer.lua
file.
- Improved Navigation: Refine the pagination and scrolling behavior for a smoother reading experience.
- Customization: Add options for setting default configurations like
lines_per_page
and buffer options. - Document Search: Implement a search feature to find specific text within the PDF.
- Improved Structure: Enhance the project structure for better maintainability and scalability.
Contributions are welcome! Feel free to open issues or submit pull requests to help improve the plugin.
- Fork the repository.
- Create a new branch (
git checkout -b feature/my-feature
). - Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature/my-feature
). - Open a pull request.
This project is licensed under the MIT License.
If you encounter any issues or have feature requests, please open an issue in the GitHub repository.
Enjoy using PDFview.nvim for your Neovim-based PDF viewing and note-taking workflow!