npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

notion-easy-export

v1.0.2

Published

Notion easy export is a lightweight library to convert notion document consisting of multiple nested documents or databases into an ebook format like PDFs, with the table of contents, page cover, headers etc.

Downloads

117

Readme

Notion Easy Export

Notion easy export is a lightweight library written in Typescript to convert any notion document consisting of multiple nested documents or databases into an ebook format like PDFs, with the table of contents, page cover, headers etc.

Use Cases

  1. Say you have a notion database containing many documents, and you wish to export them into a single PDF. Notion doesn't allow non-enterprise uses to include all the subpages into a single PDF recursively (Have a look at image below). But this library lets you generate it without any hassle, and even on a free plan. :) PDF Export Dialog
  2. Say you have an e-reader like Kindle would like to send all the articles you have written on Notion workspace every 24 hours automatically. Notion easy export can help you in it. You can use it to get the Ebook version, then can send it to your e-reader device. :). You may consider using GitHub actions or any similar service to automate the workflow.

Features

This application requires Zero Configuration. The current implementation does most things like arranging all the files as chapters and generating the Table of Contents, cover page, footer, etc.

There are two modes to use this application:

  1. Standalone mode: It allows users to generate a separate PDF for each of the HTML pages. For example, if your notion exports have a total of 12 pages (including all nested docs, tables etc.), then there will be precisely 12 PDFs generated for each one of them. You can find the exported merged file inside session_files/output/standalone.

  2. Merge mode: It allows users to generate a single PDF for the entire export. It concatenates each of the notion pages smartly to generate a single document. Table of contents of the whole document is also included at the beginning to ease browsing across the different sections of the merged PDF. You can find the exported standalone files inside session_files/output/merged.

💡 Document Arranging Logic: In merge mode all documents not linking to any other document at the current level are placed before the documents linking to other ones in alphabetical order.

Installation

npm install notion-easy-export

[Required] Installing wkhtmltopdf

The following application uses wkhtmltopdf to generate PDFs. Kindly follow these steps to get wkhtmltopdf installed and added to PATH.

⚠️ Packages provided by your distribution might be easier to install but they may not be using a patched Qt and have missing features. So use it at your own discretion.

  1. First of all, install the wkhtmltopdf by downloading the installer from here.
  2. Now we need to add wkhtmltopdf to PATH. You might or might not need to perform this step, as the installer automatically performs this step for some distributions. (FYI, macOS installer automatically adds to PATH. Another advantage of using a mac? 🤔).
  3. Confirm that wkhtmltopdf is successfully added to PATH by opening terminal/command prompt/powershell and executing the following command:
wkhtmltopdf --version

Note: On macOS, while trying to install wkhtmltopdf you will be prompted with macOS cannot verify that this app is free from malware. Kindly follow the steps mentioned here to fix it.

API

The usage is pretty straightforward.

  1. If you want to use in the standalone mode and generate separate PDF document for each one Notion Page.
import { buildStandaloneDocs } from "notion-easy-export";

const token_v2 = "YOUR_NOTION_TOKEN_V2";
const pageId = "NOTION_PAGE_ID";

buildStandaloneDocs(token_v2, pageId);
  1. If you want to use in the merged mode and generate a single PDF document for each the complete export.
import { buildMergedDoc } from "notion-easy-export";

const token_v2 = "YOUR_NOTION_TOKEN_V2";
const pageId = "NOTION_PAGE_ID";

buildMergedDoc(token_v2, pageId);

⚠️ Caution: Whenever you call any of the instances of buildStandaloneDocs or buildMergedDoc. It removes all files inside the session_files. So please be cautious before starting the script.

Details on Notion TOKEN_V2

Please note that TOKEN_V2 used in the application is different from Notion's official API Internal Integration Token.

Follow these steps to get the token_v2.

  1. Open the browser inspector tools and go to Application Tab.
  2. Then look for the cookies section, and use the value corresponding to the key token_v2 to authenticate to Notion Server.

Example

We will export this Notion document, which is a full-page database and has four documents inside it.

Please note that Notion doesn't allow us to export all of these documents as PDFs in one go without the enterprise plan.

Links to the output files generated using this library:

  1. Standalone files: Link
  2. Merged file: Link

It's Great, isn't it? 🎉

Future Changes in API

  1. Currently, the only export format this library supports is PDF. We plan to add additional formats like LaTex, mobi, epub etc. very soon.
  2. More support to tweak the configuration.

Contributing

This project welcomes contributions and suggestions. Feel free to report bugs and suggest features. It will help us improve this project. ⚡⚡