Gossamer Forum
Home : General : Perl Programming :

Printing to PDFPrinter (locally).

Quote Reply
Printing to PDFPrinter (locally).
Hi,

Does anyone know of a way to utalize a program I've just downloaded, which lets you convert .doc files into .pdf. However, it sets up a printer on the machine, which I guess you then have to "pipe" into somehow.

Anyone got any suggestions? Smile

TIA

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Printing to PDFPrinter (locally). In reply to
Have you checked any of these from CPAN?

http://search.cpan.org/...Printer&mode=all

~Charlie
Quote Reply
Re: [Chaz] Printing to PDFPrinter (locally). In reply to
Hi,

Thanks.. I managed to get it working with the below :)

Code:
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Word';

my $Word = Win32::OLE->new('Word.Application', 'Quit')|| Win32::OLE->LastError();
my $original_printer = $Word->ActivePrinter|| Win32::OLE->LastError();

my $dir = $_[0];
my $source = $_[1];

my $filename = $source;
$filename =~ s/^.*(\\|\/)//g;


use Data::Dumper;
print "Values: " . Dumper(\@_);

$Word->{'ActivePrinter'} = "Win2PDF on NE00:";

sleep 2;

$Word->ChangeFileOpenDirectory("$dir");

chdir "$dir";

my $pdf = $filename;
$pdf =~ s/doc$/doc.pdf/i;

$Word->Documents->Open("$source", {'ReadOnly' => 1,}) or die("Can't access file $source. Reason: ", Win32::OLE->LastError());
$Word->ActiveDocument->PrintOut({
'Background' => 0,
'Append' => 0,
'Range' => wdPrintAllDocument,
'Item' => wdPrintDocumentContent,
'Copies' => 1,
'PageType' => wdPrintAllPages,
'PrintToFile'=> 0,
'OutputFileName' => "d:\\tempPDF\\$pdf",
});
sleep 1;
$Word->ActiveDocument->{'Saved'} = "True";
sleep 2;
$Word->ActiveDocument->Close({
'SaveChanges' => wdDoNotSaveChanges,
'OriginalFormat' => wdOriginalDocumentFormat,
'RouteDocument' => 0,
});

sleep 2;
$Word->{'ActivePrinter'} = "$original_printer";
$Word->Quit();

One thing I do need help with though <G>

Don't suppose you know how to locally authenticate via a script? I've tried;

Code:
Win32::AuthenticateUser::AuthenticateUser("domain", "user, "pass") || die $Win32::GetLastError;

..but that doesn't work :|

TIA

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Printing to PDFPrinter (locally). In reply to
Can't help with the auth bit either. This doesn't sound too encouraging either:

Code:
This module is incomplete and is not being actively developed. No documentation exists (yet), and there may be bugs in the code.

http://aspn.activestate.com/...uthenticateUser.html

Have you tried searching through the ActiveState mailing list archives? There is bound to be something helpful there.

~Charlie
Quote Reply
Re: [Chaz] Printing to PDFPrinter (locally). In reply to
Hi,

Thanks for the reply. You gotta love Windows... huh?
Shocked

Quote:
http://aspn.activestate.com/...uthenticateUser.html

Have you tried searching through the ActiveState mailing list archives? There is bound to be something helpful there.

Yeah, still no luck :( Really starting to get on my nerves with this one. I *really* don't want to be giving out the user/pass to access the server, for obvious reasons :|

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!