From b7a5c24b51a8bcb46da749284b928225243b6dd6 Mon Sep 17 00:00:00 2001 From: Jeremie Knuesel Date: Thu, 24 Nov 2022 11:31:57 +0100 Subject: [PATCH] Support PDF in cell outputs --- octave_kernel/kernel.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/octave_kernel/kernel.py b/octave_kernel/kernel.py index 048f037..fb80b31 100644 --- a/octave_kernel/kernel.py +++ b/octave_kernel/kernel.py @@ -1,6 +1,7 @@ from __future__ import print_function import atexit +import base64 import codecs import glob import json @@ -36,6 +37,14 @@ ] + MetaKernel.help_links +class PDF(object): + """Wrapper for PDF object for display. + """ + def __init__(self, filename): + with open(filename, 'rb') as f: + data = f.read() + self._repr_pdf_ = base64.b64encode(data) + def get_kernel_json(): """Get the kernel json for the kernel. @@ -319,6 +328,8 @@ def extract_figures(self, plot_dir, remove=False): try: if fname.lower().endswith('.svg'): im = self._handle_svg(filename) + elif fname.lower().endswith('.pdf'): + im = PDF(filename) else: im = Image(filename) images.append(im)