Skip to content

Commit

Permalink
Merge pull request #75 from felipealfonsog/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
felipealfonsog authored Oct 17, 2023
2 parents 7f5971c + f05c94f commit 034255b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/Aur/PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Mantenedor: Felipe Alfonso Gonzalez <[email protected]>
pkgname=term-pdf
pkgver=0.0.3.5
pkgrel=1
pkgdesc="TermPDF Viewer is an open-source PDF file viewer designed to run in the terminal."
arch=('x86_64')
url="https://github.com/felipealfonsog/TermPDFViewer"
license=('MIT')
depends=('python-pip' 'python-pymupdf')
source=("https://github.com/felipealfonsog/TermPDFViewer/archive/refs/tags/v.${pkgver}.tar.gz")
sha256sums=('edadcca6626f9bd839816c72df90d331ecd8f1af0604628ea2d167eeb9548461')

prepare() {
tar xf "v.${pkgver}.tar.gz" -C "$srcdir" --strip-components=1
# cp "$srcdir"/term-pdf-wrp.c "$srcdir"/TermPDFViewer-v."$pkgver"/src/
}
build() {
cd "$srcdir"/TermPDFViewer-v."${pkgver}"
gcc -o term-pdf-wrp "$srcdir"/TermPDFViewer-v."${pkgver}"/src/term-pdf-wrp.c
}
package() {
install -Dm755 "$srcdir"/TermPDFViewer-v."${pkgver}"/term-pdf-wrp "${pkgdir}/usr/bin/term-pdf"
install -Dm644 "$srcdir"/TermPDFViewer-v."${pkgver}"/src/termpdf.py "${pkgdir}/$HOME/.config/termpdf.py"
}
19 changes: 18 additions & 1 deletion src/term-pdf-wrp.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,27 @@ view and navigate PDF files directly within the terminal.

// pkgver=0.0.3.4

/*
#include <stdio.h>
#include <stdlib.h>
int main() {
system("python ./TermPDFViewer-v.0.0.3.4/src/termpdf.py");
return 0;
}
}
*/

#include <stdio.h>
#include <stdlib.h>

int main() {

FILE *fp = popen("python $HOME/.config/termpdf.py", "r");
if (fp == NULL) {
perror("Error opening pipe");
return -1;
}
pclose(fp);

return 0;
}
31 changes: 31 additions & 0 deletions src/termpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def scan_pdf_files():
pdf_files = [file for file in os.listdir('.') if file.lower().endswith('.pdf')]
return pdf_files

'''
def display_pdf(pdf_filename):
doc = fitz.open(pdf_filename)
total_pages = doc.page_count
Expand All @@ -81,6 +82,36 @@ def display_pdf(pdf_filename):
break
doc.close()
'''

def display_pdf(pdf_filename):
try:
doc = fitz.open(pdf_filename)
total_pages = doc.page_count
current_page = 0

while True:
if not (0 <= current_page < total_pages):
print("Invalid page number.")
break

page = doc[current_page]
print(f'Page {current_page + 1} / {total_pages}')
print(page.get_text())

choice = input("Enter 'b' to go back, 'f' to go forward, 'q' to quit: ")
if choice == 'b':
current_page = max(current_page - 1, 0)
elif choice == 'f':
current_page = min(current_page + 1, total_pages - 1)
elif choice == 'q':
break
except Exception as e:
print(f"Error: {e}")
finally:
if 'doc' in locals():
doc.close()


def main():

Expand Down

0 comments on commit 034255b

Please sign in to comment.