betatim / notebook-as-pdf

Save Jupyter Notebooks as PDF
BSD 3-Clause "New" or "Revised" License
368 stars 72 forks source link

replace pikepdf with pypdf2, encode notebook as nbformat #4

Closed bollwyvl closed 4 years ago

bollwyvl commented 4 years ago

Not sure what the trade-off is, but this does in fact embed the notebook without requiring the qpdf dependency. It's also a few lines shorter. Also updated the embedded file to be as-formatted-by-nbformat, for good measure.

I'm not sure if this fixed #2, as I could certainly imagine some case where the embedded notebook would not be required/desired... but hey, it's easier to install, and that's good.

betatim commented 4 years ago

LGTM.

This "fixes" #2 in the sense that it means Windows users can now install this without huge struggle. Which was the motivation for making pikepdf optional (less features for easier install). With this we get the best of both worlds (all the features and easier install).

What is the difference between nbformat and json.dumps in terms of formatting?

betatim commented 4 years ago

It works for me on mybinder.org. Let's see if a Windows user has time to check this out and report back

bollwyvl commented 4 years ago

all the features and easier install

Well, like I said, no doubt one is sacrificing speed, but it likely pales in comparison to starting a bespoke web browser. Actually, to that end, if you were to have multiple documents to pdfinate, it would be cool if it used just one browser instance rather than bringing it up and down repeateadly... hadn't optimized for that before, but makes sense...

What is the difference between nbformat and json.dumps in terms of formatting?

At present, it's slightly opinionated (indentation, specific ordering opinions). But more to the point, if this is an archival format, I'd imagine you'd want to get as close to "standards" as possible. From a UX perspective, when I clicked on the json dump, i get the whole thing as one line, which kinda just looks like any JSON. With the nbformat, it has "the look" that might help someone know what to do with it.

bollwyvl commented 4 years ago

It works for me on mybinder.org.

hm, does binder pull in the hot version or the one from pip?

Let's see if a Windows user has time to check this out and report back

or, you know, test it on windows :P

betatim commented 4 years ago

does mybinder.org use the PR or PyPI?

I built your PR branch before merging it to test it out

test it on windows

I am one of the 50% who don't have access to a Windows machine :(

bollwyvl commented 4 years ago

githubcrosoft would :heart_eyes: to give you a windows machine:

name: Python package

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        python-version: [2.7, 3.6, 3.7, 3.8, pypy2, pypy3]
        exclude:
          - os: macos-latest
            python-version: 3.6
          - os: windows-latest
            python-version: 3.6
    steps:
      - uses: actions/checkout@v2
      - name: Setup Python
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python }}
      - name: Install Tox and any other packages
        run: pip install tox
      - name: Run Tox
        run: tox -e py  # Run tox using the version of Python in `PATH`