0.6.2 • Published 8 months ago

docs-to-pdf v0.6.2

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

Docs to PDF

npm node-current npm Codecov GitHub

📌 Introduction

This is a PDF generator from document website such as docusaurus. This is a fork of mr-pdf which was not maintained anymore. Feel free to contribute to this project.

⚡ Usage

For Docusaurus v2

npx docs-to-pdf --initialDocURLs="https://docusaurus.io/docs/" --contentSelector="article" --paginationSelector="a.pagination-nav__link.pagination-nav__link--next" --excludeSelectors=".margin-vert--xl a,[class^='tocCollapsible'],.breadcrumbs,.theme-edit-this-page" --coverImage="https://docusaurus.io/img/docusaurus.png" --coverTitle="Docusaurus v2"

🍗 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 selector with 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 docs-to-pdf.pdf
--pdfMarginNoset margin around PDF file. Separate each margin with comma and no space. ex: --pdfMargin="10,20,30,40". This sets margin top: 10px, right: 20px, bottom: 30px, left: 40px
--paperFormatNopdf format ex: --paperFormat="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 <br/> tags for multiple lines.
--headerTemplateNoHTML template for the print header. Please check this link for details of injecting values Puppeteer document
--footerTemplateNoHTML template for the print footer. Please check this link for details of injecting values Puppeteer document
--puppeteerArgsNoAdd puppeteer BrowserLaunchArgumentOptions arguments ex: --sandbox Puppeteer document
--protocolTimeoutNoTimeout setting for individual protocol calls in milliseconds. If omitted, the default value of 180000 ms (3 min) is used
--filterKeywordNoOnly adds pages to the PDF containing a given meta keywords. Makes it possible to generate PDFs of selected pages
--baseUrlNoBase URL for all relative URLs. Allows to render the pdf on localhost (ci/Github Actions) while referencing the deployed page.
--excludePathsNoURL Paths to be excluded
--restrictPathsNoKeep Only URL Path with the same rootPath as --initialDocURLs

🎨 Examples and Demo PDF

Docusaurus v2

20210603060438

https://docusaurus.io/

initialDocURLs: https://docusaurus.io/docs

demoPDF: https://github.com/jean-humann/docs-to-pdf/blob/master/pdf/v2-docusaurus.pdf

command:

npx docs-to-pdf --initialDocURLs="https://docusaurus.io/docs/" --contentSelector="article" --paginationSelector="a.pagination-nav__link.pagination-nav__link--next" --excludeSelectors=".margin-vert--xl a,[class^='tocCollapsible'],.breadcrumbs,.theme-edit-this-page" --coverImage="https://docusaurus.io/img/docusaurus.png" --coverTitle="Docusaurus v2"

Docusaurus v1 - Legacy

https://docusaurus.io/en/

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

demoPDF: https://github.com/jean-humann/docs-to-pdf/blob/master/pdf/v1-docusaurus.pdf

command:

npx docs-to-pdf --initialDocURLs="https://docusaurus.io/docs/en/installation" --contentSelector="article" --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"

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

📄 How docs-to-pdf works

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

docs-to-pdf-diagram

🎉 Thanks

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

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

@bojl approach to make TOC was awesome and breakthrough.

0.6.2

8 months ago

0.5.0

9 months ago

0.4.0

9 months ago

0.3.1

9 months ago

0.6.1

9 months ago

0.6.0

9 months ago

0.5.1

9 months ago

0.3.0

11 months ago

0.2.1

11 months ago

0.1.2

12 months ago

0.2.0

12 months ago

0.2.3

11 months ago

0.2.2

11 months ago

0.1.3

12 months ago

0.2.4

11 months ago

0.1.1

12 months ago

0.1.0

12 months ago