<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/local/bin/perl
#
# Sample external converter for htdig 3.1.4 or later, to convert PDFs
# using Adobe Acrobat 3's acroread -toPostScript option on UNIX systems.
# (Use it in place of conv_doc.pl if you have acroread but not pdftotext.)
# Written by Gilles Detillieux.
#
# Usage: (in htdig.conf)
#
# external_parsers: application/pdf-&gt;text/html /usr/local/bin/acroconv.pl
#
# This is a pretty quick and dirty implementation, but it does seem to
# give functionality equivalent to the now defunct htdig/PDF.cc parser.
# I'm not a Perl expert by any stretch of the imagination, so the code
# could probably use a lot of optimization to make it work better.
#

$watch = 0;
$bigspace = 0;
$putspace = 0;
$putbody = 1;

system("ln $ARGV[0] $ARGV[0].pdf; acroread -toPostScript $ARGV[0].pdf");
open(INP, "&lt; $ARGV[0].ps") || die "Can't open $ARGV[0].ps\n";

print "&lt;HTML&gt;\n&lt;head&gt;\n";
while (&lt;INP&gt;) {
	if (/^%%Title: / &amp;&amp; $putbody) {
		s/^%%Title: \((.*)\).*\n/$1/;
		s/\\222/'/g;
		s/\\267/*/g;
		s/\\336/fi/g;
		s/\\([0-7]{3})/pack(C, oct($1))/eig;
		s/\\([0-7]{2})/pack(C, oct($1))/eig;
		s/\\([0-7])/pack(C, oct($1))/eig;
		s/\\[nrtbf]/ /g;
		s/\\(.)/$1/g;
		s/&amp;/\&amp;amp\;/g;
		s/&lt;/\&amp;lt\;/g;
		s/&gt;/\&amp;gt\;/g;
		print "&lt;title&gt;$_&lt;/title&gt;\n";
		print "&lt;/head&gt;\n&lt;body&gt;\n";
		$putbody = 0;
	} elsif (/^BT/) {
		$watch = 1;
	} elsif (/^ET/) {
		$watch = 0;
		if ($putspace) {
			print "\n";
			$putspace = 0;
		}
	} elsif ($watch) {
		if (/T[Jj]$/) {
			s/\)[^(]*\(//g;
			s/^[^(]*\((.*)\).*\n/$1/;
			s/\\222/'/g;
			s/\\267/*/g;
			s/\\336/fi/g;
			s/\\([0-7]{3})/pack(C, oct($1))/eig;
			s/\\([0-7]{2})/pack(C, oct($1))/eig;
			s/\\([0-7])/pack(C, oct($1))/eig;
			s/\\[nrtbf]/ /g;
			s/\\(.)/$1/g;
			if ($bigspace) {
				s/(.)/$1 /g;
			}
			s/&amp;/\&amp;amp\;/g;
			s/&lt;/\&amp;lt\;/g;
			s/&gt;/\&amp;gt\;/g;
			if ($putbody) {
				print "&lt;/head&gt;\n&lt;body&gt;\n";
				$putbody = 0;
			}
			print "$_";
			$putspace = 1;
		} elsif (/T[Ddm*]$/ &amp;&amp; $putspace) {
			print "\n";
			$putspace = 0;
		} elsif (/Tc$/) {
			$bigspace = 0;
			if (/^([3-9]|[1-9][0-9]+)\..*Tc$/) {
				$bigspace = 1;
			}
		}
	}
}
if ($putbody) {
	print "&lt;/head&gt;\n&lt;body&gt;\n";
}
print "&lt;/body&gt;\n&lt;/HTML&gt;\n";

close(INP);
system("rm -f $ARGV[0].pdf $ARGV[0].ps");
</pre></body></html>