windows forms print pdf using axAcroPDF - c#

ASP.NET 4.5, c#, VS2013
I have a windows form application in c#. The application creates a pdf and I wanted to print it to a specific printer.
I could do:
axAcroPDF1.printWithDialog()
and user selects a printer from the list.
But my users do not like this at all. The preferred printer in this case is way back in the list and they want this to be the default printer for this program only.
I am not able to see a default printer like property in axAcroPDF and I do not know how to set the default printer for this windows application only.
Please advise an optimum solution. I did not expect this to get so complicated.
Thanks,

I don't think you can set the default printer per application, only per user. (I'm all ears if this is not the case!)
You could try programmatically getting the default printer, setting it to what you require, and then setting it back to its original value once you're done with your PDF. You can accomplish this with the Windows API using SetDefaultPrinter and GetDefaultPrinter.
You'll need to know how to make Windows API calls from C#. Have a look at pinvoke if you're not sure where to start.

Related

How to design the page and print it on the thermal printer on Epson TM-T88V POS Printer

I am creating the Web Application, After completion of payment i need to get the receipt from the Epson TM-T88V POS Printer in c# using ASP.Net. and after displaying the relevant information on the paper i need to display the Barcode also.
Will it possible to design the page and print it.
Thanks in advance,
Vara Prasad.M
Sure this can be done, however I suspect you are wanting it to be seamless, which can't be done without Silverlight, Java or another embedded solution.
What you can do however is use HTML/CSS and a Barcode image generator to create a page that contains your receipt, then you can simply print via the browser onto your thermal printer.
The only thing that you may find is that your browser often adds a header/footer to your pages and these will appear on your receipt.
A better solution is to use the Silverlight or Java to handle this, as it would have direct communication with the printer, rather than having to rely on the browser.
Link to a possible barcode generator.
http://www.codeproject.com/Articles/20823/Barcode-Image-Generation-Library

Can we get a FileStream for a Printer?

If I understand it right, a printer is also a file from the operating system's view. Can I get a .NET C# FileStream type for a printer? It seems wild to do this.
Thanks in advance.
A printer is modeled in Win32 as a set of bitmaps. This is wrapped by the PrintDocument, which basically sets up a callback that lets you draw each page individually and sends them one by one to the printing spooler which then sends the data (in .ps format usually) to the printer.
This is how modern printers operate, they draw pages, not text. Only the old school matrix printers drew text character by character, in a stream-like fashion. They used to use the "PRN:" special file. This has lost all meaning in a modern environment however.
The good news is, it's really easy to work with the PrintDocument class, you get a Graphics object for each page that you can use to print text anywhere on the page, as well as draw graphics.
You can simulate a stream-like printer if you so wish by caching all the data then just calling DrawText for every page.
Building a Windows Forms application, you can think of a printer as a Graphics Device.
The System.Drawing.Printing namespace provides print-related services for Windows Forms applications.
If you want to print from a Windows Presentation Foundation (WPF) application, see the System.Printing namespace. It provides classes that enable you to automate the management of print servers, print queues, and print jobs.
Assuming that you want to send the raw data to printer, please see How to send raw data to a printer by using Visual C# .NET
Since .Net 3.0 you can, by using the
PrintSystemJobInfo.JobStream
When you create a printjob in the spooler, e.g.
var job = LocalPrinter.GetDefaultQueue().AddJob();
You can write to the
job.JobStream
Closing that stream queues it for printing.
Interestingly, you can use that stream to write control codes and text to a generic/text-only printer (e.g. LPT1 parallel port impact printer)

How to change default audio input device programatically

I am looking for a way to set/change default input device inside my application. I have several different recording devices and it is very anoying to go into the control panel and change default recording device. I was looking around and I did not find anything that could help me with the problem. Application is written in c# and it is targeted for Windows Vista / Windows 7.
This can now (actually for quite some time already) be done very easily using the AudioSwitcher.AudioApi.CoreAudio NuGet package.
Simply create a new CoreAudioController:
var controller = new AudioSwitcher.AudioApi.CoreAudio.CoreAudioController();
Get hold of the desired device using its GUID:
var device = controller.GetDevice(Guid.Parse(...));
And lastly set it as the default playback device:
controller.DefaultPlaybackDevice = device;
Note: this answer was also posted under this question.
There is no public API to do this in Vista/7 AFAIK.
For a media center launch thing I created, I had to open the control panel and send keys to the dialog, a big ugly hack, but it's the best you can do. (Or run .net reflector on media center (It is able to change it, using undocumented calls))
If you had Windows XP, apparently, you can do this by editing the registry. The key HKEY_CURRENT_USER\Software\Microsoft\Multimedia\Sound Mapper\Playback contains the name of the current default playback device.

.Net Printing from a web site?

Scenario- I have a website that tracks/manages data stored in a DB(I know this covers 90% of websites :)). I have users that need to print specialized labels and barcodes. The app will need to print to a specialized Zebra RFID printer as well as a specific printer for bar codes. All users must use IE 7. Only 3-4 users will print these items. I want to give the user a button they press and then the barcodes/reports are just printed.
Question-
I can create all the files that need to be printed on the server but can I use an XBAP to automate the specialized printing? If not is there any other way?
Access to special hardware from within Internet Explorer is not always easy - even for something as basic as a printer. You can try using the built-in printing facilities of IE7 - but you are likely to run into formatting and layout problems when printing something like barcodes.
XBAPs run an a sandbox and have limited access to hardware as well - but you may be able to print from one - it all depends on whether you need access to any Win32 print or device APIs.
A gauranteed way to implement something like this is using an ActiveX control - but that a much more complicated thing to implement - and it will only work on Internet Explorer - and on a machine that is configured to allow ActiveX controls to run.

How can I select a different printer in a web application?

I have a Web application programmed in C#.
There are several printers and I want to choose any of them and execute the action, I would like some kind of Form to load all printers.
I found this for Win forms:
this.printDialog1.Document = this.printDocument1;
DialogResult dr = this.printDialog1.ShowDialog();
But I couldn't find something for ASP.NET.
Thanks for any help.
You really can't do it from a web app, if it was allowed then pop-up loving sites all over the internet would I'm sure be accounting for most of the worlds ink usage.
I had this issue when building a web app for a college, the most its possible to do is call up the print dialogue and have the user select the printer (best to have a decent print targeted CSS here):
javascript:window.print();
Its not perfect but to be honest although they insisted on it when it was put in a year ago, emails and PDF's are much more widely used.
The printer is assigned at the workstation.

Categories

Resources