add script
This commit is contained in:
parent
f831787069
commit
2b69668ba1
2 changed files with 67 additions and 4 deletions
|
@ -2,12 +2,12 @@
|
|||
|
||||
### Generating existing fliers
|
||||
|
||||
Make sure chromium is installed, in my case (on debian 13) I ran:
|
||||
Make sure the deps are installed, in my case (on debian 13) I ran:
|
||||
```
|
||||
sudo apt intall chromium
|
||||
sudo apt intall chromium imagemagick
|
||||
```
|
||||
|
||||
Once you've verified the installation completed successfully, run a command like the one below to generate a pdf from the html files:
|
||||
Once you've verified the installation completed successfully, run the provided script to generate a pdf/png from the html files:
|
||||
```
|
||||
chromium --headless --disable-gpu --print-to-pdf="output.pdf" file:////home/<user>/git/html-fliers/<flier-folder>/index.html
|
||||
./gen
|
||||
```
|
63
gen
Executable file
63
gen
Executable file
|
@ -0,0 +1,63 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Get all non-dot directories in current directory
|
||||
dirs=()
|
||||
while IFS= read -r -d $'\0' dir; do
|
||||
dirs+=("$dir")
|
||||
done < <(find . -maxdepth 1 -type d ! -name ".*" -printf "%P\0")
|
||||
|
||||
# Check if any directories found
|
||||
if [ ${#dirs[@]} -eq 0 ]; then
|
||||
echo "No non-dot directories found in $(pwd)."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# List directories numbered
|
||||
echo "Select a directory to generate PDF and PNG from index.html:"
|
||||
for i in "${!dirs[@]}"; do
|
||||
echo "$((i+1)). ${dirs[i]}"
|
||||
done
|
||||
|
||||
# Prompt user for choice
|
||||
read -rp "Enter number (1-${#dirs[@]}): " choice
|
||||
|
||||
# Validate choice: must be number and within range
|
||||
if ! [[ "$choice" =~ ^[0-9]+$ ]] || (( choice < 1 || choice > ${#dirs[@]} )); then
|
||||
echo "Invalid choice."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
selected_dir="${dirs[choice-1]}"
|
||||
echo "You selected: $selected_dir"
|
||||
|
||||
# Construct file URL
|
||||
abs_path="$(realpath "$selected_dir/index.html")"
|
||||
if [ ! -f "$abs_path" ]; then
|
||||
echo "index.html not found in $selected_dir"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
file_url="file://$abs_path"
|
||||
|
||||
output_pdf="$selected_dir/output.pdf"
|
||||
output_png="$selected_dir/output.png"
|
||||
|
||||
# Run chromium headless to generate PDF
|
||||
chromium --headless --disable-gpu --allow-file-access-from-files --print-to-pdf="$output_pdf" "$file_url"
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Chromium PDF generation failed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "PDF generated at $output_pdf"
|
||||
|
||||
# Convert PDF to PNG (first page only)
|
||||
pdftoppm -png -singlefile "$output_pdf" "${selected_dir}/output"
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "PDF to PNG conversion failed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "PNG generated at $output_png"
|
Loading…
Add table
Reference in a new issue