retrieve the name of the printer with silverlight - c#

I created a print soft with silverlight. I must verify on which printer my customer prints her document. But I don't find the way to access to the name of the printer after the customer have chose it.
I use this code to initialize the impression
printDoc = new PrintDocument();
printDoc.PrintPage += OnPrint;
printDoc.EndPrint += EndPrint;
printDoc.BeginPrint += BeginPrint;
printDoc.Print("Badge");
I just want cancel the print if the customer choose the bad printer. Is there a way for this? (I know the print functions in Silverlight are very light)

Related

C# PrintDocument PaperSource not applied on some Printers

I have writen some simple C# Tool that Prints PDFs with the Help of SpirePDF
In the Tool i can select The Printer and its PaperTray
I have 2 Printers here and they are working fine with my code (The correct tray is used)
On an other machine with other Printers, it doesnt work, the correct Printer is choosen, but the PaperTray is alway the same (Manual Feed), no matter which Tray i choose.
printDocument.PrinterSettings.PrinterName = PrinterSettings.InstalledPrinters[MyPrinterConfiguration.GetPrinterIndex(#"invoice_print")];
printDocument.DefaultPageSettings.PaperSource = printDocument.PrinterSettings.PaperSources[MyPrinterConfiguration.GetPrinterTrayIndex(#"invoice_print")];
MyPrinterConfiguration is an Dictionary that hold the indexes of the Trays and Printer on the System.
Are there any other methods to set the PaperSource for this Document?
My Printers are from Samsung and Brother
the others from HP and Brother (both are not working) so it seem not to be a driver Problem.
I have found a solution:
Setting the PaperSource in self-created PrinterSettings seems not to work for some Printers, but when i make a Printdialog, let the User choose the Settings (PaperSource, PaperType and so on) and take theese settings (unchanged) to apply them on the PrintDocument, then it works for all my testet printers.
I think PrinterSettings from PrintDialog have other or more characteristics than i can set programaticly.
if (printDialog.ShowDialog() == DialogResult.OK) {
gpsMyPrintSettings.SetSettingsForType( "badge", (PrinterSettings) printDialog.PrinterSettings.Clone() );
}
printDocument.PrinterSettings = gpsMyPrintSettings.GetSettingsForDocumentType( "badge" );
printDocument.Print();

printing in Zebra Z4M Plus 203dpi C#

I create a program where its objective is to monitor the Fixed asset. One part of the system is print barcode in the zebra z4m plus 203dpi. how can I print on that device? I already try but the printed barcode is blurred. I use the bitmap and print it using the PrintDocument function of c#.
You have to create a string with your ZPL code then send it to Z4M.
Can see how to do here : .NET code to send ZPL to Zebra printers
or with SharpZebra :
1) Install a Zebra Printer so it's accessible on your Print Queue (we're going to assume the name of your printer is ZDesigner S4M-203dpi ZPL).
2) Add a reference to the SharpZebra libraries to your project
3) Write the code below to print a label into a class
4) Run the code
PrinterSettings ps = new PrinterSettings();
ps.PrinterName = "ZDesigner S4M-203dpi ZPL";
ps.Width = 203 * 4;
ps.Length = 203 * 6;
ps.Darkness = 30;
List<byte> page = new List<byte>();
page.AddRange(ZPLCommands.ClearPrinter(ps));
page.AddRange(ZPLCommands.TextWrite(10, 150, ElementDrawRotation.NO_ROTATION, ZebraFont.STANDARD_NORMAL, 15, "Hello World!"));
page.AddRange(ZPLCommands.PrintBuffer(1));
new SpoolPrinter(ps).Print(page.ToArray());
As far i know, you could use ZebraDesigner (check it on Zebra site) to dessing your label.
ZebraDesigner creates a ZPL (or EPL) file this that label dessign.
You can send this files to the printer using Serial Communication and the device prints the label

PrintDocument.PrinterSettings.Print() Changing default printer

I have the following code, to test out printing to a specific printer. The code sends the print to the correct printer. But I have notices upon completing the print, the systems default printer has changed.
I thought maybe at first maybe the PrinterName property was setting the default printer, and quickly realized that is not the case. I have to assume it is happening inside the Print() method.
I did some reading on changing the default printer, the solutions I found seemed to use the System.Management Namespace. But did not find anything related to changing the default printer back in the System.Drawing.Printing Namespace.
I figure there might be a simple way to change it back using the same Namespace that used it in the first place. Other than reprinting the document or a blank document to the previously default printer.
static void Main(string[] args)
{
Receipt();
}
static private void Receipt()
{
PrintDocument p = new PrintDocument();
p.PrinterSettings.PrinterName = "Star HSP7000 Receipt";
p.PrintPage += delegate(object sender1, PrintPageEventArgs e)
{
e.Graphics.DrawString("testtesttestest", new Font("Times New Roman", 12), new SolidBrush(Color.Black), new RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height));
};
p.Print();
}
After asking this question, I continued searching, and found that windows 10 quietly manages the Default Printer to the last printer that is printed from (by default).
If you are having an issue on a windows 10 machine where the default printer is changing after a print job. Make sure to change this.

Squeezing more speed out of Windows print spooler

Our customer and I are trying to find a way to eliminate our printing bottleneck in a labeling system my company integrated at their warehouse.
The way our system is set up, a box scans, my software does this:
PrintDocument pd = new PrintDocument();
pd.PrinterSettings.PrinterName = PrinterName;
pd.PrintController = new StandardPrintController(); //Prevent print windows
pd.DefaultPageSettings.Landscape = false;
pd.DefaultPageSettings.Margins = new Margins(0, 25, 25, 0);
pd.PrintPage += (sender, args) =>
{
Image i = Image.FromFile(#"D:\Product\Labels\" + LabelID + ".png");
Rectangle m = args.MarginBounds;
args.Graphics.DrawImage(i, m);
};
pd.Print();
which sends it to the spooler. The program runs on a rack server with Windows Server 2012, and we're printing shipping labels to five label tampers powered by Intermec PX4i label printers. Each print job is sent from a different thread, because our scanpoint processing is asynchronous. Right now, the fastest our system can handle is 5 boxes, one on each line, every 2.75 seconds, and they want to speed it up to 5 boxes every 2 seconds - the problem is, if we let it go any faster, print jobs start getting held, and spoolsv.exe starts eating up whatever CPU load my program and SQL Server aren't.
Unfortunately, our customer can only provide the monochrome .PNG image files for the labels (each about 27kb, which you wouldn't think would bog down a print spooler...) and not IPL/ZPL equivalents (which we could just send to the printers via TCP in a matter of milliseconds).
Is there a way - either in the code or in the print settings - that I can eliminate this bottleneck? Please let me know if there's anything on which you'd like me to elaborate.

Is it possible to open a PDF inside a c# application with Acrobat.dll?

I know that I can display a PDF file in my c# executable (not web app) with:
private AxAcroPDFLib.AxAcroPDF axAcroPDF1;
axAcroPDF1.LoadFile(#"somefile.pdf");
axAcroPDF1.Show();
But that is the regular pdf viewer like in the browser. I don't want that. I want full Adobe Standard or Professional functionality in my C# application using the Adobe controls. For example, if I use the code above, it loads in the C# app and I can see the adobe toolbar (print, save, etc.) But it is useless to me because I need things like save which cannot be done with the activex viewer above. Specifically, you cannot save, just as you cannot within the broswer.
So, I referenced the acrobat.dll and am trying to use:
Acrobat.AcroAVDocClass _acroDoc = new Acrobat.AcroAVDocClass();
Acrobat.AcroApp _myAdobe = new Acrobat.AcroApp();
Acrobat.AcroPDDoc _pdDoc = null;
_acroDoc.Open(myPath, "test");
pdDoc = (Acrobat.AcroPDDoc)(_acroDoc.GetPDDoc());
_acroDoc.SetViewMode(2);
_myAdobe.Show();
It opens adobe acrobat but it opens it outside of my c# application. I need it to open in my c# application like the activex library does. Can it be done with these libraries?
If I cannot open it in my c# application I would like to be able to "hold" my c# app tied to it so the c# app knows when I close the adobe app. At least that way I'd have some measure of control. This means I would hit open, the adobe app opens. I close the adobe app, my C# app is aware of this and loads the newly changed doc with the activex library (because I don't need change ability anymore, just displaying.)
I have the full versions of adobe acrobat installed on my computer. It is not the reader.
Thank you for any help.
edit:
There is an example in vb in the adobe acrobat sdk. I believe it is called activeview.
you can check out ABCpdf. I dont know if it has this capability but we have used it for several of our apps
Using a webbrowser control would be an option to display the content.
IText# may help you out.
You can create PDF's and I believe you can use it to read and modify them.
As for displaying in the app..... I am not sure how to display them with iText or if it is possible (have not tried this yet), sorry. iText does let you convert to RTF which may be one approach.
Best option is to write a listener which tells your calling code when Adobe.exe is no longer running. Something like the following (with tweaks for your uses) should work:
public void Open(string myPath)
{
Acrobat.AcroAVDocClass _acroDoc = new Acrobat.AcroAVDocClass();
Acrobat.AcroApp _myAdobe = new Acrobat.AcroApp();
Acrobat.AcroPDDoc _pdDoc = null;
_acroDoc.Open(myPath, "test");
_pdDoc = (Acrobat.AcroPDDoc) (_acroDoc.GetPDDoc());
_acroDoc.SetViewMode(2);
_myAdobe.Show();
NotifyAdobeClosed += new EventHandler(Monitor_NotifyAdobeClosed);
MonitorAdobe();
}
private void Monitor_NotifyAdobeClosed(object sender, EventArgs e)
{
NotifyAdobeClosed -= Monitor_NotifyAdobeClosed;
//Do whatever it is you want to do when adobe is closed.
}
private void MonitorAdobe()
{
while(true)
{
var adcount = (from p in Process.GetProcesses()
where p.ProcessName.ToLower() == "acrobat"
select p).Count();
if (adcount == 0)
{
OnNotifyAdobeClosed();
break;
}
}
}
public event EventHandler NotifyAdobeClosed;
public void OnNotifyAdobeClosed()
{
if (NotifyAdobeClosed != null)
NotifyAdobeClosed(this, null);
}

Categories