added external filters and pdf handling
This commit is contained in:
Executable
+84
@@ -0,0 +1,84 @@
|
||||
#!/bin/sh
|
||||
# @(#$Id: rclpdf,v 1.1 2005-02-01 17:20:05 dockes Exp $ (C) 2004 J.F.Dockes
|
||||
# This is copied almost verbatim from Estraier:
|
||||
#================================================================
|
||||
# Estraier: a personal full-text search system
|
||||
# Copyright (C) 2003-2004 Mikio Hirabayashi
|
||||
#================================================================
|
||||
#================================================================
|
||||
# rclpdf
|
||||
# Strip a file of PDF and extract its text as HTML.
|
||||
#================================================================
|
||||
|
||||
|
||||
# set variables
|
||||
LANG=C ; export LANG
|
||||
LC_ALL=C ; export LC_ALL
|
||||
progname="rclpdf"
|
||||
|
||||
# show help message
|
||||
if test $# -ne 1 -o "$1" = "--help"
|
||||
then
|
||||
printf 'Strip a file of PDF and extract its text as HTML.\n'
|
||||
printf 'Usage: %s [infile]\n' "$progname"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
infile="$1"
|
||||
|
||||
# check the input file existence
|
||||
if test ! -f "$infile"
|
||||
then
|
||||
printf '%s: %s: no such file\n' "$progname" "$infile"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# output the result
|
||||
pdftotext -raw -htmlmeta -enc UTF-8 -eol unix -q "$infile" - |
|
||||
iconv -f UTF-8 -t UTF-8 -c -s |
|
||||
awk '
|
||||
BEGIN {
|
||||
esc = 0
|
||||
mul = 1
|
||||
emp = 0
|
||||
}
|
||||
{
|
||||
if(esc < 1 && $0 ~ /^<title>/ && $0 ~ /title>$/){
|
||||
printf("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n")
|
||||
gsub(/<[^>]*>/, "", $0)
|
||||
gsub(/&/, "\\&", $0)
|
||||
gsub(/</, "\\<", $0)
|
||||
gsub(/>/, "\\>", $0)
|
||||
printf("<title>%s</title>\n", $0)
|
||||
} else if($0 == "<pre>"){
|
||||
esc++
|
||||
printf("<p>")
|
||||
mul = 1
|
||||
} else if($0 == "</pre>"){
|
||||
esc--
|
||||
printf("</p>\n")
|
||||
} else if($0 ~ /-$/){
|
||||
sub(/-$/, "", $0)
|
||||
printf("%s", $0);
|
||||
} else if($0 == "\f"){
|
||||
printf("</p>\n<hr>\n<p>")
|
||||
} else {
|
||||
if(esc > 0){
|
||||
gsub(/&/, "\\&", $0)
|
||||
gsub(/</, "\\<", $0)
|
||||
gsub(/>/, "\\>", $0)
|
||||
gsub(/^ */, "", $0)
|
||||
gsub(/ *$/, "", $0)
|
||||
}
|
||||
print $0
|
||||
}
|
||||
}
|
||||
'
|
||||
# Suppressed code 2 lines above (at the last print $0), which seemed to
|
||||
# deal with multibyte character being cut by a newline ? It caused problems
|
||||
# (sometimes concatenated last word of a line with first of next, and I
|
||||
# didn't really understand its use as iconv -c is supposed to fix the
|
||||
# encoding anyway
|
||||
|
||||
# exit normally
|
||||
exit 0
|
||||
Reference in New Issue
Block a user