Here's my simple pdf-writer script on Samba:

12:44:49 db root/# cat /usr/local/bin/printpdf.pl
#!/usr/bin/perl -w
use strict;
use Getopt::Long;

my $file ='';
my $user = '';
my $ps2pdf = `which ps2pdf`;
chomp $ps2pdf;

GetOptions( 'file=s' => \$file, 'user=s' => \$user) or die;
my $outfile = "/vol1/home/guest/$user-" . time . ".pdf";

$ps2pdf .= " /tmp/$file $outfile";

`$ps2pdf`;
unlink($file);

And in smb.conf:
[pdf]
        path = /tmp
        printer admin = rob
        guest ok = Yes
        printable = Yes
        postscript = Yes
        print command = /usr/local/bin/printpdf.pl -f %s -u %U
        lpq command =
        lprm command =

As it stands now, it writes to a file in the public share named for the
user and second the job is printed. It's not ideal, but working from all
Windows apps.

I've been trying to improve the naming scheme - I'd love to grab the title
of the file being printed. Here's the code I have to do so:

12:47:16 db root/# cat /usr/local/bin/printpdf.pl.job
#!/usr/bin/perl -w
use strict;
use Getopt::Long;
use POSIX qw(strftime);

my $localtime = localtime();
`echo '----- $localtime
$0 @ARGV' >> /vol1/home/guest/printpdf.log`;

my $exec = "$0 @ARGV";
my ($file,$user,$job);
my $ps2pdf = `which ps2pdf`;
chomp $ps2pdf;

GetOptions( 'file=s' => \$file, 'user=s' => \$user) or die;
$file = "/tmp/$file";

open PS, "<$file";
while (<PS>) {
  next unless /%%Title: (.*)$/;
  $job = $1;
  last;
}
close PS;

$job = time unless $job;
$job =~ s/[^\-_\.\w]/_/g;

my $outfile = "/vol1/home/guest/" . $user . "-" . $job . ".pdf";

$ps2pdf .= " $file $outfile";

`echo '$ps2pdf' >> /vol1/home/guest/printpdf.log`;
`$ps2pdf`;
unlink($file);

It opens the postscript file in /tmp and grabs the text after "%%Title: "
to assist in naming the file. This one works great for most applications,
but unfortunately not for AutoCAD, where no file is ever written and I
haven't been able to figure out why. Of course, AutoCAD has to be one big
reason for having the pdf writer...

Anyway, just thought I'd share. Hope it's useful.

Rob Martin

On Tue, 25 Mar 2003, Spider wrote:

> begin  quote
> On 25 Mar 2003 08:16:12 -0600
> Jimmie Fulton <[EMAIL PROTECTED]> wrote:
>
>
> > > # PDF creation:
> > ps2pdf(gs)
> >
> > On a side note:  I built a PDF server (samba/cups/ghostscript) for my
> > office here in Houston.  After the other techs in my company (which
> > never ran linux before) found out, I ended up building 12 more of
> > these PDF boxes in offices around the country.  Saving company a
> > crapload of money over a license for Acrobat Writer.
>
> Cool, could you post some rationale behind it and a description of what
> parts integrated into it?   Would be nice to know, since its a way of
> production environment that I've never used.  PDF format is simply
> something loathed and disgusted from my side, so ;)
>
>
> //Spider
>
>
> --
> begin  .signature
> This is a .signature virus! Please copy me into your .signature!
> See Microsoft KB Article Q265230 for more information.
> end
>


--
[EMAIL PROTECTED] mailing list

Reply via email to