Hylafax Mailing List Archives

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [hylafax-users] pdfs...



Hello, 
In response so that Lee said, for the company I needed for an electronic
management for documents, of document to format pdf.  For that I wrote a
script in Perl which precisely converted the received fax of format tiff
to the format PS and format pd.
the file PS is intended for the edition on a printer and file pdf for
the electronic management of documents. 
 it is enough to modify script for another use. 
 Here for my small contribution.

Of which here script

#!/usr/bin/perl
#
#
#
#
#
#
#
require "bin/call_date";

use File::Copy;

$sendmail = "|/usr/sbin/sendmail";

$Path_image =
"/archives/fax/".substr($date,4,2).substr($date,6,2).substr($date,2,2).substr($date,0,2)."/";


      open( STDERR ,"|logger -itfaxrcvd")
         ||die "$0\[$$]: cannot open  logger $!\n";

           if (@ARGV > 0){

               $FILE = $ARGV[0];
               $DEVICE = $ARGV[1];
               $COMMID = $ARGV[2];
               $MSG = $ARGV[3];
               $CIDNUMBER = $ARGV[4];
               $CIDNAME = $ARGV[5];
            }
            else{
               print STDERR "Error not argument Transmitted to
Faxrcvd\n";
            exit;
            }

           open(ETCSETUP,"./etc/setup.cache")
             ||die "$0\[$$]: cannot open  etc/setup.cache $!\n";

               @setup = <ETCSETUP>;

           close(ETCSETUP);

           foreach $line (@setup){

            ($name,$value) = split(/=/,$line);

            $Item {$name} = $value;
            $Item {$name} =~ s/'//;
            $Item {$name} =~ s/'//;
            }

        chop ($Item{"TIFFBIN"});



        $fax2ps = $Item{"TIFFBIN"}."/fax2ps";
        $tiff2ps = $Item{"TIFFBIN"}."/tiff2ps";
        $ps2pdf = "/usr/bin/ps2pdf12";
        $tiffinfo = $Item{"TIFFBIN"}."/tiffinfo";

        $Lprinter_Lx = "lexmark";
        $Lprinter_Ir = "ir2200";
        $Lprinter_Epson = "Epson_C82";
	$Lprinter_HP5550 = "HP-5550";

         if ( $MSG) {

            $Message = "The received document could not be
delivered".$DEVICE." following ".$MSG;
            &send_mail;
            exit;

	  }



#------------- On cree le repertoire du jour s'il n'existe pas

          if (open(DIR,$Path_image)){

            &convert_ps;

	    }
            else{
                 mkdir($Path_image , 0744);
                 system("chmod 0777 ". $Path_image);
                 &convert_ps;
            }

exit;

sub convert_ps{


     ($file,$dummy) = split(/\./,$FILE);

     ($dummy,$file) = split(/\//,$file);


     $Nro_File = substr($file,3);
     $file = $Path_image.$file;




     $Info_File = "./tmp/Info_".$$;

        system("./bin/fax_convert ./$FILE >$Info_File");

        open(C,"$Info_File");
        @INFO = <C>;
        close(C);


     foreach $Param (@INFO){

        ($parametre,$value) = split(/=/,$Param);
         chop($value);
         $PARAM{"$parametre"} = $value;
      }

       system("$tiff2ps -a1 -O". $file.".ps ".$FILE." 2>/dev/null");


       &Include_Fax_Number(@bytes);

             if ($DEVICE eq "ttyS10"){
		      $Lprinter = $Lprinter_Epson;
              }
	      elsif ($DEVICE eq "ttyS7"){
		      $Lprinter = $Lprinter_HP5550;
	      }
	      else{
		      $Lprinter = $Lprinter_Lx;
	      }

	      system("/usr/bin/lpr-cups -P".$Lprinter." ".$file."_.ps"."\n");

       system("$ps2pdf -g".$PARAM{'GW'}."\\"."x".$PARAM{'GL'}."
-r".$PARAM{'RW'}."\\"."x".$PARAM{'RL'}." ".$file."_.ps"."
".$file.".pdf");

       system("chmod -R 777 $file.pdf");
       system("rm -f $Info_File $file.ps $file"."_.ps");
}

sub send_mail{

$DATA{'subject'}="Document reçu en Fax";
$DATA{'receiv'}="sopamii"."\@"."sopamii.fr";
$DATA{'mailaddr'}="Agent de Reception du Fax";
$boundary = $$;

         open( MAIL, "$sendmail ".$DATA{'receiv'} )
             ||die "$0\[$$]: ne peut ouvrir sendmail:
".$DATA{'receiv'}.": $!\n";

         print MAIL "Subject: $DATA{ 'subject' }\n";
         print MAIL "From:$DATA{'mailaddr'}";
         print MAIL "Reply-to:$DATA{'mailaddr'}\n";
	 print MAIL "To: ".$DATA{'receiv'}."\n";
	 print MAIL "MIME-Version: 1.0"."\n";
	 print MAIL "Content-Type: multipart/mixed;"."\n";
	 print MAIL " boundary="."\"".$boundary."\""."\r\n";
	 print MAIL "--".$boundary."\n";
	 print MAIL "Content-Type: text/plain; charset="."us-ascii"."\n";
	 print MAIL "Content-Transfer-Encoding: 8bit"."\r\n\r\n";
         print MAIL $Message."\r\n";
	 print MAIL "--".$boundary."\n";
}

sub Include_Fax_Number {

         my (@Mbytes) = @_;


           open(FAX_TMP,">$file"."_.ps");
           open(FAXPS,"$file".".ps");

$Quit = 0;
$Image_Find = 0;
$End_Of_Page = 1;

          while ( !($Quit) ){

	     if (!($Image_Find)) {
                  &Search_Entete;
               }
	     elsif (!($End_Of_Page)){
                  &Search_Page(@bytes);
		}

	  }
}
sub  Search_Entete{

           $line = <FAXPS>;
           while (substr($line,0,5) ne "image"  &&  substr($line,0,5) ne
"%%EOF"){

	     if (substr($line,0,11) eq "%ImageData:"){

                ($dumm1y,$dummy2,$format) =split(/ /,$line);

		    if (substr($format,0,1) < "2" ){

                        $type_code = "1";
                        ## require
                        require "bin/convert_Nro.pl";
		      }
                    else {
                        $type_code = "2";
                        ## require
                        require "bin/convert_Nro.pl";
                      }
	      }

              print FAX_TMP ($line);
              $line = <FAXPS>;

	    }

              print FAX_TMP ($line);
	   if (substr($line,0,5) eq "%%EOF"){
            $Image_Find = 1;
            $End_Of_Page = 1;
            $Quit = 1;
	    }
            else {
                  $Image_Find = 1;
                  $End_Of_Page = 0;

            }


}

sub Search_Page{
              my (@bytes) = @_;

$line_find = "";
$Index_Line = 0;
$Ok_Valid = 0;
$line_OK = "";
$Number_Read = 0;

            $line = <FAXPS>;
            chop($line);

            while (substr($line,0,3) ne "end"){

                  $line_find = $line_find.$line;

                 if (length($line_find) >"432")
                  {

                     $line_OK = substr($line_find,0,432);
                     $line_find = substr($line_find,432);

                     if ($Number_Read > "100")
                      {

                        while ($Index_Line <= $number_line &&
!($Ok_Valid))
                         {

                               substr($line_OK,$index_run,$index_lenght)
= $bytes[$Index_Line];

                               $Ok_Valid = 1;
                               $Index_Line = $Index_Line + 1;
		         }

                         $Ok_Valid = 0;
		      }
                     $Number_Read = $Number_Read + 1;
                     print FAX_TMP ($line_OK."\n");
		   }
                  $line = <FAXPS>;
                  chop($line);
		}

		  if(substr($line,0,3) eq "end"){
                    if (length($line_find) != "0"){
                      print FAX_TMP ($line_find."\n");
		    }
		  }
	
print FAX_TMP ($line."\n");
$End_Of_Page = 1;
$Image_Find = 0;

}


Le mar 09/08/2005 à 16:04, Lee Howard a écrit :
> Samir Faci wrote:
> 
> >I Want to have hylafax receive faxes by default in pdf format.  Is there 
> >anyway to do that?  I know I can setup FaxDispatch to email the files as 
> >pdfs.  But is there any way to have hylafax receive the files by default in 
> >pdf format? 
> >  
> >
> 
> No.  Fax communication commonly uses MH, MR, and MMR image data 
> compression formats.  Although it is true that you can put a PDF wrapper 
> around these, the "native" format of these compression types is 
> generally considered to be TIFF, although some other fax applications 
> will actually store these data formats "raw" onto disk.
> 
> Some HylaFAX features also depend on the TIFF tags that are stored in 
> the image files themselves, and although this information could (in 
> theory) be stored in a PDF, HylaFAX currently has no way to glean that 
> data from PDF markers, and no TIFF-to-PDF converter has been taught to 
> take the TIFF tag information and to store it in PDF markers.
> 
> So you *could* convert the files in the recvq from TIFF to PDF with 
> FaxDispatch, but you'd lose some valuable information from the TIFF 
> files and some parts of HylaFAX may not subsequently function as expected.
> 
> Lee.
> 
> ____________________ HylaFAX(tm) Users Mailing List _______________________
>   To subscribe/unsubscribe, click http://lists.hylafax.org/cgi-bin/lsg2.cgi
>  On UNIX: mail -s unsubscribe hylafax-users-request@xxxxxxxxxxx < /dev/null
>   *To learn about commercial HylaFAX(tm) support, mail sales@xxxxxxxxx*
> 
> 


____________________ HylaFAX(tm) Users Mailing List _______________________
  To subscribe/unsubscribe, click http://lists.hylafax.org/cgi-bin/lsg2.cgi
 On UNIX: mail -s unsubscribe hylafax-users-request@xxxxxxxxxxx < /dev/null
  *To learn about commercial HylaFAX(tm) support, mail sales@xxxxxxxxx*



Home
Report any problems to webmaster@hylafax.org

HylaFAX is a trademark of Silicon Graphics Corporation.
Internet connectivity for hylafax.org is provided by:
VirtuALL Private Host Services