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.
Related
For the first time I've been given this Thermal printer (M325A) to use, at this stage I have ZERO idea of how to code my desktop application to print "ANYTHING". But my present requirement will be to print just 4 lines of information:-
Pre-mentioned Static Banner (Big text),
User supplied numeric value (Non-Decimals),
Serial Number (Progressive),
Current Date & Time.
Kindly help me start.
While there are printing libraries out there, you can as well directly connect to the printer, over serial, USB, or, ethernet, and send it the commands to print. ESC/POS capable printers interpret escape sequences, which are very well documented. You must, however, get to know how you can send binary data (i.e. 8-bit bytes) directly to the printer.
Does POS printer just support Epson printers? (related to https://msdn.microsoft.com/en-us/library/windows/apps/mt426652)
How to send a document directly to the printer without showing Print Dialog?
ESC/POS is a command system created by Epson used across a wide range of POS printer systems, aimed at avoiding incompatible command sets by providing universal applicability. Most modern printers support ESC/POS.
So, for your first question, I think the answer is no. This POS printer API can be used for all the printers which support ESC/POS. Please refer to Epson ESC/POS with formatting.
For your second question, using POS printer API, you can print without a Print Dialog.
But I assume, what you want is Windows.Graphics.Printing namespace. For this printing in a UWP app, the Print Preview UI must be shown to guide user complete the printing operation.
You can refer to the official POS printer sample and Printing sample.
Update 2/1/2016:
using POS printer API, you can print without a Print Dialog.
#Seb, this is my personal conclusion, the official document of POS printer doesn't mention anything about a UI dialog.
But in the short sample in the document and official sample, when we print with a pos device, we create a print job at first, then call the PrintLine(string) method with the content which we want to print, at last, we execute it/them with ExecuteAsync method, this method
Runs the print job on the receipt printer station asynchronously.
In this process, we don't show any dialog unlike in the normal printing. In the normal printing, when we want to print a document from our app, we call ShowPrintUIAsync() method, this method will show a dialog to provide guidance for users to help them complete a printing-related oricess.
#Hamed, this Pos printer API can't support those device without ESC/POS, I'm not sure if it possible to send commands to your printer and get response from it through serial port, I think you may read the develop document of your printer.
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.
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?
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.