Created
October 14, 2024 13:09
-
-
Save bschne/00604c47016408e38d529b03881e44f5 to your computer and use it in GitHub Desktop.
PDF to Clipboard Text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Extracts text from a PDF file and copies it to clipboard | |
| # This relies on pdftotext, which you can install via "brew install poppler" | |
| # pbcopy is available by default on macOS, but if you're on linux, this won't work | |
| ptxt() { | |
| if [[ -z "$1" ]]; then | |
| echo "Usage: ptxt <path_to_pdf>" | |
| return 1 | |
| fi | |
| local pdf_path="$1" | |
| # Check if the file exists | |
| if [[ ! -f "$pdf_path" ]]; then | |
| echo "Error: File '$pdf_path' not found." | |
| return 1 | |
| fi | |
| # Convert PDF to text and copy to clipboard | |
| pdftotext "$pdf_path" - | pbcopy | |
| if [[ $? -eq 0 ]]; then | |
| echo "Text from '$pdf_path' has been copied to the clipboard." | |
| else | |
| echo "Failed to convert '$pdf_path' to text." | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment