Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Python 3 PyQt5 Project to Open & Capture Screenshot of URL as PDF Document in Browser

Posted on January 4, 2023

 

 

Welcome folks today in this blog post we will be opening and capturing screenshot of url as pdf document in browser using pyqt5 framework in python. All the full source code of the application is shown below.

 

 

Get Started

 

 

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

 

 

pip install pyqt5

 

 

pip install pyqtwebengine

 

 

And after that you need to make an app.py file and copy paste the following code

 

 

app.py

 

 

Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import sys
from PyQt5.QtCore import QUrl
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWidgets import QApplication
 
app = QApplication(sys.argv)
 
view = QWebEngineView()
view.load(QUrl("http://google.com"))
view.show()
 
def save_pdf():
    view.page().printToPdf("document.pdf")
 
view.loadFinished.connect(save_pdf)
 
sys.exit(app.exec_())

 

 

As you can see we are importing the pyqt5 and pyqtwebengine libraries at the very top and then we are opening a new url inside the browser which is https://www.google.com and then we are converting the url to pdf document and then we are saving the pdf document with the filename called document.pdf. We are loading the remote url using the QUrl widget. Now if you open the app.py file inside the command line as shown below

 

 

python app.py

 

 

 

 

 

 

Recent Posts

  • Node.js Tutorial to Export All Pages of PDF Document to Images and Save it in Javascript
  • Node.js OfficeGen Example to Add Text & Images in Powerpoint Presentation in Javascript
  • Node.js OfficeGen Example to Generate Excel Files By Adding Data inside Cells & Sheets in Javascript
  • Node.js OfficeGen Example to Create Word Docx Files & Add Text Images inside it Using Javascript
  • React.js Twitter API Tutorial to Embed Profile & Timeline, Hashtags of User in Browser Using Javascript
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme