Save and Get network printer options - c#

My goal is to send a PDF to a printer with specific sheet feeder, that is configured a first time by print option dialog (or just a form with network printer, tray, and margin).
I've seek about PrintDocument, PrintDialog (from System.Windows.Forms) and PrinterSettings
I can show network printer, save the selected network printer and I can use this with PrinterSettings.PrinterName but my issue is on tray's choice. I have no option to select this and customer that use my application can take every printer that exists.
So how I can show all the tray of printer selected, save it and use it to print ?

Does this link:
http://msdn.microsoft.com/en-us/library/system.drawing.printing.pagesettings.papersource.aspx
contains useful information?

Related

Why is the printable item disappear from Printing queue after closing the connection and nothing happens?

I'm using SMB shared printers to print labels ( Zebra printer ) written in ZPL from IIS backend.
The printable item is in the Queue while i'm closing the connection but the printer do not print the data.
I've checked the System32\Spool\Printers and the SDL has data but SPL is empty.
There is no errors, the JobStream.Close(); the connection and the item is disappearing.
I've googled a lot and checked the similar questions but I did not find the answer.
Thank you!
I realise that this is quite an old post, but thought I would add this as I have been having similar problems printing to Zebra printers from C#.
It turned out that a way that I could work around this was to set the "Keep printed documents" checkbox in the advanced tab of the printer settings.
Not only was the printer then retaining the document, but it was also actually printing out the document, whereas previously the document was disappearing from the queue without printing.

Ghostscript.NET can't print with selected printer name

I want to print a pdf file with selected printer name via Ghostscript.NET. This application is actually a wrapper of CefSharp browser. When user click on a download button, it download and print out with selected printer directly.
You can see the screenshot above, I pass the printer name thru URL query string. Also, I have set the option -dNOPAUSE & -dNOPROMPT. But why it still come out a print window, and the default selected printer is not what I have set?
Any idea what's going wrong here?
EDIT: Mar 4, 2016 11:31am
For ghostscript in command line, it will be like
"C:\Program Files (x86)\gs\gs9.18\bin\gswin32c.exe"^
-empty^
-dPrinted^
-dBATCH^
-dNOPAUSE^
-dNOPROMPT^
-sFONTPATH=C:\Windows\Fonts^
-dNOSAFER^
-dNumCopies=1^
-sDEVICE=mswinpr2^
-sOutputFile="%printer%Brother MFC-295CN Printer"^
-f C:\Users\Dell\AppData\Local\Temp\file-tmp.pdf
but then it still show the print prompt.
Add -dQueryUser=3 to your command line to print directly to the default printer using that printer's default settings.
If the printer you are printing ot is not the Windows default printer, (on this system) then you must specify the printer in the print dialog. This is because there are 2 disconnected entities.
1) The printer you send the data to.
2) The creation of data in the correct format.
The mswinpr2 device uses the Windows print system to take the rendered output from Ghostscript and convert it into whatever the printer understands (PostScript, HP-PCL, Epson ESC/P etc, etc). It then sends that data to the named printer. NB this is why the driver for that printer must be available locally.
However, the mswinpr2 device doesn't know which printer device driver corresponds to a given named printer of the form "%printer%Name", you have to tell it that. If the named printer is the windows default printer then you can use -dQueryUser=3 to say so, otherwise you need to present the printer dialog so that the user can select the correct printer and that's what mswinpr2 uses to create the data that it then sends to the printer.
I believe that its perfectly possible to get this wrong! If you select a PostScript printer in the printer dialog, but then set -sOuputFile=%printer%HP-PCL printer" the combination will send output formatted as PostScript to a printer which expects PCL, the result in that case will be reams of garbage printout.
You need to exercise caution with the use of this device, which is why the default behaviour is to make you select the printer from the list of available printers.

Emulate a printer in pc

I have made an desktop application using C# to make ID card .And i am required to add functionality of printing an ID card .Basically i just make an image in a win form which will be eventually printed using.
But as i have no printer,i can't test my code to see if it prints something.
Is there any emulator or software that emulates a printer in windows,so that i cant test my application?
This is a sample what i need to print.It wiil be in a win form.
And another thing. How can i maintain size of the id card while printing. Say id card size should be in 2inch * 3.5inch. How can i make sure it will print same size?
You can use the Microsoft XPS printer driver that ships with Windows (since Vista, but available for Windows XP)
The XPS Document Writer allows you to create .xps files using any
program that you can print from in Windows. Print to the XPS Document
Writer when you want to create, send, and share or publish documents
that you do not want other people to modify, or when you want to print
a document or display it online exactly as it appears on your screen.
It's also a good idea to create an XPS document for files that contain
graphics or illustrations that might otherwise display differently in
print than online or on computers with different monitors.
Once you click OK, you're prompted for the file path to save it to.
Try print to PDF file to check that Your application works. For example You can use "PDF Creator" under Windows OS's. It is the easiest way.

Programmatically select a printer in PrintDialog

I have a Web Browser control in Windows forms. It loads a HTML file. I want to be able to give an option to the user to Save this as PDF file.
If the user has "CutePDF Writer" installed then I thought I can just select it programmatically from Print Dialog and Save it as PDF. I am showing the PrintDialog using Web_browser_control.ShowPrintDialog(). Is there a way to select a printer(CutePDF Writer in my case) programmatically in this Print Dialog without user intervention?
You can do like, this,
printDocument.PrinterSettings.PrinterName = "YOUR_PRINTER";
Refer, https://andres.jaimes.net/65/how-to-choose-a-printer-using-c-sharp/
Not quite sure,but print dialog has printer settings related properties where you can define the default printer.
Here is somewhat similar question asked in SO, the only difference being it was asked for windows. Neverthless, PrintDialog works in a similar fashion in web too.

How do I write a print job image to disk?

When I print any document with my computer I want the printed page to be saved on my computer as for example a bmp or jpg file and printed to a piece of paper at the same time. I don't know if it is possible to extract this information from a printer or if it is possible to make a virtual printer and use it as "pass through" and get the image from the virtual printer and send it to the real printer afterwards.
OS: Windows XP.
The Win2PDF virtual printer can create a PDF and print it to a paper printer at the same time. To do this, set your real printer as the Windows default printer, print to the Win2PDF printer, and select the "print file" option in the file save window. After the PDF file is created, it is automatically printed to your real printer.

Categories