Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am trying to print directly to the printer from server side by passing printer name to PrintDocuemt() object. Below codes works fine when running from localhost but gets stucked when running from hosted application on IIS. I am trying to print document to pdf using, microsofts default printer "Microsoft Print to PDF" in windows 10/

What I have tried:

C#
var doc = new PrintDocument();
               doc.PrintPage += new PrintPageEventHandler(ProvideContent);
               if (TempData.Peek("PrinterName") != null && TempData.Peek("PrinterName").ToString() != "")
               {
                   doc.PrinterSettings.PrinterName = TempData.Peek("PrinterName").ToString();
               }

               doc.Print();
               doc.Dispose();
Posted
Updated 6-Dec-18 21:04pm
v2

1 solution

Does the server have the PDF print driver installed? If its doesn't, then no, that's not going to work ...
 
Share this answer
 
Comments
Chirag Sudra 7-Dec-18 3:06am    
PDF driver is on that machine and its working fine from other apps/print commands
OriginalGriff 7-Dec-18 3:15am    
Then you need to start adding logging code to find out exactly what is happening.
For example, what's in TempData.Peek("PrinterName")?
What value is going in the PrinterName property?

Have you looked to see? Or did you assume they are correct because it worked in dev?
Chirag Sudra 7-Dec-18 3:51am    
No, I have not assumed and already logged the printer name from TempData in text file & printer name is correctly passed to the printer object.
OriginalGriff 7-Dec-18 3:56am    
You'd be surprised how many do assume ... :sigh:
(And if you have tried something, it's a good idea to tell us - along with any results: we can't see your screen!)

OK, so the printer name looks right. What exactly happens? Any exceptions, messages, crashes? Does it get into the event handler?
Chirag Sudra 7-Dec-18 4:00am    
I'm invoking print method by Ajax call. There's not exception or warning/error message. It just gets stuck on doc.Print() line and as a result ajax call waits for response.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900