diff --git a/src/Aur/PKGBUILD b/src/Aur/PKGBUILD new file mode 100644 index 0000000..42b467f --- /dev/null +++ b/src/Aur/PKGBUILD @@ -0,0 +1,24 @@ +# Mantenedor: Felipe Alfonso Gonzalez +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" +} diff --git a/src/term-pdf-wrp.c b/src/term-pdf-wrp.c index f68ab42..5e5b594 100644 --- a/src/term-pdf-wrp.c +++ b/src/term-pdf-wrp.c @@ -56,10 +56,27 @@ view and navigate PDF files directly within the terminal. // pkgver=0.0.3.4 +/* #include #include int main() { system("python ./TermPDFViewer-v.0.0.3.4/src/termpdf.py"); return 0; -} \ No newline at end of file +} +*/ + +#include +#include + +int main() { + + FILE *fp = popen("python $HOME/.config/termpdf.py", "r"); + if (fp == NULL) { + perror("Error opening pipe"); + return -1; + } + pclose(fp); + + return 0; +} diff --git a/src/termpdf.py b/src/termpdf.py index 34dc7ca..c9a7ac6 100644 --- a/src/termpdf.py +++ b/src/termpdf.py @@ -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 @@ -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():