Click here to Skip to main content
15,561,125 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How I do to print some data such as invoive in asp core on server side? I have a web project, when some data arrive to the server, it needs to be printed on server side for reporting. Is it possible to use html razor template

What I have tried:

there are a lot of example on client side bu none on servers,
I have used PrintDocument Class but it needs a lot of work, I want to create/print it with razor template from view model if is it possible
Posted
Updated 10-Jul-19 7:21am
Comments
Anurag Gandhi 10-Jul-19 11:41am    
Why would you like to print at server side?
If there is a case in which you want the user to print at server side, your server needs to have printer connected. How will user collect the print-outs from the server. Server may geographically located in another country. Just think over it.
Member 10003895 11-Jul-19 9:52am    
actually, there is Web API , no web server , and I use it for inside the company for 7-8 client machine. Some transactions to DB need to be reported/printed on a paper. if printing as windows service is a solution, it could be too heavy job for setting paper/printer all types,isnt it? Any idea for this configutaion?
Anurag Gandhi 11-Jul-19 10:12am    
I would still question on why you need web api in that case. But not going towards that direction.
https://www.strathweb.com/2012/10/remote-printing-with-asp-net-web-api-in-windows-service/
This may help.
Dave Kreskowiak 10-Jul-19 11:49am    
You normally don't want the web server to print anything. It ties up resources that can be used to serve requests. The printing should be handled by a separate service running on a non-web server looking at the same database the web servers are using.

Quote:
there are a lot of example on client side bu none on servers,

Here's why: 99.9999% of web developers do not want the client to be able to trigger physical printing on the server.

For the same reason, there is also no built-in way to plug a Razor template in a PrintDocument. You will have to write your custom solution here.
 
Share this answer
 
There are 2 parts to your question.

As for using a Razor template; I really don't know. I imagine it could be done but it would be some ugly coding. You would be better off by having your web application trigger an SSRS report or similar and design that instead.

As for auto-printing... Not recommended. But if you insist you can read through the rigmarole and attempt this:
SQL Tip: Auto-printing from SSRS to a Networked Printer[^]
 
Share this answer
 

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