mirror of
https://github.com/kmein/niveum
synced 2026-03-16 10:11:08 +01:00
Packaged 14 scripts from .bin/ into packages/ with proper dependency declarations (writers.writeDashBin/writeBashBin/writePython3Bin): - 256color → two56color (terminal color chart) - avesta.sed → avesta (Avestan transliteration) - bvg.sh → bvg (Berlin transit disruptions) - unicode → charinfo (Unicode character info) - chunk-pdf → chunk-pdf (split PDFs by page count) - csv2json → csv2json (CSV to JSON converter) - fix-sd.sh → fix-sd (exFAT SD card recovery, improved output handling) - json2csv → json2csv (JSON to CSV converter) - mp3player-write → mp3player-write (audio conversion for MP3 players) - mushakkil.sh → mushakkil (Arabic diacritization) - nix-haddock-index → nix-haddock-index (GHC Haddock index generator) - pdf-ocr.sh → pdf-ocr (OCR PDFs via tesseract) - prospekte.sh → prospekte (German supermarket flyer browser) - readme → readme (GitHub README as man page) All added to overlay and packages output. .bin/ directory removed.
31 lines
897 B
Nix
31 lines
897 B
Nix
# Split a PDF into chunks of N pages
|
|
{
|
|
writers,
|
|
pdftk,
|
|
gnugrep,
|
|
coreutils,
|
|
}:
|
|
writers.writeDashBin "chunk-pdf" ''
|
|
set -efu
|
|
|
|
INPUT_FILE="''${2:?Pass the PDF path as second argument.}"
|
|
PAGES_PER_REPORT="''${1:?Pass the chunk size as first argument.}"
|
|
|
|
if [ ! -f "$INPUT_FILE" ]; then
|
|
echo >&2 "File $INPUT_FILE does not exist."
|
|
exit 1
|
|
fi
|
|
|
|
TOTAL_PAGES="$(${pdftk}/bin/pdftk "$INPUT_FILE" dump_data | ${gnugrep}/bin/grep NumberOfPages | ${coreutils}/bin/cut -f2 -d' ')"
|
|
|
|
RUNS=$((TOTAL_PAGES/PAGES_PER_REPORT))
|
|
|
|
for run in $(${coreutils}/bin/seq 0 "$((RUNS-1))"); do
|
|
start_page=$((run*PAGES_PER_REPORT+1))
|
|
end_page=$(((run+1)*PAGES_PER_REPORT))
|
|
output_file="chunk_$((run+1)).pdf"
|
|
echo "splitting $INPUT_FILE from $start_page to $end_page into $output_file"
|
|
${pdftk}/bin/pdftk "$INPUT_FILE" cat "$start_page-$end_page" output "$output_file"
|
|
done
|
|
''
|