#!/usr/bin/perl use strict; use warnings; use CGI; use CGI::Carp qw(fatalsToBrowser); my $q=CGI->new; use RTF::HTML::Converter; use PDF::FromHTML; print $q->header; print $q->start_html; my $base_directory = '.'; my $base_filename = 'text_only1'; my $rtf_file = "$base_directory/$base_filename" . '.rtf'; my $html_file = "$base_directory/$base_filename" . '.html'; my $pdf_file = "$base_directory/$base_filename" . '.pdf'; open (RTF_FILE, "< $rtf_file") || die "Couldn't open RTF file: $!"; open (HTML_FILE, "> $html_file") || die "Couldn't open HTML file: $!"; # Convert the rtf file to HTML format my $file = RTF::HTML::Converter->new(output => \*HTML_FILE); $file->parse_stream( \*RTF_FILE ) || die "Error converting RTF to HTML: $!"; close RTF_FILE; close HTML_FILE; print "Converted RTF to HTML.
\n"; # Convert the HTML file to PDF format my $pdf = PDF::FromHTML->new( encoding => 'utf-8' ); $pdf->load_file($html_file); $pdf->convert( Font => '/path/to/font.ttf', LineHeight => 10, Landscape => 0, ); $pdf->write_file($pdf_file); print "Converted HTML to PDF.
\n"; print $q->end_html;