Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions nbconvert/exporters/webpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _template_name_default(self):
""",
).tag(config=True)

def run_playwright(self, html):
def run_playwright(self, html, path=None):
"""Run playwright."""

async def main(temp_file):
Expand Down Expand Up @@ -143,7 +143,9 @@ async def main(temp_file):
# file to be opened by a separate process. So we must close it first
# before calling Chromium. We also specify delete=False to ensure the
# file is not deleted after closing (the default behavior).
temp_file = tempfile.NamedTemporaryFile(suffix=".html", delete=False)
temp_file = tempfile.NamedTemporaryFile(
suffix=".html", prefix=".webpdf-", dir=path, delete=False
)
with temp_file:
temp_file.write(html.encode("utf-8"))
try:
Expand All @@ -169,9 +171,10 @@ def run_coroutine(coro):
def from_notebook_node(self, nb, resources=None, **kw):
"""Convert from a notebook node."""
html, resources = super().from_notebook_node(nb, resources=resources, **kw)
path = resources.get("metadata", {}).get("path")

self.log.info("Building PDF")
pdf_data = self.run_playwright(html)
pdf_data = self.run_playwright(html, path)
self.log.info("PDF successfully created")

# convert output extension to pdf
Expand Down
Loading