print to file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers print to file
# 1  
Old 09-18-2012
Question print to file

Hello.

The company I work for would like to stop using these big ol' Genicom 4440 printers and create PDFs instead. The cost for maintenance and paper has gotten too high. Ideally whenever someone prints in Unix it will produce a (plain text) file in a folder on a windows server. I believe this is called a print image file.

We have other software that will process it and output the PDF.

I am not an experience user. I'm not afraid to try and do things myself, which I have, but when you get down to it I just don't know what I'm doing . I've logged in as root, gone into sco admin, and messed around trying to set up a printer, but it never works.

Any time I search the web, I can find step by step instructions on setting up a printer in windows to be remote printer for Unix, but only a vague description on how to set things up on the Unix side.

Can this be done, and if so what are my first steps in getting this accomplished?

Any thoughts or advice is much appreciated. Thank you.

Oh and we are running SCO OpenServer release 5 if that helps.

I originally posted this under the SCO section but I think it belongs here under Unix for dummies.
# 2  
Old 09-18-2012
consider alternatives:

Do you have an sftp/ftp server installed on a windows box somewhere?

If so, just sftp/ftp the file you want to print over to the windows server. Then play with the file over there. If that is more convenient.

On the SCO box, if you have perl, there are modules that create pdf files from flat text files. You simply add the perl library files to /usr/lib/perl5/.... (wherever you have your perl libraries) and run the code on each file. (this also works on Windows)

PDF::Create - search.cpan.org

has extensive sample bits of perl code.

With regard to "printing" , create an alias for lp that is really your perl/ftp script, place it in /etc/profile
Code:
# last line of code in /etc/profile
alias lp='/path/to/my/perl/code/script.pl'


Last edited by jim mcnamara; 09-18-2012 at 12:14 PM..
# 3  
Old 09-18-2012
Common misconception these days that PDF and HTML are the only viable text formats... Add a carriage-return and .txt still works great. Better than PDF for many purposes since they're trivial to edit and you can append to them with no fuss.
# 4  
Old 09-18-2012
There are some instances were FTP works. Thats what I do. It works great for me. However, the work I do produces a data file and I get to chose what to do with it. I'm one of a dozen users. The work the other users are doing results in reports printing off. Custom reports like year to date financial information on clients for example. I have no idea where that data is coming from. There isn't anybody in our company that knows COBOL anymore. Our programmer that wrote all this custom stuff has probably passed away. We can't get a hold of him. I do see /usr/lib/perl5/ but I don't know if that would be a solution I could implement. I don't how to edit the code that is executed when something gets sent to a printer.

---------- Post updated at 11:39 AM ---------- Previous update was at 11:34 AM ----------

I don't want unix to create PDFs. I want a plain text file to appear in a folder instead of being printed. From there I'm going to use software to map data from the text file out into fields and store it in a SQL database and do some archiving. The format I spit the report back out in doesn't have to be PDF but plain txt presents problems. I don't want anyone who looks at a report to be able to edit anything. If a report says we are to pay a client a certain amount of money, I don't want someone changing that.

---------- Post updated at 01:14 PM ---------- Previous update was at 11:39 AM ----------

My original thoughts were that I could set up a generic printer on a windows machine that printed to a file, then share that printer and install it on unix. Make it my default printer and remove the Genicoms. Not that easy though huh?

Last edited by kolsen; 09-18-2012 at 03:07 PM..
# 5  
Old 09-18-2012
A file solution would be the most straightforward, especially if you want a PDF. Instead of n levels of printers, just make a file. Then the problem becomes the simpler one of getting the files where you want.

Looking into Perl's PDF::Create module...

Last edited by Corona688; 09-18-2012 at 04:31 PM..
# 6  
Old 09-18-2012
This takes raw text on stdin and writes a PDF on stdout. Wrap text to 80 columns before you feed it into it.

Adapted from here.

Code:
#!/usr/bin/perl

use PDF::Create;

my      $fsize=12;
my      $xmargin=0.25*72,       $ymargin=0.5*72;
my      $ymin=0+$ymargin,       $ymax=(11*72)-$ymargin,
        $xmin=0+$xmargin,       $xmax=(8.5*72)-$xmargin,
        $n=0;

my $pdf = new PDF::Create(      'fh'       => *STDOUT,
                                'Version'  => 1.2,
                                'PageMode' => 'UseOutlines',
                                'Author'   => 'Some Guy',
                                'Title'    => 'Log File',       );

my $root = $pdf->new_page(      'MediaBox' => [ 0, 0, 8.5*72, 11*72 ]);

# Add a page which inherits its attributes from $root
my $page = $root->new_page;

# Prepare 2 fonts
my $f1 = $pdf->font(            'Subtype'  => 'Type1',
                                'Encoding' => 'WinAnsiEncoding',
                                'BaseFont' => 'Courier'         );

my $f2 = $pdf->font(            'Subtype'  => 'Type1',
                                'Encoding' => 'WinAnsiEncoding',
                                'BaseFont' => 'Courier-Bold');

$page->stringc($f2, 40, 306, 426, "Log File");
$page->stringc($f1, 20, 306, 396, "Generated on ".`date`);

while(!eof(STDIN))
{
        # Add another page
        my $page2 = $root->new_page;

        for($y = $ymax; $y >= $ymin; $y-=(144/$fsize))
        {
                if(eof(STDIN)) { break }
                my $line=<STDIN>;
                $page2->stringl($f1, $fsize, $xmin, $y, $line);
        }
}

# Add the missing PDF objects and a the footer then close the file
$pdf->close;

# 7  
Old 09-19-2012
The simplest solution is to create a "dumb" printer that saves the print file to a directory on the SCO system. This can be made flexible enough to allow different directories for different users/applications etc.
Implement either Samba, or Visionfs, depending upon which release of SCO that you have, and share the folder that contains the print files. The print files will then be available on a shared drive to the Windows software.
Depending upon how the cobol print files are created, there can be issues creating a PDF file from them.
If you have the source code for your cobol programs, I can provide support for those.
To create the printer:
Save the following script as /usr/spool/lp/model/file with owner bin, group lp perms 0550
Code:
:                                                          
#       @(#) file 25.2 95/03/27                            
#                                                          
#                                                          
# lp interface for print to file                           
#                                                          
                                                           
#Set up some global variables.                             
: ${SPOOLDIR:=/usr/spool/lp}                               
: ${LOCALPATH:=${SPOOLDIR}/bin}                            
                                                           
shift; shift; shift; shift; shift                          
files="$*"                                                 
for file in $files                                         
do                                                         
        cp ${file} /u/spool/`/bin/basename $file`                              
done                                                       
exit 0   
  ------end of script------                                                 
-bash-3.2# l file                                          
-r-xr-x---    1 bin      lp         267 Sep 19 11:25 file

Add a local printer
Select "file" as the model name
Select "/dev/null" as the device.
Create the directory /u/spool, or modify to suit.
Code:
cd /u
mkdir spool
chown root spool
chgrp group spool
chmod 0777 spool
chmod +t spool

This will give everyone read/write access to the directory, but only root will be able to remove the directory.
These 2 Users Gave Thanks to jgt For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use while loop to read file and use ${file} for both filename input into awk and as string to print

I have files named with different prefixes. From each I want to extract the first line containing a specific string, and then print that line along with the prefix. I've tried to do this with a while loop, but instead of printing the prefix I print the first line of the file twice. Files:... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

2. UNIX for Dummies Questions & Answers

Reading Xml file and print the values into the text file in columnwise?

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (4 Replies)
Discussion started by: sravanreddy
4 Replies

3. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

4. Shell Programming and Scripting

How to print excel file / csv file in solaris server ?

Hi, I have to print a excel file in solaris server. I am using lexmark printer with post script printer driver . But the problem is when i am using " lp -d <printer name> <somefile name.xls>" command it is not printing correctly. but for pdf file using the same command it printing correctly. ... (2 Replies)
Discussion started by: Sambuddha
2 Replies

5. Shell Programming and Scripting

Strings from one file which exactly match to the 1st column of other file and then print lines.

Hi, I have two files. 1st file has 1 column (huge file containing ~19200000 lines) and 2nd file has 2 columns (small file containing ~6000 lines). ################################# huge_file.txt a a ab b ################################## small_file.txt a 1.5 b 2.5 ab ... (4 Replies)
Discussion started by: AshwaniSharma09
4 Replies

6. Shell Programming and Scripting

Howto Print File Path or Print the Filename

I'm trying to clean up my samba share and need to print the found file or print the path of the image it tried to searched for. So far I have this but can't seem to get the logic right. Can anyone help point me in the right direction? for FILE in `cat list`; do if ; then ... (1 Reply)
Discussion started by: overkill
1 Replies

7. UNIX for Dummies Questions & Answers

find locked files, print file path, unlock file

using OS X and the Terminal, I'd like to find all locked files in a specified directory, unlock them, and print a list of those files that were unlocked how can I do this? I'm familiar with chflags nouchg for unlocking one file but not familiar with unix enough to do what I'd like. Thanks! (0 Replies)
Discussion started by: alternapop
0 Replies

8. Shell Programming and Scripting

Need shell script to read two file at same time and print out in single file

Need shell script to read two file at same time and print output in single file Example I have two files 1) file1.txt 2) file2.txt File1.txt contains Aaa Bbb Ccc Ddd Eee Fff File2.txt contains Zzz Yyy Xxx (10 Replies)
Discussion started by: sreedhargouda
10 Replies

9. Shell Programming and Scripting

search for the contents in many file and print that file using shell script

hello have a file1 H87I Y788O T347U J23U and file2 J23U U887Y I99U T556U file3 I99O J99T F557J file4 N99I T666U R55Y file5 H87I T347U file6 H77U R556Y E44T file7 Y788O K98U H8I May be using script we can use file1 to search for all the files and have the output H87I file5... (3 Replies)
Discussion started by: cdfd123
3 Replies
Login or Register to Ask a Question