0

I am trying to convert multiple htm files to pdf using HTMLDOC. I can convert a single file with the following: htmldoc --webpage -f filename.pdf sample/filename.htm.

I try making a script and it seems to run but does not create the pdf files.

    for F in *; do
if [ "${F}" ]; then
    echo "${F}"   htmldoc --webpage -f /home/name/pdf/$F.pdf /home/name/sample/$F
fi
done

I would appreciate if someone would help me to get this working. I am not getting any errors other than not resulting in expected pdf files.

Thank you.

Jesse.

P.S. I just noticed that the output from my script prefixes the filename on the command line that executes the program htmldoc.

computer1% ./convertpdf.sh
convertpdf.sh htmldoc --webpage -f /home/name/pdf/convertpdf.sh.pdf /home/name/oz-sample/convertpdf.sh
sample1.htm htmldoc --webpage -f /home/name/pdf/sample1.htm.pdf /home/name/oz-sample/sample1.htm
sample2.htm htmldoc --webpage -f /home/name/pdf/sample2.htm.pdf /home/name/oz-sample/sample2.htm
sample3.htm htmldoc --webpage -f /home/name/pdf/sample3.htm.pdf /home/name/oz-sample/sample3.htm
sample4.htm htmldoc --webpage -f /home/name/pdf/sample4.htm.pdf /home/name/oz-sample/sample4.htm
sample5.htm htmldoc --webpage -f /home/name/pdf/sample5.htm.pdf /home/name/oz-sample/sample5.htm
computer1%

I edited the script

for F in *; do
if [ "${F}" ]; then
    echo htmldoc --webpage -f /home/name/pdf/$F.pdf /home/name/sample/$F
fi
done

Now I get normal output but still no pdf.

computer1% ./convertpdf.sh
htmldoc --webpage -f /home/name/pdf/sample1.htm.pdf /home/name/oz-sample/sample1.htm
htmldoc --webpage -f /home/name/pdf/sample2.htm.pdf /home/name/oz-sample/sample2.htm
0

From any directory

htmdir="change this to directory of htm without final slash"
pdfdir="change this to pdf dir without final slash"  
for f in $htmdir/*.htm
do
  if [ -f $f ]
  then
    fname=$(basename "$f")
    echo converting $f to $pdfdir/${fname%.*}.pdf
    htmldoc --webpage -f $pdfdir/${fname%.*}.pdf $f
  fi
done
  • I will try this version and let you know. – Jesse Nov 3 '17 at 20:17
  • This worked quite well and gave feedback on each file. Would you be able to suggest how It could be run from outside the directory that contains the files I am converting without including that in the path of the destination pdf files? – Jesse Nov 3 '17 at 20:29
1

Okay, so I found that because I was echoing it wasn't actually running the htmldoc command it was just echoing the command string to console. I removed the echo and it created the pdf files.

Now to figure out how to get it to run from outside the directory where the source files are. when I call it from the directory above it includes the path I set in the command and creates an invalid command string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.