Skip to content

Commit

Permalink
fix windows export problem
Browse files Browse the repository at this point in the history
  • Loading branch information
John Lyu committed Aug 29, 2023
1 parent c092b64 commit 26c34ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
30 changes: 17 additions & 13 deletions dataframe_image/_browser_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,16 @@ async def main(file_name, p):
await handler(ws, data, "content")

# fourth - get pdf
await asyncio.sleep(1)
params = {"displayHeaderFooter": False, "printBackground": True}
data = {"id": 4, "method": "Page.printToPDF", "params": params}
pdf_data = await handler(ws, data, "data")
pdf_data = base64.b64decode(pdf_data)
for i in range(10):
await asyncio.sleep(1)
params = {"displayHeaderFooter": False, "printBackground": True}
data = {"id": 4, "method": "Page.printToPDF", "params": params}
pdf_data = await handler(ws, data, "data")
pdf_data = base64.b64decode(pdf_data)
if len(pdf_data) > 1000:
break
else:
raise Exception("Could not get pdf data")
return pdf_data


Expand Down Expand Up @@ -102,11 +107,6 @@ def launch_chrome():
return p


def get_html_data(nb, resources, **kw):
he = HTMLExporter()
html_data, resources = he.from_notebook_node(nb, resources, **kw)
html_data = html_data.replace("@media print", "@media xxprintxx")
return html_data

# deprecated
def get_pdf_data(file_name):
Expand All @@ -118,7 +118,7 @@ def get_pdf_data(file_name):

with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
future = executor.submit(run, main(file_name, p))
data = future.result()
data = future.result()
p.kill()
return data

Expand Down Expand Up @@ -147,15 +147,19 @@ def get_pdf_data_chromecontroller(file_name):
return pdf_data


class BrowserExporter(TemplateExporter):
class BrowserExporter(HTMLExporter):
def _file_extension_default(self):
return ".pdf"

def _template_extension_default(self):
return ".html.j2"

def from_notebook_node(self, nb, resources=None, **kw):
resources["output_extension"] = ".pdf"
nb_home = resources["metadata"]["path"]

html_data = get_html_data(nb, resources, **kw)
html_data, resources = super().from_notebook_node(nb, resources, **kw)
html_data = html_data.replace("@media print", "@media xxprintxx")
fd, tf_name = mkstemp(dir=nb_home, suffix=".html")
with open(fd, "w", encoding="utf-8") as f:
f.write(html_data)
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
["jupyter-config/nbconfig/notebook.d/dataframe_image.json"],
)
],
use_scm_version=True,
use_scm_version={
'write_to': 'dataframe_image/_version.py',
'write_to_template': '__version__ = "{version}"',
'tag_regex': r'^(?P<prefix>v)?(?P<version>[^\+]+)(?P<suffix>.*)?$',
},
setup_requires=["setuptools_scm"],
)

0 comments on commit 26c34ff

Please sign in to comment.