Initial commit

This commit is contained in:
Elnu 2023-08-17 22:34:18 -07:00
commit 96bd340006
7 changed files with 142 additions and 0 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
*.pdf
*.aux
*.log
.direnv

40
README.md Normal file
View file

@ -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]
```

27
flake.lock generated Normal file
View file

@ -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
}

44
flake.nix Normal file
View file

@ -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 ];
};
};
}

24
numbered.tex Normal file
View file

@ -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}

2
run.sh Executable file
View file

@ -0,0 +1,2 @@
#!/usr/bin/env bash
pdflatex "\newcommand{\vartitle}{${1}}\newcommand{\varinput}{${2}}\input{numbered.tex}" && mv numbered.pdf ${3} &> /dev/null