[Solved] can't crop any PDF?

Everything about X, Gnome, KDE, ... and everything running on it

[Solved] can't crop any PDF?

Postby bester69 » 2020-03-22 14:02

Mi System.:
- Debian GNU/Linux 9.12 (stretch)
- wkhtmltopdf 0.12.5 (with patched qt)
- pdfCropMargins-0.2.6
.-------------------------------


Hi,
Im trying to create an URL hyperlink embedded within a PDF, by using the following html template and sed remplaces.:

compose.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<a href="WEBPAGE">PAGE_TITLE</a> <br>
<img src="file:///home/user/IMAGE.png"><br>
</body>
</html>


Ive twe issues.:
1- I dont know how to convert the html to pdf by creating a resulting pdf page size that fix the image size...
wkhtmltopdf "$webjob/compose.html" "$webjob/sal.pdf"

>> This, create an A4 page size pdf file resulting, I wanted a pdf that adjust to image size within html template. :?

2- As I dont know how to adjust the resulting pdf to image dimmensions by using wkhtmltopdf, I've tried to crop tha pdf to workaround that, and no application was able to crop any pdf file (pdfCropMargins eventually stopped working)
I tried.:
- pdfcrop (didnt do anything)
- https://pypi.org/project/pdfCropMargins/:
pdf-crop-margins -v -s -u "$webjob/nocrop.pdf" -o "$webjob/sal.pdf"

>> pdfCropMargins worked at first and cropped all pdf generated by wkhtmltopdf , but I dont know what has happend (or i made) that has stopped working..
-----

Im using the following script to capture image screen and url from tab browser and create the pdf.:
web2pdf.sh
Code: Select all
#!/bin/bash
# Dependencies: tesseract-ocr imagemagick google-trans
webfile="/home/user/LINUXDEBS/scripts/web2pdf.html"
pdfurl="/home/user/LINUXDEBS/PDF docs/WEB2PDF"

mkdir -p "$pdfurl"
N_random=$(echo "$RANDOM")
SCR_IMG=`mktemp`
#SCR_IMG="/tmp/web2pdf"
webjob="$SCR_IMG"


rm $webjob
rm "$webjob/"*
mkdir -p $webjob

clear
echo $webjob
cp $webfile "$webjob/template.html"

#trap "rm $SCR_IMG*" EXIT
xdotool windowminimize $(xdotool getactivewindow)
sleep 1
WID=$(xdotool search --name "opera" | tail -n 1)

# Limpia el clipboard
xclip -i /dev/null
#xdotool windowactivate $WID
xdotool windowactivate $WID key ctrl+l key ctrl+c
gnome-screenshot -a -f "$webjob/sal.png"
if [ ! -f "$webjob/sal.png" ]
then
xdotool windowactivate $WID  key Escape
exit
fi


while true;  do
xdotool windowactivate $WID
xdotool windowactivate $WID key ctrl+l key ctrl+c
sleep 1
url=$(xclip -o)
if [ ! -z $url ]
then
    break
fi
done
xdotool windowactivate $WID  key Escape


pagename=$(wget -q -O - "$url" |  tr "\n" " " | sed 's|.*<title>\([^<]*\).*</head>.*|\1|;s|^\s*||;s|\s*$||')
# echo "URL es $url"
# echo "name es $pagename"

if [ -z "$pagename" ]
then
    pagename="Página web URL**"
    filename=$(echo "${url//\//}" | cut -c -80)
        else
    filename=$(echo "$pagename" | cut -c -80)   
fi
#pagename="How to get"
echo "URL: $url" > "$webjob/urlname.txt"
echo "Pagname: $pagename" >> "$webjob/urlname.txt"
echo "Filename: $filename" >> "$webjob/urlname.txt"


#Image Path
sed 's!<img src="file:///home/user/sal.png">!<img src="file://'''$webjob'''/sal.png">!'  "$webjob/template.html" > "$webjob/tmp1.html"
#URL Path
sed -i 's!WEBPAGE!'$url'!'  "$webjob/tmp1.html"
sed -i 's!WEBPAGE!\&!g'  "$webjob/tmp1.html"
#URL title
sed 's!PAGE_TITLE!'"$pagename"'!'  "$webjob/tmp1.html"  > "$webjob/compose.html"

#mogrify -modulate 100,0 -resize 400% "$webjob/sal.png"
#wkhtmltopdf "$webjob/compose.html" "$webjob/sal.pdf"  &> /dev/null

wkhtmltopdf "$webjob/compose.html" "$webjob/sal.pdf"

cp "$webjob/sal.pdf" "$webjob/nocrop.pdf"
pdf-crop-margins -v -s -u "$webjob/nocrop.pdf" -o "$webjob/sal.pdf"
cp "$webjob/sal.pdf" "$filename.$N_random.pdf"
cp "$webjob/sal.pdf" "$pdfurl/$filename.$N_random.pdf"
cp "$webjob/sal.png" "$filename.$N_random.png"
cp "$webjob/sal.png" "$pdfurl/$filename.$N_random.png"




This is how it looked the pdf resulted, until pdfCropMargins stop working.:

Image


Any help, :( , or way to workaround this? thanks
Last edited by bester69 on 2020-03-25 17:54, edited 1 time in total.
bester69 wrote:You wont change my mind when I know Im right, Im not an ...
User avatar
bester69
 
Posts: 1609
Joined: 2015-04-02 13:15

Re: can't crop any PDF?

Postby bester69 » 2020-03-22 14:32

Ok, I restored back a btrf home volume snapshot, and now Its working again pdf-crop-margins :shock: (thats why I cant live without btrfs filesystem type :? )

things of linux.. :shock:.. ANyways, why cant I create easily a pdf dimmesioned page to image size with wkhtmltopdf :?:
bester69 wrote:You wont change my mind when I know Im right, Im not an ...
User avatar
bester69
 
Posts: 1609
Joined: 2015-04-02 13:15


Return to Desktop & Multimedia

Who is online

Users browsing this forum: No registered users and 6 guests

fashionable