Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use mutool draw for previewing PDFs #494

Closed
mizlan opened this issue Feb 6, 2022 · 3 comments · Fixed by #898
Closed

Use mutool draw for previewing PDFs #494

mizlan opened this issue Feb 6, 2022 · 3 comments · Fixed by #898
Labels
enhancement New feature or request

Comments

@mizlan
Copy link

mizlan commented Feb 6, 2022

MuPDF's mutool draw command produces a decently high-resolution image form of a PDF. It can be specified to only produce an image of the first page, which would be nice for previewing PDFs.

Quick demo (after installing MuPDF):

$ mutool draw -o pdf-preview.png julia-1.5.0.pdf 1 # can add 2>/dev/null
page julia-1.5.0.pdf 1
$ kitty +kitten icat pdf-preview.png

Or directly through stdout:

mutool draw -o - julia-1.5.0.pdf 1 2>/dev/null | kitty +kitten icat
@mizlan mizlan added the enhancement New feature or request label Feb 6, 2022
@xxyxxyxyx1
Copy link

PDF previews would allow me to use broot as my main file browser, I hope it can be added! In addition to mutool, the Kitty icat method may be of interest. It uses ImageMagick to open both images and pdfs. (For a pdf, one generally needs a white background.)
kitty +kitten icat --background white stuff.pdf

@andrej1919
Copy link

PDF previews would allow me to use broot as my main file browser, I hope it can be added! In addition to mutool, the Kitty icat method may be of interest. It uses ImageMagick to open both images and pdfs. (For a pdf, one generally needs a white background.) kitty +kitten icat --background white stuff.pdf

Just discovered Broot. Amazing application. PDF previews are literately the only missing feature.

@Canop
Copy link
Owner

Canop commented Jul 6, 2024

@xxyxxyxyx1 @mizlan @andrej1919 Feedback on #898 would be welcome

Canop added a commit that referenced this issue Jul 13, 2024
This allows defining file transformations that are applied to files before preview.

The default conf has 2 examples: previewing PDF and beautifying JSON: 

```Hjson
preview_transformers: [
     # Use mutool to render any PDF file as an image
     # In this example we use placeholders for the input and output files
     {
         input_extensions: [ "pdf" ] // case doesn't matter
         output_extension: png
         mode: image
         command: [ "mutool", "draw", "-o", "{output-path}", "{input-path}" ]
     }

     # Use jq to beautify JSON
     # In this example, the command refers to neither the input nor the output,
     # so broot pipes them to the stdin and stdout of the jq process
     {
         input_extensions: [ "json" ] 
         output_extension: json
         mode: text
         command: [ "jq" ]
     }
]
```

PDF preview:

![image](https://github.com/Canop/broot/assets/617006/4c140060-573f-4368-b98b-61443f2f56c9)

JSON beautification (the original file has no space nor new line):

![image](https://github.com/Canop/broot/assets/617006/9363bd0e-0ad4-43cc-956d-6d807e40d11c)

Fix #494
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants