Skip to content

Commit

Permalink
Re-enable pdf printing
Browse files Browse the repository at this point in the history
  • Loading branch information
ayjayt committed Oct 22, 2024
1 parent 0b6114d commit a701db2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
15 changes: 13 additions & 2 deletions src/py/kaleido/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
script_path = Path(__file__).resolve().parent / "vendor" / "index.html"

# pdf and eps temporarily disabled
_all_formats_ = ("png", "jpg", "jpeg", "webp", "svg", "json") # pdf and eps
_text_formats_ = ("svg", "json",) # eps
_all_formats_ = ("png", "jpg", "jpeg", "webp", "svg", "json", "pdf") # eps missing (emf has code but no listed support)
_text_formats_ = ("svg", "json",) # eps is a text format? :-O

_scope_flags_ = ("plotlyjs", "mathjax", "topojson", "mapbox_access_token")

Expand Down Expand Up @@ -84,6 +84,17 @@ async def load_done_cb(response):
img = js_response.get("result")
except Exception as e:
raise RuntimeError(response) from e
await asyncio.sleep(30)
if response_format == "pdf":
pdf_params = dict(printBackground=True,
marginTop=0,
marginBottom=0,
marginLeft=0,
marginRight=0,
preferCSSPageSize=True,)
pdf_response = await tab.send_command("Page.printToPDF", params=pdf_params)
img = pdf_response.get("result").get("data")


# Base64 decode binary types
if response_format not in _text_formats_:
Expand Down
8 changes: 4 additions & 4 deletions src/py/kaleido/scopes/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def make_page_string(self):
"""<!DOCTYPE html>
<html>
<head>
<style id=\"head-style\"></style>
<title>Kaleido-fier</title>
<script>
window.PlotlyConfig = {MathJaxConfig: 'local'}
Expand All @@ -100,10 +101,9 @@ def make_page_string(self):
if self._mathjax:
page += f" <script type=\"text/javascript\" id=\"MathJax-script\" src=\"{self._mathjax}?config=TeX-AMS-MML_SVG\"></script>\n"
page+= \
f""" <script src="{Path(self._plotlyfier).absolute().as_uri()}"></script>
</head>
<body>
</body>
f""" <script src="{Path(self._plotlyfier).absolute().as_uri()}"></script>"""+\
""" </head>
<body style=\"{margin: 0; padding: 0;}\"><img id=\"kaleido-image\"><img></body>
</html>"""
return page

Expand Down

0 comments on commit a701db2

Please sign in to comment.