Как закрыть PDF-файл с помощью Python - PullRequest
0 голосов
/ 11 ноября 2019

Я пытаюсь закрыть PDF-файл с помощью кнопки Tkinter, но не могу найти подходящего решения для моей проблемы. Я использую Raspberry Pi с операционной системой Raspbian

Я пробовал функцию kill(), но мой файл PDF не закрывается.

Вот мой код, чтобы открыть файл PDF

class Thesis():
   self.packet = io.BytesIO()
   self.can = canvas.Canvas(self.packet, pagesize = letter)
   self.can.drawString(250,250, "Hello World")
   self.can.save()

   self. packet.seek(0)
   self.new_pdf = PdfFileReader(self.packet)
   self. existing_pdf = PdfFileReader(open("Sample.pdf", "rb"))
   self.existing _pdf.decrypt('')
   self.output = PdfFileWriter()

   self.page = self.existing_pdf.getPage(0)
   self.page.mergePage(self.new_pdf.getPage(0))

   self.outpute.addPage(self.page)
   self.outputStream = open("destination.pdf", "wb")
   output.write(self.outpuStream)


   self.opener ="open" if sys.platform == "darwin"else "xdg-open"
   subprocess.call([self.opener, "destination.pdf"])

   #create print button
   self.print_root = Toplevel()
   self.print_root.geometry("+910+635")

   self.print_button = Button(self.print_root, text ="Print", width = 10, height = 5, command = self.print_form)
   self.print_button.pack()

   def print_form(self):

      #code to close a pdf file after clicking a print button.
      self.filename = "/home/pi/Thesis/barangay_certification_result.pdf"
      self.p = subprocess.Popen("exec " + filename, stdout=subprocess.PIPE, shell = True)
      self.p.kill()

все, что мне нужно сделать, это полностью закрыть файл pdf, полностью прерванный.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...