Go Premium for a chance to win a PS4. Enter to Win

x
Solved

# printDocument in vb.net

Posted on 2013-01-22
Medium Priority
1,800 Views
Here is my code:

Dim printDocument1 As New PrintDocument()
Dim Printd As New PrintDialog()
Dim res As DialogResult = Printd.ShowDialog()

printDocument1.DocumentName = "c:\TEMP\TestT.rtf"                            Printd.Document = printDocument1
Printd.AllowSomePages = True
Printd.ShowHelp = True

If (res = DialogResult.OK) Then
printDocument1.Print()
End If

When it print just printing with blank paper.
What iam doing wrong?
0
Question by:Nettodotnet
• 5
• 3

LVL 75

Expert Comment

ID: 38806218
What are you trying to print?
0

LVL 19

Expert Comment

ID: 38806248
Have you checked the contents of file at 'c:\TEMP\TestT.rtf'
0

Author Comment

ID: 38806256
kaufmed : Iam trying to print a rtf file.
AmanBhullar: yes it has 2 pages content.
0

LVL 75

Expert Comment

ID: 38806317
With PrintDocument you have to do all of the drawing to the page yourself. What you are attempting to do now will not work. You can certainly do the work to print the RTF document using PrintDocument if you like, but I think you would find it easier to use the Process class and pass the "Print" verb.

e.g.

Dim printer As New System.Diagnostics.Process()

printer.StartInfo.FileName = "C:\path\to\file.rtf"
printer.StartInfo.Verb = "Print"
printer.Start()

0

Author Comment

ID: 38806510
I try with below code too...
Dim p As New Process
p.StartInfo.FileName = "C:\\TEMP\TestT.rtf"
'p.StartInfo.WindowStyle = Diagnostics.ProcessWindowStyle.Hidden
p.StartInfo.Verb = "print"
p.Start()

This is working fine on my local box ..But when i deployed into teat server this is not working.
Printing is not working.
0

LVL 75

Expert Comment

ID: 38806673
Are you running the application as a user who has access to that path?
0

Author Comment

ID: 38806842
Iam creating a TEMP file under each user:
C:\\TEMP\TestT.rtf"
0

Accepted Solution

Nettodotnet earned 0 total points
ID: 38815454
I figured out it:
here are the steps:

Converting RTF to PDF by using 3rd party DLL's.
Printing from the IFRAME.
0

Author Closing Comment

ID: 38830325
i reasearched my self
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
###### Suggested Courses
Course of the Month8 days, 17 hours left to enroll