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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing PRN-File with WORD

Status
Not open for further replies.

ToonKayser

Programmer
Jun 20, 2000
23
0
0
DE
I want to write a word-document to a prn-file.
Before that I filled that document and all works well.
But the last thing I want to do is write this document to a PRN-File.
This file is transfered afterwards and is printed with some remote application.

I did this before with asp and the statement was:
objWord.Application.ActiveDocument.Printout 0,,,"C:afile.prn"

and this was ok.

Now I am trying to use only ColdFusion and no ASP for this.
All I get is this error:
COM error 0x80020005. Typkonflikt.

My statements in CF are like this:

<cfset no = false>
<cfset yes = true>
<cfset zero = 0>
<cfset file = &quot;c:\#namedoc#.prn&quot;>
<cfset ret = objDoc.SaveAs(&quot;c:\#namedoc#.doc&quot;)>
<cfset ssret = objDoc.PrintOut(yes,no,zero, &quot;#file#&quot;)>

The saveAs stement works fine.
But all the combinations I've tried with Printout all failed.
Help me please..... I am going insaaaaaaaaaaaaaaaane!

Toon

ps. Is there any documentation on this for ColdFusion?
 
Got this from the site. Hope it helps.
(see newdoc.printout() ) below...

This example shows how to print a Word document from COM:

<!--- Try to connect to the Word application object --->
<CFTRY>
<!--- If it exists, connect to it --->
<CFOBJECT
ACTION=&quot;CONNECT&quot;
CLASS=&quot;Word.Application&quot;
NAME=&quot;objWord&quot;
TYPE=&quot;COM&quot;>
<CFCATCH>
<!--- The object doesn't exist, so create it --->
<CFOBJECT
ACTION=&quot;CREATE&quot;
CLASS=&quot;Word.Application&quot;
NAME=&quot;objWord&quot;
TYPE=&quot;COM&quot;>
</CFCATCH>
</CFTRY>

<CFSCRIPT>
/* This will open Word if running locally */
objWord.Visible = true;

/* This returns the 'Documents' collection of the Word object */
objDoc = objWord.Documents;

/* Open the document */
newDoc = objDoc.open(&quot;D:\template.doc&quot;);

... Additional Code ....

/* Save the changes */
newDoc.Save();

OR

/* If you want to save it as a new document */
newDoc.SaveAs(&quot;D:\template_new.doc&quot;);

/* Send the document to the server's default printer */
newDoc.PrintOut();

/* Close the document */
newDoc.Close();

/* Quit Word */
objWord.Quit();
</CFSCRIPT>
 
Thank you. But it isn't quite what I mean.
I want to write a 'printfile'.
A file that can be printed on a computer without Word installed there.
The suffix of such a file is PRN.
I know the 4th argument of Printout is the filename.
But the problem are the 3 arguments before that.
I don't seem to get the syntax right.

The arguments are 'background', 'Append' and 'Range'.
Argument 1 and 2 are Boolean and the third is a number.

How to get the statement right?

Regards

Toon

 
Well, I found out how it works. It was in a google.newsgroup. Somebody found out how to make the arguments for printout work. (I would like to know HOW this guy found out how it's done)
I give the code here because I am sure a lot of people struggle with this COM-thing.
What I do in this program is read a wordfile that is intended to send to a customer along with his order. There is a message for that customer and there are 7 empty Formfields in it.
This program fills the formfields from a coldfusionform and puts the order-nr in the footer of the word-document. After that the File is saved as a PRN-File because it will be printed elsewhere on a computer where Word isn't installed.
The order-pick-program prints the document in dos (See below) and the order-picker can tell to which order it belongs because of
the ordernr in the footer.
I know it's a very special problem, but perhaps somebody could use this example.

<cfset adresdaten = ''>
<cfset adresdaten = listappend(adresdaten,'Anrede')>
<cfset adresdaten = listappend(adresdaten,'name')>
<cfset adresdaten = listappend(adresdaten,'Abteilung')>
<cfset adresdaten = listappend(adresdaten,'Strasse und Hausnummer')>
<cfset adresdaten = listappend(adresdaten,'NL')>
<cfset adresdaten = listappend(adresdaten,'PLZ')>
<cfset adresdaten = listappend(adresdaten,'Ort')>
<cfset adresdaten = listappend(adresdaten,'xx')>
<cfset adresdaten = listappend(adresdaten,'xx')>
<cfset namedoc = &quot;b2&quot;>
<cfset auftrag = &quot;MI131148&quot;>

<!--- Try to connect to the Word application object --->
<cftry>
<!--- If it exists, connect to it --->
<cfobject
action=&quot;CONNECT&quot;
class=&quot;Word.Application&quot;
name=&quot;objWord&quot;
type=&quot;COM&quot;>
<cfcatch>
<!--- The object doesn't exist, so create it --->
<cftry>
<cfobject
action=&quot;CREATE&quot;
class=&quot;Word.Application&quot;
name=&quot;objWord&quot;
type=&quot;COM&quot;>
<!--- Word isn't installed, or ColdFusion doesn't have access to it --->
<cfcatch type=&quot;Object&quot;>
<font color=&quot;RED&quot;>Cannot create Word Object<br>
Make sure Word is installed and that ColdFusion has permissions to
use the Word COM objects.</font>
<cfabort>
</cfcatch>
</cftry>
</cfcatch>
</cftry>
<!--- formfelder füllen start 7 stück --->
<cfset objWord.Visible = false>
<cfset objDoc = objWord.Documents>
<cfset newDoc = objDoc.Open(&quot;c:\inetpub\<cfset theFields = newDoc.FormFields>
<cfset a = 0>
<CFLOOP COLLECTION=&quot;#theFields#&quot; ITEM=&quot;this&quot;>
<cfset a = a + 1>
<cfif a lt 8>
<cfset this.Result = listgetat(adresdaten,a)>
</cfif>
<CFOUTPUT>
#this.Name#<BR>
#this.Result#<P>
</CFOUTPUT>
</CFLOOP>


<!--- füllen footer mit auftrag-nr --->
<CFSCRIPT>
/* Get the doc */
objDocs = objWord.Documents;
objDoc = objDocs.Open(&quot;c:\inetpub\/* Get the Sections collection */
objSecs = objDoc.Sections;
/*footer */
/* Get the first footer of the first section */
objFirstSec = objSecs.Item(1);
objFirstSecFooters = objFirstSec.Footers;
objFirstSecFirstFooter = objFirstSecFooters.Item(1);
sFooterRange = objFirstSecFirstFooter.Range;
/* Get the original footer text */
sOrigFooterText = sFooterRange.Text;
/* Set the new footer text */
sFooterRange.Text = &quot;Nr #auftrag#&quot;;
/* Get the new footer text */
sNewFooterText = sFooterRange.Text;

/* set printer */
newApp = objDoc.Application;
newApp.ActivePrinter = &quot;HP LaserJet 4000 Series PCL&quot;;
ActivePrinter = &quot;HP LaserJet 4000 Series PCL&quot;;
</cfscript>





<!--- Vorbereiten drucken PRN-File --->
<!--- Create variables for true and false values --->
<cfset comtrue = isbinary(0)>
<cfset comfalse = isbinary('a')>

<!--- zuerst komplette Datei als DOC drucken --->
<cfset ret = objDoc.SaveAs(&quot;c:\#namedoc#.doc&quot;)>
<cfscript>
// WORD file path
WORDFilePath = &quot;c:\inetpub\// Destination path for printed output
PrintFile = &quot;c:\#namedoc#.prn&quot;;
// Disable alerts such as: 'Save this document?'
objWord.DisplayAlerts = false;
// Get the 'Documents' collection
objDoc = objWord.Documents;
// Open the WORD document
/* ist bereits geöffnet */
/* newDoc = objDoc.open(WORDFilePath); */
// Print the word document to a file
newDoc.PrintOut(comFalse, comTrue,0,PrintFile);
// Close the document
newDoc.Close();
// Quit Word
objWord.Quit();
</cfscript>

<!--- testen PRN-File in DOS: --->
<!--- copy /B b1.prn LPT1: --->

Best regards from

Toon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top