commit 885280cf3764ef46e82a7e2a3567e0f8e4dd5b73 Author: Oliver Date: Tue Jan 20 20:24:13 2026 -0700 init diff --git a/README.md b/README.md new file mode 100644 index 0000000..3b624f2 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# HTML to PDF + +## Usage + +1. Run the setup script on a debian machine (tested on a debian 13 LXC container) +2. You need to set the parameters in the gen.sh file to match your environmnet. +3. Use either of the following syntax: + +```bash +./gen.sh my-file.html +``` +``` +./gen.sh oliveratkinson.net +``` + diff --git a/extension/inject.css b/extension/inject.css new file mode 100644 index 0000000..ddd0d4b --- /dev/null +++ b/extension/inject.css @@ -0,0 +1,4 @@ +@page { + margin: 0; +} + diff --git a/extension/manifest.json b/extension/manifest.json new file mode 100644 index 0000000..0e542d3 --- /dev/null +++ b/extension/manifest.json @@ -0,0 +1,13 @@ +{ + "name": "Print CSS", + "description": "Change the default print css for pages", + "version": "1.0", + "manifest_version": 3, + "content_scripts": [ + { + "matches": [""], + "css" : ["inject.css"] + } + ] +} + diff --git a/gen.sh b/gen.sh new file mode 100755 index 0000000..03c8470 --- /dev/null +++ b/gen.sh @@ -0,0 +1,26 @@ +DEV="192.168.1.179" +USER="chrome" +CHROME="/home/chrome/chrome/linux-144.0.7559.96/chrome-linux64/chrome" +KEYFILE="chrome" + +if [[ -z $1 ]]; then + echo Requires argument + exit 1 +fi + +PRINT="" + +if [[ $(printf $1 | tail -c 4) = "html" ]]; then + scp -i $KEYFILE $1 $USER@$DEV:/tmp/input.html + echo html; + PRINT="/tmp/input.html" +else + # This might be a bad idea, idk + echo Assuming argument 1 is a url: $1 + PRINT=$1 +fi + +scp -i $KEYFILE -r extension $USER@$DEV:~/ +ssh -i $KEYFILE $USER@$DEV $CHROME --headless=new --no-pdf-header-footer --print-to-pdf --load-extension="/home/$USER/extension" $PRINT +scp -i $KEYFILE $USER@$DEV:~/*.pdf ./ + diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..76ce7f0 --- /dev/null +++ b/setup.sh @@ -0,0 +1,4 @@ +#!/bin/bash +apt update +apt install npm libnspr4 libss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libxkbcommon-x11-0 libxdamage1 libcario2 libpango-1.0-0 libasound2 +npx @puppeteer/browsers install chrome@stable