Socket
Book a DemoInstallSign in
Socket

vitpress-generate-pdf

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vitpress-generate-pdf

Generate pdf from document

1.1.4
latest
npmnpm
Version published
Weekly downloads
1.7K
-13%
Maintainers
1
Weekly downloads
 
Created
Source

⚠️ Caution!

Currently, this package is not catching up with docusaurus v2 HTML markup, so command may not find the correct HTML to loop through docs. Please modify the command to find correct HTML markup by yourself.

📌 Introduction

This is a PDF generator from document website such as docusaurus, vuepress, mkdocs.

⚡ Usage

For docusaurus v1

npx mr-pdf --initialDocURLs="https://v1.docusaurus.io/docs/en/installation" --paginationSelector=".docs-prevnext > a.docs-next" --excludeSelectors=".fixedHeaderContainer,footer.nav-footer,#docsNav,nav.onPageNav,a.edit-page-link,div.docs-prevnext" --cssStyle=".navPusher {padding-top: 0;}" --contentSelector="article"

🍗 CLI Options

OptionRequiredDescription
--initialDocURLsYesset URL to start generating PDF from.
--contentSelectorYesused to find the part of main content
--paginationSelectorYesCSS Selector used to find next page to be printed for looping.
--excludeURLsNoURLs to be excluded in PDF
--excludeSelectorsNoexclude selectors from PDF. Separate each selectorwith comma and no space. But you can use space in each selector. ex: --excludeSelectors=".nav,.next > a"
--cssStyleNoCSS style to adjust PDF output ex:--cssStyle="body{padding-top: 0;}" *If you're project owner you can use @media print { } to edit CSS for PDF.
--outputPDFFilenameNoname of the output PDF file. Default is mr-pdf.pdf
--pdfMarginNoset margin around PDF file. Separate each marginwith comma and no space. ex: --pdfMargin="10,20,30,40". This sets margin top: 10px, right: 20px, bottom: 30px, left: 40px
--pdfFormatNopdf format ex:--pdfFormat="A3". Please check this link for available formats Puppeteer document
--disableTOCNoOptional toggle to show the table of contents or not
--coverTitleNoTitle for the PDF cover.
--coverImageNo<src> Image for PDF cover (does not support SVG)
--coverSubNoSubtitle the for PDF cover. Add `` tags for multiple lines.
--headerTemplateNoHTML template for the print header. Please check this link for details of injecting valuesPuppeteer document
--footerTemplateNoHTML template for the print footer. Please check this link for details of injecting valuesPuppeteer document
--buildDirPathNolocation of build directory
--firstDocPathNolocation of first doc path

🎨 Examples and Demo PDF

Docusaurus v1

https://docusaurus.io/en/

initialDocURLs: https://docusaurus.io/docs/en/installation

demoPDF: https://github.com/kohheepeace/mr-pdf/blob/master/v1-docusaurus.pdf

command:

npx mr-pdf --initialDocURLs="https://docusaurus.io/docs/en/installation" --paginationSelector=".docs-prevnext > a.docs-next" --excludeSelectors=".fixedHeaderContainer,footer.nav-footer,#docsNav,nav.onPageNav,a.edit-page-link,div.docs-prevnext" --cssStyle=".navPusher {padding-top: 0;}" --pdfMargin="20"

Docusaurus v2 beta

20210603060438

https://docusaurus.io/

initialDocURLs: https://docusaurus.io/docs

demoPDF: https://github.com/kohheepeace/mr-pdf/blob/master/v2-docusaurus.pdf

command:

npx mr-pdf --initialDocURLs="https://docusaurus.io/docs/" --contentSelector="article" --paginationSelector=".pagination-nav__item--next > a" --excludeSelectors=".margin-vert--xl a" --coverImage="https://docusaurus.io/img/docusaurus.png" --coverTitle="Docusaurus v2"

Vuepress v1

https://vuepress.vuejs.org/

initialDocURLs:

https://vuepress.vuejs.org/guide/

demoPDF: https://github.com/kohheepeace/mr-pdf/blob/master/v1-vuepress.pdf command:

npx mr-pdf --initialDocURLs="https://vuepress.vuejs.org/guide/" --contentSelector="main" --paginationSelector=".page-nav .next a" --excludeSelectors="header.navbar,aside.sidebar,footer.page-edit .edit-link,.global-ui,.page-nav" --coverImage="https://vuepress.vuejs.org/hero.png" --coverTitle="VuePress" --coverSub="Vue-powered Static Site Generator"

Vuepress v2 beta

https://v2.vuepress.vuejs.org/

initialDocURLs:

https://v2.vuepress.vuejs.org/guide/

demoPDF: https://github.com/kohheepeace/mr-pdf/blob/master/v2-vuepress.pdf command:

npx mr-pdf --initialDocURLs="https://v2.vuepress.vuejs.org/guide/" --contentSelector="main" --paginationSelector=".page-nav .next a" --excludeSelectors="header.navbar,aside.sidebar,footer.page-edit .edit-link,.global-ui,.page-nav" --coverImage="https://v2.vuepress.vuejs.org/images/hero.png" --coverTitle="VuePress" --coverSub="Vue-powered Static Site Generator"

Mkdocs

https://www.mkdocs.org/

initialDocURLs: https://www.mkdocs.org/

demoPDF: https://github.com/kohheepeace/mr-pdf/blob/master/mkdocs.pdf

command:

npx mr-pdf --initialDocURLs="https://www.mkdocs.org/" --paginationSelector="ul.navbar-nav li.nav-item a[rel~='next']" --excludeSelectors=".navbar.fixed-top,footer,.homepage .container .row .col-md-3,#toc-collapse" --cssStyle=".col-md-9 {flex: 0 0 100%; max-width: 100%;}"

Material for Mkdocs

https://squidfunk.github.io/mkdocs-material/

initialDocURLs: https://squidfunk.github.io/mkdocs-material/getting-started/

demoPDF: https://github.com/kohheepeace/mr-pdf/blob/master/material-for-mkdocs.pdf command:

npx mr-pdf --initialDocURLs="https://squidfunk.github.io/mkdocs-material/getting-started/" --paginationSelector="a.md-footer-nav__link--next" --excludeSelectors="header.md-header,.announce,nav.md-tabs,.md-main__inner .md-sidebar--primary,.md-main__inner .md-sidebar--secondary,footer" --cssStyle=".md-content {max-width: 100%!important;}"

Generate PDF from build folder

npx mr-pdf --buildDirPath="docusaurus-website/build"  --firstDocPath="/docs/summary/basic-summary/" --paginationSelector=".pagination-nav__link--next" --contentSelector="article"

PR to add new docs is welcome here... 😸

📄 How mr-pdf works

  • puppter can make html to PDF like you can print HTML page in chrome browser
  • so, the idea of mr-pdf is generating one big HTML through looping page link, then run page.pdf() from puppter to generate PDF.

mr-pdf-diagram

🎉 Thanks

This repo's code is coming from https://github.com/KohheePeace/docusaurus-pdf.

Thanks for awesome code made by @maxarndt and @aloisklink.

@bojl approach to make TOC was awesome and breakthrough.

Keywords

pdf

FAQs

Package last updated on 06 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.