PagedJS

Javascript library to transform HTML document into print-ready pdf

Declared in: projects/PagedJS/default.nix

Try the program in a shell

  1. Install Nix
    Bash
    $ apt install --yes curl git jq nix
    Bash
    $ apt install --yes curl git jq nix
    Bash
    $ pacman --sync --refresh --noconfirm curl git jq nix
  2. Download a configuration file
    # default.nix
    {
      ngipkgs ? import (fetchTarball "https://github.com/ngi-nix/ngipkgs/tarball/main") { },
    }:
    ngipkgs.demo-shell (
      {
        lib,
        pkgs,
        ...
      }:
      {
        # Enable X11
        services.xserver.enable = true;
    
        programs.pagedjs.enable = true;
    
        environment.systemPackages = with pkgs; [
          evince # PDF viewer
        ];
    
        environment.etc."pagedjs.html".text = ''
          <!DOCTYPE html>
          <html>
            <head>
              <title>PagedJS Example</title>
            </head>
            <body>
              <h1>Hello, PagedJS!</h1>
              <p>This is a simple example of using PagedJS.</p>
            </body>
          </html>
        '';
      }
    )
    
  3. Enable binary substituters
    Bash
    $ export NIX_CONFIG='substituters = https://cache.nixos.org/ https://ngi.cachix.org/
    trusted-public-keys = cache.nixos.org-1:6nchdd59x431o0gwypbmraurkbj16zpmqfgspcdshjy= ngi.cachix.org-1:n+cal72roc3qqulxihpv+tw5t42whxmmhpragkrsrow='
  4. Build and run the shell
    Bash
    $ nix-build ./default.nix && ./result
    Bash
    $ nix-build ./default.nix && ./result
    Bash
    $ rev=$(nix-instantiate --eval --attr sources.nixpkgs.rev https://github.com/ngi-nix/ngipkgs/archive/master.tar.gz | jq --raw-output)
    $ nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/$rev.tar.gz --packages nix --run "nix-build ./default.nix && ./result"
    Bash
    $ nix-build ./default.nix && ./result
  5. Usage Instructions
    1. A simple HTML file has been created at /etc/pagedjs.html for testing.

    2. Run pagedjs-cli --help to see available commands.

    3. To create a PDF from the HTML file, use: $ pagedjs-cli -i /etc/pagedjs.html -o ~/pagedjs-example.pdf

    4. View the PDF using evince: $ evince ~/pagedjs-example.pdf

Options

programs.pagedjs
programs.pagedjs.enable

Whether to enable PagedJS.

Type:
boolean
Default:
false
Declared in:
projects/PagedJS/programs/pagedjs/module.nix
programs.pagedjs.package

The pagedjs-cli package to use.

Type:
package
Default:
pkgs.pagedjs-cli
Declared in:
projects/PagedJS/programs/pagedjs/module.nix

Examples

Enable pagedjs
{
  lib,
  pkgs,
  ...
}:
{
  # Enable X11
  services.xserver.enable = true;

  programs.pagedjs.enable = true;

  environment.systemPackages = with pkgs; [
    evince # PDF viewer
  ];

  environment.etc."pagedjs.html".text = ''
    <!DOCTYPE html>
    <html>
      <head>
        <title>PagedJS Example</title>
      </head>
      <body>
        <h1>Hello, PagedJS!</h1>
        <p>This is a simple example of using PagedJS.</p>
      </body>
    </html>
  '';
}

Declared in: projects/PagedJS/programs/pagedjs/examples/pagedjs.nix

This project is funded by NLnet through these subgrants:

Commons
PagedJS

Related links: