commit 96bd340006d109130a4d02c769dd312f50160106 Author: ElnuDev Date: Thu Aug 17 22:34:18 2023 -0700 Initial commit diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..8392d15 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3964e22 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.pdf +*.aux +*.log +.direnv \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..070c2d7 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +# pdf-annotator + +pdf-annotator is a utility for quickly adding a titled header and page number to arbitrary PDF documents. + +Please note that there are a couple known limitations: + +- All outputted documents will be US Letter size in portrait orientation, regardless of the dimensions of the input PDF. In the case that the dimensions differ, the input contents will be centered on the page. +- Any filled form fields and comments on the input PDF will be lost. This appears to be a limitation of LaTeX's `\includepdf`. + +## Usage + +If you have Nix installed, you can run pdf-annotator with `nix run`. + +```SH +nix run git+https://git.elnu.com/ElnuDev/pdf-annotator -- header input [output] +``` + +The output parameter is optional, and if excluded, the output PDF will be saved to `numbered.pdf`. + +For example: + +```SH +nix run git+https://git.elnu.com/ElnuDev/pdf-annotator -- "The header goes here." input.pdf output.pdf +``` + +### Usage without Nix + +If you have the misfortune of not having [Nix](https://nixos.org/) available, ensure that the `pdflatex` command is available, which should be installed alongside `texlive-full`. + +Clone the repository: + +```SH +git clone https://git.elnu.com/ElnuDev/pdf-annotator && cd pdf-annotator +``` + +Usage: + +```SH +./run.sh header input [output] +``` \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..bfc4792 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1692174805, + "narHash": "sha256-xmNPFDi/AUMIxwgOH/IVom55Dks34u1g7sFKKebxUm0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "caac0eb6bdcad0b32cb2522e03e4002c8975c62e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..17e5699 --- /dev/null +++ b/flake.nix @@ -0,0 +1,44 @@ +{ + description = "PDF page number and header annotator using LaTeX"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = { self, nixpkgs }: let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in { + packages.${system} = { + pdf-annotator = let + texlive = pkgs.texlive.combined.scheme-full; + script = "run.sh"; + tex = "numbered.tex"; + in pkgs.stdenv.mkDerivation rec { + name = "${pname}"; + pname = "pdf-annotator"; + src = ./.; + buildInputs = [ texlive ]; + nativeBuildInputs = with pkgs; [ makeWrapper ]; + postPatch = '' + substituteInPlace run.sh \ + --replace pdflatex ${texlive}/bin/pdflatex \ + --replace ${tex} $out/share/${tex} + ''; + installPhase = '' + runHook preInstall + mkdir -p $out/bin + cp ${script} $out/bin/${pname} + mkdir -p $out/share + cp ${tex} $out/share/${tex} + wrapProgram $out/bin/${pname} --prefix PATH : ${nixpkgs.lib.makeBinPath (with pkgs; [ bash ])} + runHook postInstall + ''; + }; + default = self.packages.${system}.pdf-annotator; + }; + devShells.${system}.default = with pkgs; mkShell { + inputsFrom = with self.packages.${system}; [ pdf-annotator ]; + }; + }; +} diff --git a/numbered.tex b/numbered.tex new file mode 100644 index 0000000..bda7ed5 --- /dev/null +++ b/numbered.tex @@ -0,0 +1,24 @@ +\documentclass[letterpaper, 12pt]{article} +\usepackage{pdfpages} +\usepackage{changepage} +\usepackage{fancyhdr} + +\setlength\topmargin{-0.675in} +\setlength\textheight{7.0in} +\setlength\textwidth{7.0in} +\setlength\oddsidemargin{-0.25in} +\setlength\evensidemargin{-0.25in} + +\strictpagecheck + +\thispagestyle{empty} +\fancypagestyle{mystyle}{ + % hide any background elements in source PDF with \colorbox{white} % + \fancyhead[C]{\colorbox{white}\vartitle} + \fancyhead[R]{\colorbox{white}{Page \thepage}} + \fancyfoot[C]{} % Remove default page number footer % +} + +\begin{document} + \includepdf[pages=-,pagecommand={\thispagestyle{mystyle}}]\varinput +\end{document} \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..904a547 --- /dev/null +++ b/run.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +pdflatex "\newcommand{\vartitle}{${1}}\newcommand{\varinput}{${2}}\input{numbered.tex}" && mv numbered.pdf ${3} &> /dev/null \ No newline at end of file