File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change 5
5
import os .path
6
6
import sys
7
7
import tempfile
8
+ from datetime import datetime
8
9
from pathlib import Path
9
10
from shutil import copy
11
+ from time import sleep
10
12
from typing import Optional , List
11
13
12
14
import requests
@@ -148,9 +150,30 @@ def get_pdf_from_html(driver, url) -> bytes:
148
150
print ("HTML2PDF: executing print command with Chrome Driver." ) # noqa: T201
149
151
result = driver .execute_cdp_cmd ("Page.printToPDF" , calculated_print_options )
150
152
153
+ class Done (Exception ): pass
154
+
155
+ datetime_start = datetime .today ()
156
+
157
+ logs = None
158
+ try :
159
+ while True :
160
+ logs = driver .get_log ("browser" )
161
+ for entry_ in logs :
162
+ if "HTML2PDF4DOC time" in entry_ ["message" ]:
163
+ print ("success: HTML2PDF completed its job." )
164
+ raise Done
165
+ if (datetime .today () - datetime_start ).total_seconds () > 60 :
166
+ raise TimeoutError
167
+ sleep (0.5 )
168
+ except Done :
169
+ pass
170
+ except TimeoutError :
171
+ print ("error: could not receive a successful completion status from HTML2PDF." )
172
+ sys .exit (1 )
173
+
151
174
print ("HTML2PDF: JS logs from the print session:" ) # noqa: T201
152
175
print ('"""' ) # noqa: T201
153
- for entry in driver . get_log ( "browser" ) :
176
+ for entry in logs :
154
177
print (entry ) # noqa: T201
155
178
print ('"""' ) # noqa: T201
156
179
You can’t perform that action at this time.
0 commit comments