Print file question

H

Harvey

Hi everyone,
I have a print file( .prn) that i want to print it but when i open it with
word it shows several pages of numbers and when I print it it prints the same
numbers insted of printing the actual document which is only one page long.
Any idea about how can i fix this?
Thanks:)
 
J

Jay Freedman

A .prn file is a capture of the data that would normally be sent directly to
the printer, telling it which dots to print. It's specific to the particular
printer (or printer driver) that was selected when the file was created.
There's no way to get Word to print anything intelligible from it. All you
can do is file-copy it in binary mode to the printer (and even that may be
hard to do, if you have a USB printer instead of a parallel-port printer).

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
H

Harvey

Thanks Jay,
What do you exactly mean by "file-copy in binary mode" ? I thought with
using .prn files we can move printable files from computer to computer and
print it with the same printer. If we can't print the actual document with a
..prn file so what is the usage of this type of files?
thanks:)
 
O

old man

Hi,

A prn file is a file that can be sent to a PCL (usually a HP) printer. To
see how to do this (print the file) see the support note at:
http://support.microsoft.com/kb/158081/en-us

Prn files was used to save the output of file (so users could not edit the
file-just print it). To view the file there are multiple approaches which you
can find by googling "prn file windows."

The current practice is to either create a PDF file or a mdi (Microsoft
Document Office Image Writer) file that users can view or print. To create a
mdi file from Word 2003 use File--> Print and the select the Microsoft
Document Office Image Writer from the drop down list.

old man
 
K

Karl E. Peterson

Harvey said:
I have a print file( .prn) that i want to print it but when i open it with
word it shows several pages of numbers and when I print it it prints the same
numbers insted of printing the actual document which is only one page long.
Any idea about how can i fix this?

It's unclear if you're intending to do this programatically or manually? If the
latter, the other responses about doing a binary file copy are right on target. If
you're using VBA, take a look at http://vb.mvps.org/samples/Spool for a BAS module
you can drop right into your project and submit these PRN files directly to the
Windows print spooler. Here's the general idea:

Public Sub SpoolFile(sFile As String, PrnName As String, Optional AppName As
String = "")
Dim hPrn As Long
Dim Buffer() As Byte
Dim hFile As Integer
Dim Written As Long
Dim di As DOC_INFO_1
Dim i As Long
Const BufSize As Long = &H4000
'
' Extract filename from passed spec, and build job name.
' Fill remainder of DOC_INFO_1 structure.
'
If InStr(sFile, "\") Then
For i = Len(sFile) To 1 Step -1
If Mid(sFile, i, 1) = "\" Then Exit For
di.pDocName = Mid(sFile, i, 1) & di.pDocName
Next i
Else
di.pDocName = sFile
End If
If Len(AppName) Then
di.pDocName = AppName & ": " & di.pDocName
End If
di.pOutputFile = vbNullString
di.pDatatype = "RAW"
'
' Open printer for output to obtain handle.
' Set it up to begin recieving raw data.
'
Call OpenPrinter(PrnName, hPrn, ByVal 0&)
Call StartDocPrinter(hPrn, 1, di)
Call StartPagePrinter(hPrn)
'
' Open file and pump it to the printer.
'
hFile = FreeFile
Open sFile For Binary Access Read As hFile
'
' Read in 16K buffers and spool.
'
ReDim Buffer(1 To BufSize) As Byte
For i = 1 To LOF(hFile) \ BufSize
Get #hFile, , Buffer
Call WritePrinter(hPrn, Buffer(1), BufSize, Written)
Next i
'
' Get last chunk of file if it doesn't
' fit evenly into a 16K buffer.
'
If LOF(hFile) Mod BufSize Then
ReDim Buffer(1 To (LOF(hFile) Mod BufSize)) As Byte
Get #hFile, , Buffer
Call WritePrinter(hPrn, Buffer(1), UBound(Buffer), Written)
End If
Close #hFile
'
' Shut down spooling process.
'
Call EndPagePrinter(hPrn)
Call EndDocPrinter(hPrn)
Call ClosePrinter(hPrn)
End Sub

Complete source at the link above.
 
J

Jay Freedman

In the Bad Old Days when everybody had their printers attached to
serial port COM1: (have you ever heard of that?), you could use the
DOS command

COPY /b myfile.prn COM1:

to copy the binary file (that's the meaning of the /b switch) from
disk to the serial port. Some printers used a parallel port, so you
would use LPT1: instead of COM1: in the command.

I've never seen an equivalent for a USB-connected printer, since DOS
predated USB and the pseudo-DOS command processor in Windows doesn't
recognize USB as a destination for the COPY command. If you scrounge
around the freeware/shareware web sites, you might find a program that
does some magic to make it work.

Failing that, .prn files are pretty useless. If you can get the
document that was used to make your .prn file, just print it normally.
Or ask for a PDF version, which you can print from Adobe Reader.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
K

Karl E. Peterson

Jay Freedman said:
I've never seen an equivalent for a USB-connected printer, since DOS
predated USB and the pseudo-DOS command processor in Windows doesn't
recognize USB as a destination for the COPY command. If you scrounge
around the freeware/shareware web sites, you might find a program that
does some magic to make it work.

Simple stuff, actually. See http://vb.mvps.org/samples/Spool for both the code, and
a compiled EXE, that will submit any file to the print queue for any attached
printer.
 
H

Harvey

Thank you guys,
very helpful .

Karl E. Peterson said:
It's unclear if you're intending to do this programatically or manually? If the
latter, the other responses about doing a binary file copy are right on target. If
you're using VBA, take a look at http://vb.mvps.org/samples/Spool for a BAS module
you can drop right into your project and submit these PRN files directly to the
Windows print spooler. Here's the general idea:

Public Sub SpoolFile(sFile As String, PrnName As String, Optional AppName As
String = "")
Dim hPrn As Long
Dim Buffer() As Byte
Dim hFile As Integer
Dim Written As Long
Dim di As DOC_INFO_1
Dim i As Long
Const BufSize As Long = &H4000
'
' Extract filename from passed spec, and build job name.
' Fill remainder of DOC_INFO_1 structure.
'
If InStr(sFile, "\") Then
For i = Len(sFile) To 1 Step -1
If Mid(sFile, i, 1) = "\" Then Exit For
di.pDocName = Mid(sFile, i, 1) & di.pDocName
Next i
Else
di.pDocName = sFile
End If
If Len(AppName) Then
di.pDocName = AppName & ": " & di.pDocName
End If
di.pOutputFile = vbNullString
di.pDatatype = "RAW"
'
' Open printer for output to obtain handle.
' Set it up to begin recieving raw data.
'
Call OpenPrinter(PrnName, hPrn, ByVal 0&)
Call StartDocPrinter(hPrn, 1, di)
Call StartPagePrinter(hPrn)
'
' Open file and pump it to the printer.
'
hFile = FreeFile
Open sFile For Binary Access Read As hFile
'
' Read in 16K buffers and spool.
'
ReDim Buffer(1 To BufSize) As Byte
For i = 1 To LOF(hFile) \ BufSize
Get #hFile, , Buffer
Call WritePrinter(hPrn, Buffer(1), BufSize, Written)
Next i
'
' Get last chunk of file if it doesn't
' fit evenly into a 16K buffer.
'
If LOF(hFile) Mod BufSize Then
ReDim Buffer(1 To (LOF(hFile) Mod BufSize)) As Byte
Get #hFile, , Buffer
Call WritePrinter(hPrn, Buffer(1), UBound(Buffer), Written)
End If
Close #hFile
'
' Shut down spooling process.
'
Call EndPagePrinter(hPrn)
Call EndDocPrinter(hPrn)
Call ClosePrinter(hPrn)
End Sub

Complete source at the link above.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top