Skip to content

Commit 5e2d501

Browse files
committed
Webpage To PDF Script Added
1 parent 1b83024 commit 5e2d501

File tree

11 files changed

+302
-0
lines changed

11 files changed

+302
-0
lines changed

Webpage To PDF/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Convert Webpage o PDF File
2+
[![forthebadge](https://forthebadge.com/images/badges/built-with-grammas-recipe.svg)](https://forthebadge.com)
3+
[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com)
4+
[![forthebadge](https://forthebadge.com/images/badges/made-with-python.svg)](https://forthebadge.com)
5+
[![forthebadge](https://forthebadge.com/images/badges/powered-by-water.svg)](https://forthebadge.com)
6+
7+
The python script converts the webpage to pdf file
8+
9+
What the program does?
10+
- Takes single URL as input at the same time
11+
- Converts the page into PDF file
12+
13+
### Requirements
14+
>Python3.6+
15+
>
16+
> wkhtmltopdf in the same directory
17+
>
18+
> pip install -r requirements.txt
19+
20+
21+
### Usage
22+
```
23+
get_links.py [-h] -u URL
24+
25+
Download Images From Webpage
26+
27+
optional arguments:
28+
-h, --help show this help message and exit
29+
-u URL URL to extract links from
30+
```
31+
32+
### Contribution
33+
Any kind of contributions are welcome
34+
1. Fork the project
35+
2. Commit your changes
36+
3. Open a pull request
37+
38+

Webpage To PDF/html2pdf.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import argparse
2+
import pdfkit
3+
4+
5+
def converter(url, filename):
6+
path_wkthmltopdf = "wkhtmltopdf/bin/wkhtmltopdf.exe"
7+
config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
8+
9+
pdfkit.from_url(url, filename, configuration=config)
10+
11+
12+
def main():
13+
parser = argparse.ArgumentParser(description='Convert Webpage To PDF')
14+
15+
# Argument is to input the url to download images from
16+
parser.add_argument('-u', dest='url', type=str, help='URL to convert to PDF', required=True)
17+
18+
# Argument is to input the url to download images from
19+
parser.add_argument('-f', dest='file', type=str, help='Filename of the PDF', required=True)
20+
21+
args = parser.parse_args()
22+
23+
if args.url:
24+
25+
url = args.url
26+
27+
# Check if the url starts with wither http or https
28+
if not url.startswith("http") and not url.startswith("https"):
29+
# Add the https in front of the url
30+
url = "https://" + url
31+
32+
# Call to the function
33+
filename = str(args.file)
34+
35+
if filename.endswith('.pdf'):
36+
converter(url, filename)
37+
38+
else:
39+
print(f"The Extension Of Fil Should be .pdf, you entered: {filename}")
40+
41+
42+
if __name__ == '__main__':
43+
main()

Webpage To PDF/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pdfkit==0.6.1
28.5 MB
Binary file not shown.
28.5 MB
Binary file not shown.
28.4 MB
Binary file not shown.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2010 wkhtmltopdf authors
3+
*
4+
* This file is part of wkhtmltopdf.
5+
*
6+
* wkhtmltopdf is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* wkhtmltopdf is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with wkhtmltopdf. If not, see <http: *www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef __WKHTMLTOPDF_DLLBEGIN__
21+
#define __WKHTMLTOPDF_DLLBEGIN__
22+
23+
#if defined _WIN32 || defined __CYGWIN__
24+
#ifdef BUILDING_DLL
25+
#define DLL_PUBLIC __declspec(dllexport)
26+
#else
27+
#define DLL_PUBLIC __declspec(dllimport)
28+
#endif
29+
#define DLL_LOCAL
30+
#else
31+
#if __GNUC__ >= 4
32+
#define DLL_PUBLIC __attribute__ ((visibility("default")))
33+
#define DLL_LOCAL __attribute__ ((visibility("hidden")))
34+
#else
35+
#define DLL_PUBLIC
36+
#define DLL_LOCAL
37+
#endif
38+
#endif
39+
40+
#if defined _WIN32
41+
#define CALLTYPE __stdcall
42+
#else
43+
#define CALLTYPE
44+
#endif
45+
46+
#ifdef __cplusplus
47+
#define CAPI(type) extern "C" DLL_PUBLIC type CALLTYPE
48+
#else
49+
#define CAPI(type) DLL_PUBLIC type CALLTYPE
50+
#endif
51+
52+
#endif /*__WKHTMLTOPDF_DLLBEGIN__*/
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2010 wkhtmltopdf authors
3+
*
4+
* This file is part of wkhtmltopdf.
5+
*
6+
* wkhtmltopdf is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* wkhtmltopdf is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with wkhtmltopdf. If not, see <http: *www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifdef __WKHTMLTOPDF_DLLBEGIN__
21+
22+
#undef __WKHTMLTOPDF_DLLBEGIN__
23+
#undef DLL_PUBLIC
24+
#undef DLL_LOCAL
25+
#undef CAPI
26+
#undef CALLTYPE
27+
28+
#endif /*__WKHTMLTOPDF_DLLBEGIN__*/
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2010 wkhtmltopdf authors
3+
*
4+
* This file is part of wkhtmltopdf.
5+
*
6+
* wkhtmltopdf is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* wkhtmltopdf is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with wkhtmltopdf. If not, see <http: *www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef __IMAGE_H__
21+
#define __IMAGE_H__
22+
#include <wkhtmltox/dllbegin.inc>
23+
24+
struct wkhtmltoimage_global_settings;
25+
typedef struct wkhtmltoimage_global_settings wkhtmltoimage_global_settings;
26+
27+
struct wkhtmltoimage_converter;
28+
typedef struct wkhtmltoimage_converter wkhtmltoimage_converter;
29+
30+
typedef void (*wkhtmltoimage_str_callback)(wkhtmltoimage_converter * converter, const char * str);
31+
typedef void (*wkhtmltoimage_int_callback)(wkhtmltoimage_converter * converter, const int val);
32+
typedef void (*wkhtmltoimage_void_callback)(wkhtmltoimage_converter * converter);
33+
34+
CAPI(int) wkhtmltoimage_init(int use_graphics);
35+
CAPI(int) wkhtmltoimage_deinit();
36+
CAPI(int) wkhtmltoimage_extended_qt();
37+
CAPI(const char *)wkhtmltoimage_version();
38+
39+
CAPI(wkhtmltoimage_global_settings *) wkhtmltoimage_create_global_settings();
40+
41+
CAPI(int) wkhtmltoimage_set_global_setting(wkhtmltoimage_global_settings * settings, const char * name, const char * value);
42+
CAPI(int) wkhtmltoimage_get_global_setting(wkhtmltoimage_global_settings * settings, const char * name, char * value, int vs);
43+
44+
CAPI(wkhtmltoimage_converter *) wkhtmltoimage_create_converter(wkhtmltoimage_global_settings * settings, const char * data);
45+
CAPI(void) wkhtmltoimage_destroy_converter(wkhtmltoimage_converter * converter);
46+
47+
CAPI(void) wkhtmltoimage_set_warning_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_str_callback cb);
48+
CAPI(void) wkhtmltoimage_set_error_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_str_callback cb);
49+
CAPI(void) wkhtmltoimage_set_phase_changed_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_void_callback cb);
50+
CAPI(void) wkhtmltoimage_set_progress_changed_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_int_callback cb);
51+
CAPI(void) wkhtmltoimage_set_finished_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_int_callback cb);
52+
CAPI(int) wkhtmltoimage_convert(wkhtmltoimage_converter * converter);
53+
/* CAPI(void) wkhtmltoimage_begin_conversion(wkhtmltoimage_converter * converter); */
54+
/* CAPI(void) wkhtmltoimage_cancel(wkhtmltoimage_converter * converter); */
55+
56+
CAPI(int) wkhtmltoimage_current_phase(wkhtmltoimage_converter * converter);
57+
CAPI(int) wkhtmltoimage_phase_count(wkhtmltoimage_converter * converter);
58+
CAPI(const char *) wkhtmltoimage_phase_description(wkhtmltoimage_converter * converter, int phase);
59+
CAPI(const char *) wkhtmltoimage_progress_string(wkhtmltoimage_converter * converter);
60+
CAPI(int) wkhtmltoimage_http_error_code(wkhtmltoimage_converter * converter);
61+
CAPI(long) wkhtmltoimage_get_output(wkhtmltoimage_converter * converter, const unsigned char **);
62+
63+
#include <wkhtmltox/dllend.inc>
64+
#endif /*__IMAGE_H__*/
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2010 wkhtmltopdf authors
3+
*
4+
* This file is part of wkhtmltopdf.
5+
*
6+
* wkhtmltopdf is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* wkhtmltopdf is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with wkhtmltopdf. If not, see <http: *www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef __PDF_H__
21+
#define __PDF_H__
22+
#include <wkhtmltox/dllbegin.inc>
23+
24+
struct wkhtmltopdf_global_settings;
25+
typedef struct wkhtmltopdf_global_settings wkhtmltopdf_global_settings;
26+
27+
struct wkhtmltopdf_object_settings;
28+
typedef struct wkhtmltopdf_object_settings wkhtmltopdf_object_settings;
29+
30+
struct wkhtmltopdf_converter;
31+
typedef struct wkhtmltopdf_converter wkhtmltopdf_converter;
32+
33+
typedef void (*wkhtmltopdf_str_callback)(wkhtmltopdf_converter * converter, const char * str);
34+
typedef void (*wkhtmltopdf_int_callback)(wkhtmltopdf_converter * converter, const int val);
35+
typedef void (*wkhtmltopdf_void_callback)(wkhtmltopdf_converter * converter);
36+
37+
CAPI(int) wkhtmltopdf_init(int use_graphics);
38+
CAPI(int) wkhtmltopdf_deinit();
39+
CAPI(int) wkhtmltopdf_extended_qt();
40+
CAPI(const char *) wkhtmltopdf_version();
41+
42+
CAPI(wkhtmltopdf_global_settings *) wkhtmltopdf_create_global_settings();
43+
CAPI(void) wkhtmltopdf_destroy_global_settings(wkhtmltopdf_global_settings *);
44+
45+
CAPI(wkhtmltopdf_object_settings *) wkhtmltopdf_create_object_settings();
46+
CAPI(void) wkhtmltopdf_destroy_object_settings(wkhtmltopdf_object_settings *);
47+
48+
CAPI(int) wkhtmltopdf_set_global_setting(wkhtmltopdf_global_settings * settings, const char * name, const char * value);
49+
CAPI(int) wkhtmltopdf_get_global_setting(wkhtmltopdf_global_settings * settings, const char * name, char * value, int vs);
50+
CAPI(int) wkhtmltopdf_set_object_setting(wkhtmltopdf_object_settings * settings, const char * name, const char * value);
51+
CAPI(int) wkhtmltopdf_get_object_setting(wkhtmltopdf_object_settings * settings, const char * name, char * value, int vs);
52+
53+
54+
CAPI(wkhtmltopdf_converter *) wkhtmltopdf_create_converter(wkhtmltopdf_global_settings * settings);
55+
CAPI(void) wkhtmltopdf_destroy_converter(wkhtmltopdf_converter * converter);
56+
57+
CAPI(void) wkhtmltopdf_set_warning_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_str_callback cb);
58+
CAPI(void) wkhtmltopdf_set_error_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_str_callback cb);
59+
CAPI(void) wkhtmltopdf_set_phase_changed_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_void_callback cb);
60+
CAPI(void) wkhtmltopdf_set_progress_changed_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_int_callback cb);
61+
CAPI(void) wkhtmltopdf_set_finished_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_int_callback cb);
62+
/* CAPI(void) wkhtmltopdf_begin_conversion(wkhtmltopdf_converter * converter); */
63+
/* CAPI(void) wkhtmltopdf_cancel(wkhtmltopdf_converter * converter); */
64+
CAPI(int) wkhtmltopdf_convert(wkhtmltopdf_converter * converter);
65+
CAPI(void) wkhtmltopdf_add_object(
66+
wkhtmltopdf_converter * converter, wkhtmltopdf_object_settings * setting, const char * data);
67+
68+
CAPI(int) wkhtmltopdf_current_phase(wkhtmltopdf_converter * converter);
69+
CAPI(int) wkhtmltopdf_phase_count(wkhtmltopdf_converter * converter);
70+
CAPI(const char *) wkhtmltopdf_phase_description(wkhtmltopdf_converter * converter, int phase);
71+
CAPI(const char *) wkhtmltopdf_progress_string(wkhtmltopdf_converter * converter);
72+
CAPI(int) wkhtmltopdf_http_error_code(wkhtmltopdf_converter * converter);
73+
CAPI(long) wkhtmltopdf_get_output(wkhtmltopdf_converter * converter, const unsigned char **);
74+
75+
#include <wkhtmltox/dllend.inc>
76+
#endif /*__PDF_H__*/
55.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)