Python Tkinter GUI Script to Load and View PDF Document Using tkPDFViewer Library Full Project For Beginners

Python Tkinter GUI Script to Load and View PDF Document Using tkPDFViewer Library Full Project For Beginners

 

 

Welcome folks today in this post we will be displaying pdf file inside tkinter application using the tkPDFViewer library. All the full source code of the application is shown below.

 

 

 

Get Started

 

 

 

In order to get started you need to install the following library using the pip command as shown below

 

pip install tkinter

 

pip install tkPDFViewer

 

After installing all these libraries now make an app.py file and copy paste the following code

]

app.py

 

 

# Importing tkinter to make gui in python 
from tkinter import*
  
# Importing tkPDFViewer to place pdf file in gui. 
# In tkPDFViewer library there is 
# an tkPDFViewer module. That I have imported as pdf 
from tkPDFViewer import tkPDFViewer as pdf 
  
# Initializing tk 
root = Tk() 
  
# Set the width and height of our root window. 
root.geometry("550x750") 
  
# creating object of ShowPdf from tkPDFViewer. 
v1 = pdf.ShowPdf() 
  
# Adding pdf location and width and height. 
v2 = v1.pdf_view(root, 
                 pdf_location = r"##locationofpdfile##.pdf",  
                 width = 50, height = 100) 
  
# Placing Pdf in my gui. 
v2.pack() 
root.mainloop()

 

See also  Top Python Data Science Books Every Data Scientist Must Read For Building Data Intensive Application Using Machine Learning in Python

 

Now in the above python script just replace the path of the input pdf file that needs to be displayed inside the pdf viewer

 

Now if you run this python script app.py by typing the following command

 

python app.py

 

 

 

 

Leave a Reply