Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing via NT, into a file?

Status
Not open for further replies.

youradds

Programmer
Joined
Jun 27, 2001
Messages
817
Location
GB
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
 
Forgive me but what exactly is your question?



``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
Hi,

Basically, I need a way of passing a .doc file, into the printer queue (on our NT server), and then output it as PDF (via an add-on program that we've installed).

So, in short;

Perl script > Passes .doc into printer > saves .doc locally > Perl script reads this file line-by-line, and lets the user download the PDF version.

The part in bold is what I need help with :) The other part I can handle fine (Perl's my main programming language, so I'm not a newbie .. I just don't know how to do this :().

Eventually, I'd like to do more with the PDF's (watermarking, headers, etc)... but I need to get this part going first <G>

TIA

Andy
 
I cannot vouch for the correctness of this script (as I never had a chance to actually finish it before I lost interest), but this uses the PDFCreator printer driver (found on SourceForge) to convert Word documents to PDFs.

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

my $dir = '/public_html/temp';
my $Word = Win32::OLE->new('Word.Application', 'Quit');
my $original_printer = $Word->ActivePrinter;

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

sleep 2;

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

chdir "$dir";

while(defined(my $filename = glob("*.doc"))) {
    $Word->Documents->Open("$dir/$filename", {'ReadOnly' => 1,}) or die("Can't access file ", Win32::OLE->LastError());
    $Word->ActiveDocument->PrintOut({
	'Background' => 0,
	'Append'     => 0,
	'Range'      => wdPrintAllDocument,
	'Item'       => wdPrintDocumentContent,
	'Copies'     => 1,
	'PageType'   => wdPrintAllPages,
	'PrintToFile'=> 0,
#	'OutputFileName' => "c:\\temp2\\$filename.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();

- Rieekan
 
OMG.. you are a STAR! Thats about the 100th thing I've tried... and it works!!!! You are a life saver :)

Thanks again.

Andy
 
Hey, no problem. Glad I could find that code snippet in my script archives (using Perl of course [wink]).

- Rieekan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top