[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ghostscripts in python with watchdog

I'm trying to use ghostscripts with python watchdog.

I want to duplicate the last page of a pdf to another directory using the
same name as the source pdf + page number.

So watchdog will monitor the directory for the pdf and ghostscript will copy
the last page to another directory.

I have this, and not able to figure out how to change the output name and


import sys

import os

import time

import logging

from watchdog.observers import Observer

from import LoggingEventHandler

from import PatternMatchingEventHandler


if __name__ == "__main__":

    patterns = "*"

    ignore_patterns = ""

    ignore_directories = False

    case_sensitive = True

    my_event_handler = PatternMatchingEventHandler(patterns,
ignore_patterns, ignore_directories, case_sensitive)

    def on_created(event):

        number_of_pages = 4

        input_pdf = event.src_path

        for i in range(4, number_of_pages +1):

            os.system("gswin64c -q -dBATCH -dNOPAUSE

                    " -dFirstPage={page} -dLastPage={page}"

                    " -sDEVICE=pdfwrite {input_pdf}"

                    .format(page=i, input_pdf=input_pdf))


    my_event_handler.on_created = on_created


    path = "."

    go_recursively = True

    my_observer = Observer()

    my_observer.schedule(my_event_handler, path, recursive=go_recursively)




        while True:


    except KeyboardInterrupt: