Skip to content

Commit

Permalink
Merge pull request #226 from knuesel/support-pdf-outputs
Browse files Browse the repository at this point in the history
Fixes #223
  • Loading branch information
blink1073 authored Nov 24, 2022
2 parents 85714c6 + b7a5c24 commit 6338f1a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions octave_kernel/kernel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import print_function

import atexit
import base64
import codecs
import glob
import json
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6338f1a

Please sign in to comment.