how to know what file to print?

  • Thread starter jabslim via DotNetMonster.com
  • Start date
J

jabslim via DotNetMonster.com

hi guys! i need help with printing. i want to print it with the filename
"c:\testfile.doc". i use the code below for it to disable the use of color
ink, but it doesnt print anything.

---------------------------------------------------------------------------
Dim printDoc As New Printing.PrintDocument
Dim currentPageNumber
Dim printern

printern = "EPSON Stylus C59 Series"

' Set the printer name and ensure it is valid. If not, provide a
message to the user.
printDoc.PrinterSettings.PrinterName = printern

If printDoc.PrinterSettings.IsValid Then

' If the printer supports printing in color, then override the
printer's default behavior.
If printDoc.PrinterSettings.SupportsColor Then

' Set the page default's to not print in color.
printDoc.DefaultPageSettings.Color = False
End If

printDoc.DocumentName = "c:\testfile.doc" '(name of file i want
to print)
currentPageNumber = 1
printDoc.Print()
Else
MessageBox.Show("Printer is not valid")
End If
 
A

Armin Zingler

jabslim via DotNetMonster.com said:
hi guys! i need help with printing. i want to print it with the
filename "c:\testfile.doc". i use the code below for it to disable
the use of color ink, but it doesnt print anything.
[...]
printDoc.DocumentName = "c:\testfile.doc" '(name of file
i want to print)
[...]
how come printDoc.Print() doesnt print testfile.doc? can you guys
please help me? thanks!


You completely misunderstood the purpose of the Printdocument class and
it's DocumentName property. You have to handle the Printdocument's
PrintPage event and draw text, lines, rectangles and whatever on your
own. The PrintDocument does not print any file for you.

The DocumentName property is just the name of the document that is
displayed in dialogs or in the printer spooler. It is not a file name.

See also:
http://msdn2.microsoft.com/en-us/library/a585x1he.aspx


Armin
 
K

kimiraikkonen

     hi guys! i need help with printing. i want to print it with thefilename
"c:\testfile.doc". i use the code below for it to disable the use of color
ink, but it doesnt print anything.

---------------------------------------------------------------------------
   Dim printDoc As New Printing.PrintDocument
   Dim currentPageNumber
   Dim printern

        printern = "EPSON Stylus C59 Series"

        ' Set the printer name and ensure it is valid. If not, provide a
message to the user.
        printDoc.PrinterSettings.PrinterName = printern

        If printDoc.PrinterSettings.IsValid Then

            ' If the printer supports printing in color, then override the
printer's default behavior.
            If printDoc.PrinterSettings.SupportsColor Then

                ' Set the page default's to not print in color.
                printDoc.DefaultPageSettings.Color = False
            End If

            printDoc.DocumentName = "c:\testfile.doc" '(nameof file i want
to print)
            currentPageNumber = 1
            printDoc.Print()
        Else
            MessageBox.Show("Printer is not valid")
        End If

This quite old article may help you to undestand:
http://www.vbdotnetheaven.com/UploadFile/mgold/PrintinginVBNET04202005015906AM/PrintinginVBNET.aspx
 
J

jabslim via DotNetMonster.com

thanks guys for the replies. but i want to print a .doc file(not a .txt file)
in black ink only. how do i do about this? because i tried the codes on the
internet and it worked fine for a .txt file. but when i tried to print a .doc
file, it prints abnormally(it prints boxes, special characters and things
that we cannot understand). can you guys teach me how to achieve the task i
want for my project? thanks!!


     hi guys! i need help with printing. i want to print it with the filename
"c:\testfile.doc". i use the code below for it to disable the use of color
[quoted text clipped - 36 lines]
This quite old article may help you to undestand:
http://www.vbdotnetheaven.com/UploadFile/mgold/PrintinginVBNET04202005015906AM/PrintinginVBNET.aspx
 
A

Armin Zingler

jabslim via DotNetMonster.com said:
thanks guys for the replies. but i want to print a .doc file(not a
.txt file) in black ink only. how do i do about this? because i
tried the codes on the internet and it worked fine for a .txt file.
but when i tried to print a .doc file, it prints abnormally(it
prints boxes, special characters and things that we cannot
understand). can you guys teach me how to achieve the task i want
for my project? thanks!!


MSFT Word is able to read and print .doc files. After you've installed
it, try this:

Dim psi As New ProcessStartInfo("g:\test.doc")

psi.Verb = "print"
Process.Start(psi)



Armin
 
K

kimiraikkonen

thanks guys for the replies. but i want to print  a .doc file(not a .txtfile)
in black ink only. how do i do about this? because i tried the codes on the
internet and it worked fine for a .txt file. but when i tried to print a .doc
file, it prints abnormally(it prints boxes, special characters and things
that we cannot understand). can you guys teach me how to achieve the task i
want for my project? thanks!!
     hi guys! i need help with printing. i want to print it with the filename
"c:\testfile.doc". i use the code below for it to disable the use of color
[quoted text clipped - 36 lines]

Could you try:

Dim process As New System.Diagnostics.ProcessStartInfo()
process.Verb = "print"
process.WindowStyle = ProcessWindowStyle.Hidden
process.FileName = "yourfile.doc"
process.UseShellExecute = True
System.Diagnostics.Process.Start(process)

i think works for PDFs but may work also with docs.
 
J

jabslim via DotNetMonster.com

we kinda use the same code for printing .doc files.. the one i use is here
below:

Dim print_file As New ProcessStartInfo
print_file.UseShellExecute = True
print_file.Verb = "print"
print_file.WindowStyle = ProcessWindowStyle.Hidden
print_file.FileName = "c:\test.doc"
Process.Start(print_file)


assuming the printer is colored, this code prints the .doc file normally. but
what i need is to print it in black ink only. how do i do it? for example if
the test.doc has colored fonts, i just want the printer to print in only
black ink, so the printed output is in black fonts.

Armin said:
thanks guys for the replies. but i want to print a .doc file(not a
.txt file) in black ink only. how do i do about this? because i
[quoted text clipped - 3 lines]
understand). can you guys teach me how to achieve the task i want
for my project? thanks!!

MSFT Word is able to read and print .doc files. After you've installed
it, try this:

Dim psi As New ProcessStartInfo("g:\test.doc")

psi.Verb = "print"
Process.Start(psi)

Armin
 
J

jabslim via DotNetMonster.com

yah! i also use that code!haha i found it in the internet! but it prints
normally, i need to print it only in black ink. how do i do it?


guys, im really grateful for your quick replies!!
thanks guys for the replies. but i want to print  a .doc file(not a .txt file)
in black ink only. how do i do about this? because i tried the codes on the
[quoted text clipped - 16 lines]
Could you try:

Dim process As New System.Diagnostics.ProcessStartInfo()
process.Verb = "print"
process.WindowStyle = ProcessWindowStyle.Hidden
process.FileName = "yourfile.doc"
process.UseShellExecute = True
System.Diagnostics.Process.Start(process)

i think works for PDFs but may work also with docs.
 
K

kimiraikkonen

yah! i also use that code!haha i found it in the internet! but it prints
normally, i need to print it only in black ink. how do i do it?

guys, im really grateful for your quick replies!!




thanks guys for the replies. but i want to print  a .doc file(not a .txt file)
in black ink only. how do i do about this? because i tried the codes onthe
[quoted text clipped - 16 lines]
Could you try:
Dim process As New System.Diagnostics.ProcessStartInfo()
process.Verb = "print"
process.WindowStyle = ProcessWindowStyle.Hidden
process.FileName = "yourfile.doc"
process.UseShellExecute = True
System.Diagnostics.Process.Start(process)
i think works for PDFs but may work also with docs.

Even you print a colored doc file from MS Office Word, you need to set
your printer's printing preference output to "grayscale or only black
ink" from "colored" output. So i beleive you need to set grayscale
inside your printer's settings using "printdialog" control to print in
black only.
 
J

jabslim via DotNetMonster.com

i am not allowed to show the printdialog in my project. i need the print to
be done in a single command button. is there a way to programmatically tinker
the printer's printing preference and change it to print "black ink only"?

yah! i also use that code!haha i found it in the internet! but it prints
normally, i need to print it only in black ink. how do i do it?
[quoted text clipped - 24 lines]
- Show quoted text -

Even you print a colored doc file from MS Office Word, you need to set
your printer's printing preference output to "grayscale or only black
ink" from "colored" output. So i beleive you need to set grayscale
inside your printer's settings using "printdialog" control to print in
black only.
 
K

kimiraikkonen

i am not allowed to show the printdialog in my project. i need the print to
be done in a single command button. is there a way to programmatically tinker
the printer's printing preference and change it to print "black ink only"?
yah! i also use that code!haha i found it in the internet! but it prints
normally, i need to print it only in black ink. how do i do it?
[quoted text clipped - 24 lines]
- Show quoted text -
Even you print a colored doc file from MS Office Word, you need to set
your printer's printing preference output to "grayscale or only black
ink" from "colored" output. So i beleive you need to set grayscale
inside your printer's settings using "printdialog" control to print in
black only.

Not sure. In this case, there are some choices, first one is to set
your printer setting to grayscale via printdialog control, second one
is to copy doc content to a text file (black by default) which is
another issue.

Also don't know the exact code but
system.drawing.printing.printdocument class may provide printing
settings.

On MSDN it's said that:
Use the PrinterSettings..::.PrinterName property to specify which
printer should print the document.

The Print method prints the document without using a print dialog. Use
a PrintDialog when you want to offer the user the ability to choose
print settings.

http://msdn2.microsoft.com/en-us/library/system.drawing.printing.printdocument.print.aspx
 
J

jabslim via DotNetMonster.com

oh... ok! i guess there really isn't a way to do it, because i cant have the
option of showing the printdialog. also i cant have the option of converting
it to a textfile, because converting it to a textfile will mean losing the
original format of the .doc document.haha thanks for your ideas!!! i really
really appreciate it!!

i am not allowed to show the printdialog in my project. i need the print to
be done in a single command button. is there a way to programmatically tinker
[quoted text clipped - 16 lines]
Not sure. In this case, there are some choices, first one is to set
your printer setting to grayscale via printdialog control, second one
is to copy doc content to a text file (black by default) which is
another issue.

Also don't know the exact code but
system.drawing.printing.printdocument class may provide printing
settings.

On MSDN it's said that:
Use the PrinterSettings..::.PrinterName property to specify which
printer should print the document.

The Print method prints the document without using a print dialog. Use
a PrintDialog when you want to offer the user the ability to choose
print settings.

http://msdn2.microsoft.com/en-us/library/system.drawing.printing.printdocument.print.aspx
 
A

Armin Zingler

jabslim via DotNetMonster.com said:
oh... ok! i guess there really isn't a way to do it, because i cant
have the
option of showing the printdialog. also i cant have the option of
converting
it to a textfile, because converting it to a textfile will mean losing
the
original format of the .doc document.haha thanks for your ideas!!! i
really
really appreciate it!!


Search the web for DMCOLOR_MONOCHROME. Sorry, no complete solution.


Armin
 
K

kimiraikkonen

oh... ok! i guess there really isn't a way to do it, because i cant have the
option of showing the printdialog. also i cant have the option of converting
it to a textfile, because converting it to a textfile will mean losing the
original format of the .doc document.haha  thanks for your ideas!!! i really
really appreciate it!!




i am not allowed to show the printdialog in my project. i need the print to
be done in a single command button. is there a way to programmatically tinker
[quoted text clipped - 16 lines]
Not sure. In this case, there are some choices, first one is to set
your printer setting to grayscale via printdialog control, second one
is to copy doc content to a text file (black by default) which is
another issue.
Also don't know the exact code but
system.drawing.printing.printdocument class may provide printing
settings.
On MSDN it's said that:
Use the PrinterSettings..::.PrinterName property to specify which
printer should print the document.
The Print method prints the document without using a print dialog. Use
a PrintDialog when you want to offer the user the ability to choose
print settings.

Don't know if you mocked or not, i wanted to pay attention if you
convert doc to text strings, it's apparent that special doc settings
will be lost. As you know word processing does not only contain texts
that's why it's not a good idea to convert doc to text if you have
special word effects or materials such as pictures, animations,
tables, colored areas....etc in your doc file.
 

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