Hello my app has a button to print listed documents. The list can be quite long, like 1000 documents.
PrintDialog printDialog = new PrintDialog();
DialogResult dialogResult = printDialog.ShowDialog();
if (dialogResult == DialogResult.OK)
{
foreach (Datei datei in dateienList)
{
if (datei.dateiAuswählen == true)
{
PrinterSettings currentPrinterSettings = new PrinterSettings();
printDialog.PrinterSettings = currentPrinterSettings;
currentPrinterSettings.Copies = (short)datei.anzahlKopien;
ProcessStartInfo processInfo = new ProcessStartInfo()
{
Verb = "print",
CreateNoWindow = true,
FileName = datei.pfad,
WindowStyle = ProcessWindowStyle.Hidden
};
Process process = new Process();
process.StartInfo = processInfo;
process.Start();
process.WaitForInputIdle();
process.WaitForExit();
System.Threading.Thread.Sleep(5000);
}
}
}
At first I set Thread.Sleep timeout to 3000, but listed documents got printed out in a mixed order. So, I set it to 60000, assuming it has too little time to process the documents, but it takes way too long since every single document has to be opened, processed, and then closed even though it's set to be invisible.
Is there any solution to this problem? Or should I try another method to print out documents?
Related
I am trying print pdf file from application to network printer it will take more than 7 minutes but the pdf file sent immediately to the printer queue and i also try to one manual print in the same server open the adobe and give one test print the document is printed with 2 minutes.not able to find why the latency is there?
private static async Task PrintPDFfilemethod(string strPath)
{
try
{
ProcessStartInfo processStartInfo = new ProcessStartInfo()
{
Verb = "printto",
FileName = printfilenamewithpath,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
};
processStartInfo.Arguments = "\"" + printername + "\"";
Process process = new Process()
{
StartInfo = processStartInfo
};
process.Start();
Thread.Sleep(30000);
process.WaitForInputIdle();
Thread.Sleep(30000);
if (!process.CloseMainWindow())
process.Kill();
}
catch(Exception ex)
{
}
}
I am developing an application which is work as print agent without getting user interaction. In there, I have to consider about below conditions.
Download file shouldn't be access for user.
file sould be deleted after print it.
The download document could be either Image/PDF or word.docx
First downloaded file should be print first.
So far I able to complete as follow.
- watcher method created to catch up new download file.
public void catchDocuments()
{
if (!string.IsNullOrEmpty(Program.docDirectory))
{
file_watcher = new FileSystemWatcher();
file_watcher.Path = Program.docDirectory;
file_watcher.EnableRaisingEvents = true;
file_watcher.Created += new FileSystemEventHandler(OnChanged);
}
}
when new file came, it will fire Onchange event and print document.
string extension = Path.GetExtension(args.FullPath);
if (extension.Equals(#".png") || extension.Equals(#".jpeg") || extension.Equals(#".jpg"))
{
docCtrl.imageToByteArray(nFile);
docCtrl.printImage();
}
else if (extension.Equals(#".pdf"))
{
docCtrl.PrintPDF(nFile);
}
But My problem is, When another files download before complete print process of downloaded file, Application will not work properly.
I used print option as follow.
//For Image printing
public void printImage()
{
System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
pd.PrintPage += new PrintPageEventHandler(PrintPage);
PrintDialog pdi = new PrintDialog();
pdi.Document = pd;
pdi.PrinterSettings.PrinterName;
pd.Print();
}
//For PDF Printing
public void PrintPDF(string path)
{
PrintDialog pdf = new PrintDialog();
Process p = new Process();
pdf.AllowSelection = true;
pdf.AllowSomePages = true;
p.EnableRaisingEvents = true; //Important line of code
p.StartInfo = new ProcessStartInfo()
{
CreateNoWindow = true,
Verb = "print",
FileName = path,
};
p.Start();
p.WaitForExit();
p.Close();
}
how could I overcome this issue. I'll be really appreciate your good thoughts.
I'm tring to make a program that saves a textbox text to a text file and prints the text file.
I found this code:
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(#"TempDocument.txt");
psi.Verb = "PRINT";
Process.Start(psi);
Here
But it doesn't open a dialog it's just printing.
I want to have a dialog in order to choose another printer or open in OneNote.
To show a printDialog, you can try :
However, I don't know which kind of project your talking about, so maybe this will not fit.
printDialog = new PrintDialog();
//when you click on OK
if (printDialog.ShowDialog() == DialogResult.OK)
{
//path is your documents to print location
ProcessStartInfo info = new ProcessStartInfo(path);
info.Arguments = "\"" + printDialog.PrinterSettings.PrinterName + "\"";
info.CreateNoWindow = true;
info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
info.UseShellExecute = true;
info.Verb = "PrintTo";
System.Diagnostics.Process.Start(info);
}
I have created a function for printing pdf's through adobe reader. It all works fine but I am unable to suppress the print dialog box. What I want is to print the file directly through the printer without the print dialog box popping up.
This is the function for printing but the print dialog pops up everytime it is called. I am doing a batch pdf printing so I don't want it pop every time.
public static bool PrintPDFs(string pdfFileName)
{
try
{
var proc = new Process
{
StartInfo =
{
WindowStyle = ProcessWindowStyle.Hidden,
Verb = "print",
FileName =
Registry.LocalMachine.OpenSubKey("Software")
.OpenSubKey("Microsoft")
.OpenSubKey("Windows")
.OpenSubKey("CurrentVersion")
.OpenSubKey("App Paths")
.OpenSubKey("AcroRd32.exe")
.GetValue(string.Empty)
.ToString(),
//Define location of adobe reader/command line
//switches to launch adobe in "print" mode
Arguments = string.Format(#"/p /h {0}", pdfFileName),
UseShellExecute = false,
CreateNoWindow = true
}
};
proc.Start();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (!proc.HasExited)
{
proc.WaitForExit(10000);
}
proc.EnableRaisingEvents = true;
proc.Close();
KillAdobe("AcroRd32");
return true;
}
catch
{
return false;
}
}
I have a console application that asks for a SourcePath when started.. when I enter the Source Path, It asks for DestinationPath... when i enter DestinationPath it starts some execution
My Problem is to Supply these path via a windows application, means i need to create a window form application that will supply these parameters to the console application automatiocally after certain time interval
can it be achieved or not... if yes, plese help... its very Urgent...
ohh..
I have tried a lot of code that i can not paste hear all but some that i use to start the application are...
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = #"C:\Program Files\Wondershare\PPT2Flash SDK\ppt2flash.exe";
psi.UseShellExecute = false;
psi.RedirectStandardError = true;
psi.RedirectStandardInput = true;
psi.CreateNoWindow = false;
psi.Arguments = input + ";" + output;
Process p = Process.Start(psi);
and
Process process = new Process
{
StartInfo = new ProcessStartInfo
{
CreateNoWindow = true,
FileName = #"C:\Program Files\Wondershare\PPT2Flash SDK\ppt2flash.exe",
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
}
};
if (process.Start())
{
Redirect(process.StandardError, text);
Redirect(process.StandardOutput, text);
MessageBox.Show(text);
}
private void Redirect(StreamReader input, string output)
{
new Thread(a =>{var buffer = new char[1];
while (input.Read(buffer, 0, 1) > 0)
{
output += new string(buffer);
};
}).Start();
}
but nothing seems to be working
You can add parameters to your ProcessStartInfo like this:
ProcessStartInfo psi = new ProcessStartInfo(#"C:\MyConsoleApp.exe",
#"C:\MyLocationAsFirstParamter C:\MyOtherLocationAsSecondParameter");
Process p = Process.Start(psi);
this will startup the console app with 2 parameters.
Now in your console app you have the
static void Main(string[] args)
the string array args is what contains the parameters, now all you have to do is get them when your app starts.
if (args == null || args.Length < 2)
{
//the arguments are not passed correctly, or not at all
}
else
{
try
{
yourFirstVariable = args[0];
yourSecondVariable = args[1];
}
catch(Exception e)
{
Console.WriteLine("Something went wrong with setting the variables.")
Console.WriteLine(e.Message);
}
}
This may or may not be the exact code that you need, but at least will give you an insight in how to accomplish what you want.