Is there a way to switch printer trays during a print job? I've been asked to put together a pick/pack slip program. They want the inventory pick slip to be printed on a sheet of colored paper, the pack slips to be on white paper, and they want it properly collated (pick, pack, pack, pack, pack; pick, pack, pack, pack, pack; ...).
I found some other threads on setting default trays, but didn't find anything on alternating trays during the job. Maybe I'm not searching on the right thing.
Don't know if it makes a difference, but our printer is an HP 3015n and the clients will be both XP and Win 7 Pro.
You can try something like this you have to reference System.Drawing.dll from the projects --> Reference--> Add
//Namespace: System.Drawing.Printing
//Assembly: System.Drawing (in System.Drawing.dll)
PrintDocument printDoc = new PrintDocument();
PaperSize oPS = new PaperSize();
oPS.RawKind = (int)PaperKind.A4;
PaperSource oPSource = new PaperSource();
oPSource.RawKind = (int) PaperSourceKind.Upper;
printDoc.PrinterSettings = new PrinterSettings();
printDoc.PrinterSettings.PrinterName = sPrinterName;
printDoc.DefaultPageSettings.PaperSize = oPS;
printDoc.DefaultPageSettings.PaperSource = oPSource;
printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);
printDoc.Print();
printDoc.Dispose();
To my knowledge no - you have to submit 2 jobs on a queue that basically only you use.
You can change printer tray with this code.
string _paperSource = "TRAY 2"; // Printer Tray
string _paperName = "8x17"; // Printer paper name
//Tested code comment. The commented code was the one I tested, but when
//I was writing the post I realized that could be done with less code.
//PaperSize pSize = new PaperSize() //Tested code :)
//PaperSource pSource = new PaperSource(); //Tested code :)
/// Find selected paperSource and paperName.
foreach (PaperSource _pSource in printDoc.PrinterSettings.PaperSources)
{
if (_pSource.SourceName.ToUpper() == _paperSource.ToUpper())
{
printDoc.DefaultPageSettings.PaperSource = _pSource;
//pSource = _pSource; //Tested code :)
break;
}
}
foreach (PaperSize _pSize in printDoc.PrinterSettings.PaperSizes)
{
if (_pSize.PaperName.ToUpper() == _paperName.ToUpper())
{
printDoc.DefaultPageSettings.PaperSize = _pSize;
//pSize = _pSize; //Tested code :)
break;
}
}
//printDoc.DefaultPageSettings.PaperSize = pSize; //Tested code :)
//printDoc.DefaultPageSettings.PaperSource = pSource; //Tested code :)
Related
According this Link I installed the IronOcr package and I try the follow code.
using IronOcr;
var Result = new IronTesseract().Read(path);
string currentSubText = Result.Text;
textBox1.Text += currentSubText + Environment.NewLine + Environment.NewLine;
I tested it with six pictures:
Picture
Picture
Picture
Picture
I could just upload four pictures.
Actually it looks good. There are just a few mistakes with some special German language characters (äöü)
Result 1:
I google and found it is possible to use a language package in OCR. I try it with the follow code.
var Ocr = new IronTesseract();
//Ocr.Language = OcrLanguage.German;
Ocr.Language = OcrLanguage.GermanBest;
using (var Input = new OcrInput(path))
{
var Result = Ocr.Read(Input);
string currentSubText = Result.Text;
textBox1.Text += currentSubText + Environment.NewLine + Environment.NewLine;
}
Unfortunately the result is very, very bad.
Result 2:
Can someone help me here?
Thanks and best regards
Did you try using the built in inversion color filter?
All OCR tends to work best for me with black text on white. I use this code based on code found in the IronOCR documentation:
https://ironsoftware.com/csharp/ocr/examples/ocr-image-filters-for-net-tesseract/
Simplified source code:
using IronOcr;
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.GermanBest;
using (var Input = new OcrInput(#"image.png"))
{
//Input.EnhanceResolution(300);
Input.Invert();
/*
// Optional: Export modified images so you can view them.
foreach(var page in Input.Pages){
page.SaveAsImage("filtered.bmp")
}
*/
var Result = Ocr.Read(Input);
Console.WriteLine(Result.Text);
}
MSDN style docs:
https://ironsoftware.com/csharp/ocr/object-reference/api/IronOcr.OcrInput.html#IronOcr_OcrInput_Invert_System_Boolean_
My project needs to print a simple string object to a printer of choice using something like the WPF System.Windows.Controls.PrintDialog.
I created a standard System.Drawing.Printing.PrintDocument but it does not have a DocumentPaginator that is required for the PrintDocument() method belonging to the PrintDialog class.
This seems like a trivial task to print a string to a printer with a dialog to show printer choices, but is turning out significantly more difficult. Please Help!
Since you're using WPF, instead of using the PrintDocument, just create a FlowDocument. I think that's a lot easier.
var dlg = new PrintDialog();
dlg.PageRangeSelection = PageRangeSelection.AllPages;
dlg.UserPageRangeEnabled = false;
if(dlg.ShowDialog() == true)
{
var doc = new FlowDocument();
// For normal A4&/letter pages, the defaults will print in two columns
doc.ColumnWidth = dlg.PrintableAreaWidth;
doc.Blocks.Add(new Paragraph(new Run("My arbitrary long string to print.\nNewlines work. Pages will break as needed.")));
dlg.PrintDocument(((IDocumentPaginatorSource)doc).DocumentPaginator, "Simple document");
}
I'm printing pages via GTK# using a PrintOperation object like this:
PrintOperation print = new PrintOperation();
print.BeginPrint += new BeginPrintHandler(OnBeginPrint);
print.DrawPage += new DrawPageHandler(OnDrawPage);
print.EndPrint += new EndPrintHandler(OnEndPrint);
print.Run(PrintOperationAction.Print, null);
Result: My page is silently printed on the systems default printer.
So far so good.
If I replace the last line with
print.Run(PrintOperationAction.PrintDialog, null);
I'm able to choose a printer via default printer selection dialog and the page is printed on the selected printer.
What I'd like to do now is to print the document silently on another (= non default) printer without choosing it manually from the dialog (my application should print in background without user interaction).
I know the printers name in my application, but how can I set the printer that my pages are printed on this "non default" printer without user interaction?
Again I found the answer myself:
PrintSettings settings = new PrintSettings();
settings.Printer = "MY SECONDARY PRINTER";
PrintOperation print = new PrintOperation();
print.PrintSettings = settings;
print.BeginPrint += new BeginPrintHandler(OnBeginPrint);
print.DrawPage += new DrawPageHandler(OnDrawPage);
print.EndPrint += new EndPrintHandler(OnEndPrint);
print.Run(PrintOperationAction.Print, null);
I've seen many posts with regards to setting printer tray in c# for word document. I need a solution for Excel.
A better solution, if possible, for any document. Some kind of method i can pass a file path and the tray.
EDIT
So far I've tried the following but no visible changes have been made in the printer settings.
PrinterSettings ps = new PrinterSettings();
ps.PrinterName = #"\\localhost\HP-4515n";
var dps = ps.DefaultPageSettings;
dps.PaperSource.RawKind = 260;
OR
PrinterSettings ps = new PrinterSettings();
ps.PrinterName = #"\\localhost\HP-4515n";
PaperSource psrc = new PaperSource();
psrc.RawKind = 260;
psrc.SourceName = "unknown";
dps.PaperSource = psrc;
EDIT 2
I'm hardcoding RawKind since the tray somehow does not show in the papersources.
And currently when i print eg. Excel document i show the PrinterDialog, get the name of the selected printer and pass it to interop Excel active printer property. But now i need to print mass of documents and i need to set the selected printer and it's property specially the tray programmatically.
#sysboard, I see from the MSDN page on the PrinterSettings class that the DefaultPageSettings property does not have a set method, only a get method. I am not sure that this is accessible from external classes...You might look into the PageSettings class as it looks like it has an overloaded constructor that allows you to pass a specified printer, and it has a set method on PaperSource.
You can get the available papersources using the folowing code :
PrintDocument printDoc1 = new PrintDocument();
List<PaperSource> psList = new List<PaperSource>();
PaperSource pkSource;
for (int i = 0; i < printDoc1.PrinterSettings.PaperSources.Count; i++)
{
pkSource = printDoc1.PrinterSettings.PaperSources[i];
psList.Add(pkSource);
}
Now present these options to the user and get the input as to which paper source to use, say its the first one, you can do :
PrintDocument doc = new PrintDocument();
doc.DefaultPageSettings.PaperSource = psList[0];
doc.Print();
Why you are hardcoding psrc.RawKind = 260;
To set a RawKind for a Paper Source there is PaperSourceKind enum available. try the following code
PrintDocument doc = new PrintDocument();
PaperSource pSource = new PaperSource();
pSource.RawKind = (int)PaperSourceKind.Middle;
doc.DefaultPageSettings.PaperSource = pSource;
I'm trying to print labels with a dynamic content. The print works fine but the problem is that the printing itself (the font) is 90 degrees twisted. It looks like this:
But it should look like this:
I cannot change the settings of the printer because other labels do print correct. So I think it must be something in the code. You can watch the C# code here:
System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();
printerSettings.PrinterName = #"\\server\printer";
printerSettings.Copies = Convert.ToInt16((Convert.ToInt16(row.Cells["Counter"].Value.ToString()) - 1));
System.Drawing.Printing.PrintController standardPrintController = new System.Drawing.Printing.StandardPrintController();
Telerik.Reporting.Processing.ReportProcessor reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
reportProcessor.PrintController = standardPrintController;
Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
instanceReportSource.ReportDocument = myReport;
reportProcessor.PrintReport(instanceReportSource, printerSettings);
Does anyone know such a problem or a possible solution?
Suggestion very appreciated :)
I've had the same problem once, but never used Telerik for anything. I was trying to print a XPS file with the PrintServer object, and came up with this solution to rotate the print.
Basicly I change the page orientation of the queue before I print for the user, and then change it back afterwards.
It might be usefull to you as well.
PrintServer ps = new PrintServer("\\\\somePrintServer");
var queue = ps.GetPrintQueue("printerShareName");
var oldOrientation = queue.UserPrintTicket.PageOrientation;
queue.UserPrintTicket.PageOrientation = PageOrientation.Landscape;
//print job here
queue.UserPrintTicket.PageOrientation = oldOrientation;