#!/usr/bin/perl use strict; use warnings; #since first page gets treated like the end of a chapter #we start with end_chapter being true. my $end_chapter = 1; my $time = time(); #line required to redirect output to postprocessor (ie perfectbinder) my $to_pp = '<>setpagedevice \n'; #line to force chapterization my $chapter = 'true [] /110pProcs /ProcSet findresource /setchapters get exec \n'; #my $outfile = "/var/spool/drop_box/autoq/".$time.".print"; my $outfile = "d:/customer files/WPS/Quint.out"; my $infile = $ARGV[0]; open (OUT, ">".$outfile) or die "Can't create temp file!!!!!!!!!"; open (IN, "<".$infile); while (){ #if its the KDKHost line, skip it my $line = del_KDKHost($_); #handle chapter endings - currently denoted by null OutputType $line = chapterize($line); if ($end_chapter) { handleSeps(); } else { print OUT "$line"; } } sub del_KDKHost { #if this the KDKHost line, delete it my $line = shift; if ($line =~ m/^%KDKHost:/){ $line = ""; } return $line; } sub chapterize { my $line = shift; if ($line =~ m!<>setpagedevice!) { $line = $chapter; } $end_chapter = 1; return $line; } sub handleSeps { #if we just made a chapter, or this is the first page of the file #we have to make the next 2 pages come out of the top exit my $counter= 0; #if this is the pagenumber line, increment counter #we only need work with 2 pages while ( && $counter<=3) { #if we have started a new page #increment page counter and if we are on the 3rd page #since chapter break, insert line for output to perfect binder if ($_ =~ /%%BeginPageSetup/){ print "STARTED NEW PAGE"; $counter++; if ($counter==3){ $_ .= "\n $to_pp"; $counter = 0; } #if it is the OutputType line for this page, change to top output elsif ($_ =~ m!<>setpagedevice!){ $_ =~ s/Stacker/top/; } } print OUT $_; } $end_chapter = 0; }