Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pdfc

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdfc

PDF compiler for your source code

  • 1.0.9
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-80%
Maintainers
1
Weekly downloads
 
Created
Source

pdfc

PDF compiler for your source code

Uses Shiki for perfect syntax highlighting and shiki-renderer-pdf to create the PDFs.

semantic-release

Installation

npm install pdfc

Usage

Most uses are through the CLI, but there is a programatic API.

CLI

To compile all files in a directory to PDFs you can use this:

pdfc src

src is the rootDir here, so all paths will be relative to that. You cannot include files outside of the rootDir.

Output is placed in the pdfs directory by default. To change the output directory you can use the -d or --out-dir flag:

pdfc src -d pdf-build

This will compile all files in src by default. If you want to restrict to a subset of files you can use the --include flag:

pdfc src --include "src/**/*.js"

This will compile only the js files in src. The same can be done with the --exclude flag:

pdfc src --exclude "node_modules" --exclude "src/**/*.test.js"

This will exclude all test files from compilation. Note that node_modules should also be excluded here because it is only excluded by default if --exclude is not passed. If include is specified, exclude will apply to the included files.

You can also specify a theme to use with the -t or --theme flag:

pdfc src -t github-light

If none if specified, it will default to light-plus. See shiki docs for a list of themes.

Run pdfc --help for more on what you can do.

API

Please note that this package is pure ESM, see this for more details.

Compile PDFs, this will also write files to pdfs by default:

import { compilePdfs } from 'pdfc'
;(async () => {
  await compilePdfs({
    rootDir: 'src',
    include: ['src/**/*.js'],
    theme: 'light-plus',
  })
})()

Compile string to a PDFDocument instance:

import fs from 'node:fs/promises'
import { stringToPdf } from 'pdfc'
;(async () => {
  const code = 'console.log("Hello World")'

  const pdfDocument = await stringToPdf(code, {
    lang: 'js',
    theme: 'light-plus',
  })

  const pdfBytes = await pdfDocument.save()
  await fs.writeFile('hello-world.pdf', pdfBytes, 'binary')
})()

Read more about what you can do with pdfDocument here.

Keywords

FAQs

Package last updated on 22 Mar 2023

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc