Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c837181
feat: make feature configurable via opts
MadKuntilanak Jul 8, 2026
e0921e8
docs(readme): update README with new configuration options and keymaps
MadKuntilanak Jul 9, 2026
9f0aa53
add preview demo
MadKuntilanak Jul 9, 2026
0960145
fix(readme): typo
MadKuntilanak Jul 9, 2026
9b334eb
feat: implement bookmark and improve keymap configs
MadKuntilanak Jul 9, 2026
66da9d4
feat: add automatic picker detection and fallback
MadKuntilanak Jul 9, 2026
050ef4f
feat: implement search functionality
MadKuntilanak Jul 13, 2026
1406113
fix(pickers): trim selected entries before lookup
MadKuntilanak Jul 14, 2026
946a050
ref(pickers): extract search cache helper
MadKuntilanak Jul 14, 2026
085e6cb
feat(pickers): add `telescope` picker
MadKuntilanak Jul 14, 2026
c885ea0
fix: guard clauses, buffer safety, and namespace cleanup
MadKuntilanak Jul 14, 2026
9a6da91
fix(telescope): correct result count display
MadKuntilanak Jul 14, 2026
69cacf1
feat(picker): improve caching mechanism, improve fallback handling
MadKuntilanak Jul 14, 2026
029746b
feat(pickers): add `snacks` picker
MadKuntilanak Jul 14, 2026
b467a6e
feat: implement text search
MadKuntilanak Jul 14, 2026
43f1268
ref(search): reuse cached pages from render state, add notify
MadKuntilanak Jul 14, 2026
ef71ad2
feat: add 'q' keybinding to close search indicator
MadKuntilanak Jul 14, 2026
e1e786a
ref(ui): use dynamic padding and remove a hardcoded value
MadKuntilanak Jul 14, 2026
94c6494
ref: improve command naming and menu organization
MadKuntilanak Jul 14, 2026
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
126 changes: 113 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@

## Features

- **Open PDF Files**: Use Telescope to quickly search and open PDF files.
- **Open PDF Files**: Quickly search and open PDF files using the currently supported pickers: `telescope.nvim`, `fzf-lua`, or the built-in `vim.ui.select`.
- **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.
- **Bookmarks**: Save your reading position with a bookmark and jump back to it anytime.


<img width="800" height="495" alt="260709-14-22-34" src="https://github.com/user-attachments/assets/20ce5aa0-ffca-4972-9ca4-501736de00ac" />


![Preview](https://i.imgur.com/ClDZhnc.gif)

---

Expand All @@ -22,8 +26,12 @@
### Prerequisites

- **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. Install `pdftotext` using the following command:
- **Picker**: **Telescope.nvim** (optional), **Fzf-lua** (optional), or the **default** picker (`vim.ui.select`)
- **[Zathura](https://github.com/pwmt/zathura)**: document viewer
```bash
sudo apt install zathura
```
- **pdftotext**: this plugin relies on the `pdftotext` command-line tool to extract text from PDFs. Install it using the following command:
```bash
sudo apt install poppler-utils
```
Expand All @@ -35,16 +43,57 @@ To install `PDFview.nvim` using **LazyVim**, add the following configuration to
```lua
{
"basola21/PDFview",
lazy = false,
dependencies = { "nvim-telescope/telescope.nvim" }
}
event = "VeryLazy",
dependencies = {
"nvim-telescope/telescope.nvim"
},
opts = {
path = "/path/to/pdf_folder", -- path pdf folder
save = "/path/to/save_folder", -- bookmark save folder
picker = "default", -- fzf-lua, telescope, default (using vim.ui.select)
open = {
cb = nil,
},
window = {
winhighlight = nil,
},
keymaps = {
menu = "<CR>",
go_to_page = "gf",
show_page_in_zathura = "<Leader>x",
next_page = "<a-n>",
prev_page = "<a-p>",
bookmark = "b",
save = "s",
},
keys = {
{
"<Leader>fp",
function()
require("pdfview").select_file_pdf()
end,
desc = "Select pdf file",
},
{
"<Leader>fP",
function()
require("pdfview").menu()
end,
desc = "Open menu",
},
},
},
```

### Mappings

You can add the following key mappings to your Neovim configuration for easy navigation through the PDF pages:
The `next_page` and `prev_page` keymaps are already set up for you in the `opts.keymaps` table above.
However, if you'd rather define your own custom keys instead of using the built-in ones, you can call the underlying functions directly:

```lua
-- Open menu pdfview
map("n", "<leader>ff", "<cmd>:lua require('pdfview').menu()<CR>", { desc = "PDFview: Menu" })

-- Navigate to the next page in the PDF
map("n", "<leader>jj", "<cmd>:lua require('pdfview.renderer').next_page()<CR>", { desc = "PDFview: Next page" })

Expand All @@ -59,14 +108,16 @@ map("n", "<leader>kk", "<cmd>:lua require('pdfview.renderer').previous_page()<CR
1. **Opening a PDF File**
Use the following command to open a PDF:
```lua
require('pdfview').open()
require("pdfview").select_file_pdf()
-- or
require("pdfview").menu()
```
This will open Telescope's file finder, allowing you to search for PDF files in your project or system.

2. **Navigating Pages**
Use the defined key mappings to navigate between pages:
- `<leader>jj` for the next page.
- `<leader>kk` for the previous page.
- `<a-n>` or `<leader>jj` for the next page.
- `<a-p>` or `<leader>kk` for the previous page.

3. **Extracting Text from a PDF**
When you select a PDF using Telescope, the plugin extracts the text using `pdftotext` and displays it in a buffer, allowing for easy reading or note-taking.
Expand All @@ -86,14 +137,63 @@ map("n", "<leader>kk", "<cmd>:lua require('pdfview.renderer').previous_page()<CR

## Configuration

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.
### Support callback

You can define a custom callback function (`open.cb`) that gets triggered whenever a PDF is opened, receiving the PDF's file path as an argument. This is useful for integrating with other plugins, for example, automatically sending the opened PDF to codecompanion.nvim for translation or summarization.

Example using `codecompanion.nvim`:

```lua

... -- default config
open = {
cb = function(pdf_path)
vim.api.nvim_input ":CodeCompanion /translator_role <CR>"
end,
},
```

### Support Statusline

Example using `heirline.nvim`:

```lua
local get_pdfview = function()
if not pdfview then
local ok, session = pcall(require, "pdfview.renderer")
if ok then
pdfview = session
end
end
return pdfview
end


...

{
...
provider = function()
if vim.bo.filetype == "pdfview" then
if not pdfview then
pdfview = get_pdfview()
end

local pdf_render = pdfview.get()
if pdf_render and pdf_render.pdf_path then
return vim.fn.fnamemodify(pdf_render.pdf_path, ":~") .. " (Page " .. pdf_render.current_page .. ")"
end
end
end,
}

```

---

## Planned Features

- **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.

Expand Down
11 changes: 11 additions & 0 deletions TODO.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* TODO
- [x] define bookmark save path
- [x] implement bookmark menu
- [x] implement bookmark saving
- [x] implement last bookmark

- [X] implement text search
- [ ] implement snacks picker
- [ ] implement toggle case_sensitive
- [ ] implement popup search status
- [ ] update readme
51 changes: 51 additions & 0 deletions lua/pdfview/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
local M = {}

---@type PDFviewCfg
M.defaults = {
path = vim.fn.stdpath "config",
save = vim.fn.stdpath "state",
picker = "default",
open = {
cb = nil,
},
window = {
winhighlight = nil,
text_search_indicator = {
sep_front = "",
sep_back = "",
hl = "WarningMsg",
attr = "fg",
icon = " ",
},
},
keymaps = {
menu = "<CR>",
go_to_page = "gf",
show_page_in_zathura = "<Leader>x",
next_page = "<a-n>",
prev_page = "<a-p>",
open_bookmark = "b",
save_bookmark = "s",
search = "<C-s>",
pick_search = "<Leader>s",
next_search_text = "<C-n>",
prev_search_text = "<C-p>",
},
}

---@param cfg_tbl PDFviewCfg
---@param opts PDFviewCfg
local function merge_settings(cfg_tbl, opts)
opts = opts or {}
local def = vim.tbl_deep_extend("force", cfg_tbl, opts)
return def
end

---@param opts PDFviewCfg
function M.update_settings(opts)
opts = opts or {}

M.defaults = merge_settings(M.defaults, opts)
end

return M
Loading