Skip to content

Commit

Permalink
Add PDF container (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-kiaer authored May 16, 2019
1 parent f2cf879 commit 0cf8daf
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
5 changes: 5 additions & 0 deletions examples/basic_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ pages:
csv_file: ./example_data.csv
filtering: True

- title: PDF example
content:
- container: EmbedPdf
pdf_file: ./example.pdf

- title: Syntax highlighting example
content:
- container: SyntaxHighlighter
Expand Down
Binary file added examples/example.pdf
Binary file not shown.
4 changes: 3 additions & 1 deletion webviz_config/containers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
from ._data_table import DataTable
from ._syntax_highlighter import SyntaxHighlighter
from ._table_plotter import TablePlotter
from ._embed_pdf import EmbedPdf

__all__ = ['ExampleContainer',
'ExampleAssets',
'ExamplePortable',
'BannerImage',
'DataTable',
'SyntaxHighlighter',
'TablePlotter']
'TablePlotter',
'EmbedPdf']

for entry_point in pkg_resources.iter_entry_points('webviz_config_containers'):
globals()[entry_point.name] = entry_point.load()
Expand Down
35 changes: 35 additions & 0 deletions webviz_config/containers/_embed_pdf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from pathlib import Path
import dash_html_components as html
from ..webviz_assets import webviz_assets


class EmbedPdf:
'''### Embed PDF file
This container embeds a given PDF file into the page.
* `pdf_file`: Path to the PDF file to include. Either absolute path or
relative to the configuration file.
* `height`: Height of the PDF object (in percent of viewport height).
* `width`: Width of the PDF object (in percent of available space).
_Note_: Webviz does not scan your PDF for malicious code.
Make sure it comes from a trusted source.
'''

def __init__(self, pdf_file: Path, height: int = 80, width: int = 100):
self.pdf_url = webviz_assets.add(pdf_file)
self.height = height
self.width = width

@property
def layout(self):

style = {
'height': f'{self.height}vh',
'width': f'{self.width}%'
}

return html.Embed(src=self.pdf_url,
style=style,
type='application/pdf')
4 changes: 3 additions & 1 deletion webviz_config/themes/_theme_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
'base-uri': '\'self\'',
'form-action': '\'self\'',
'frame-ancestors': '\'none\'',
'object-src': '\'none\'',
'child-src': '\'none\'',
'object-src': '\'self\'',
'plugin-types': 'application/pdf'
}

'''
Expand Down

0 comments on commit 0cf8daf

Please sign in to comment.