Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d9b252e

Browse files
Merge pull request avinashkranjan#1147 from viraldevpb/DownloadPage-asPdf
DownloadPage-asPdf
2 parents 029ddcb + 8c49e4c commit d9b252e

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

‎Download-page-as-pdf/Readme.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Download Page as PDF:
2+
3+
Download a page as a PDF .
4+
5+
#### Required Modules :
6+
- pyppdf
7+
```bash
8+
pip3 install pyppdf
9+
```
10+
- pyppyteer
11+
```bash
12+
pip3 install pyppeteer
13+
```
14+
15+
#### Examples of use :
16+
- Download a page:
17+
```bash
18+
python download-page-as-pdf.py -l 'www.pudim.com.br'
19+
```
20+
21+
- Download a page and give a pdf name:
22+
```bash
23+
python download-page-as-pdf.py -l 'http://www.pudim.com.br' -n 'pudim.pdf'
24+
```

‎Download-page-as-pdf/main.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/python
2+
# -*- coding: UTF-8 -*-
3+
4+
import argparse
5+
import pyppdf
6+
import re
7+
from pyppeteer.errors import PageError, TimeoutError, NetworkError
8+
9+
10+
def main():
11+
parser = argparse.ArgumentParser(description = 'Page Downloader as PDF')
12+
parser.add_argument('--link', '-l', action = 'store', dest = 'link',
13+
required = True, help = 'Inform the link to download.')
14+
parser.add_argument('--name', '-n', action = 'store', dest = 'name',
15+
required = False, help = 'Inform the name to save.')
16+
17+
arguments = parser.parse_args()
18+
19+
url = arguments.link
20+
21+
if not arguments.name:
22+
name = re.sub(r'^\w+://', '', url.lower())
23+
name = name.replace('/', '-')
24+
else:
25+
name = arguments.name
26+
27+
if not name.endswith('.pdf'):
28+
name = name + '.pdf'
29+
30+
print(f'Name of the file: {name}')
31+
32+
try:
33+
pyppdf.save_pdf(name, url)
34+
except PageError:
35+
print('URL could not be resolved.')
36+
except TimeoutError:
37+
print('Timeout.')
38+
except NetworkError:
39+
print('No access to the network.')
40+
41+
if __name__ == '__main__':
42+
main()

‎Download-page-as-pdf/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pyppdf==0.1.2
2+
pyppeteer==0.2.2

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /