#!/usr/bin/perl -w use strict; use PDF::Create; use Net::SMTP; use MIME::Lite; #opens ascii file or else! open TEXT_FILE, "textsample" or die " No text file to open! $!\n"; #sets text file to new array textstrings each line is an element my @textstrings=; close TEXT_FILE; #creates new pdf file and sets initial attributes my $pdf = new PDF::Create('filename' => 'test1.pdf', 'Author' => 'Aseidas Blauvelt', 'Title' => 'Test Invoice to PDF', 'Version' => '1.3'); #sets to landscape orientation my $root = $pdf->new_page('MediaBox' => [ 0, 0, 792, 612 ]); #give my page the properties of root page my $page = $root->new_page; #give me one font my $f1 = $pdf->font('Subtype' => 'Type1', 'Encoding' => 'WinAnsiEncoding', 'BaseFont' => 'Courier'); #set y postition to top left of page my $y=600; # initilize starting array element my $start=0; foreach $start (@textstrings) { #add string of text from @textstrings to pdf $page->string($f1, 10, 20, $y, $start); #move y position down 10 pixels $y= $y-9; } #add mandatory pdf elements and go ! $pdf->close; &mailpdf; ################################################################## sub mailpdf { #We don't want to use mime to send the message we don't have sendmail #lets use smtp instead, we still need mime to create the multi part message. MIME::Lite->send('smtp', "smtp.someisp.net", Timeout=>60); #create new message headers my $msg = MIME::Lite->new( From =>'someone@someisp.com', To =>'someone@someisp.com', Cc =>'someone@someisp.com, someone@someisp.com', Subject =>'Text invoice converted to pdf', Type =>'multipart/mixed' ); #attach plain text (body) of message $msg->attach(Type =>'TEXT', Data =>"The attached pdf was converted from text and mailed to\nyou from the same Perl program"); #attach the pdf to send, after some confusion, path is the path+name of the file #filename is the name you want it to have as your atachment $msg->attach(Type =>'document/pdf', Path =>'/home/aseidasb/perl/txt2pdf/test1.pdf', Filename =>'test2.pdf', Disposition => 'attachment' ); #done send it ! $msg->send(); }