我想以静默方式打印.docx文件,并能够选择打印机的纸盘。
起初,我尝试使用Microsoft.Office.Interop.Word打印.docx,但单词正在打开...
在将.docx文件转换为图像并使用ProcessStartInfo打印后,但向用户显示了打印窗口。
ProcessStartInfo info = new ProcessStartInfo(imageFilePath);
info.Verb = "Print";
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(info);
我尝试了另一种方法,它以静默方式打印图像,但图像模糊且缩放不正确。
PrinterSettings settings = new PrinterSettings();
string defaultPrinter = settings.PrinterName;
FileInfo fileInfo = new FileInfo(imageFilePath);
PrintDocument pd = new PrintDocument();
pd.DocumentName = fileInfo.Name;
pd.PrintPage += (sender, args) =>
{
Image i = Image.FromFile(imageFilePath);
PrintPageEventArgs arguments = args;
System.Drawing.Rectangle m = new System.Drawing.Rectangle()
{
Y = 0,
X = 0,
Location = new System.Drawing.Point(0, 0),
Height = args.MarginBounds.Height,
Size = args.MarginBounds.Size,
Width = args.MarginBounds.Width
};
if ((double)i.Width / (double)i.Height > (double)m.Width / (double)m.Height)
{
m.Height = (int)((double)i.Height / (double)i.Width * (double)m.Width);
}
else
{
m.Width = (int)((double)i.Width / (double)i.Height * (double)m.Height);
}
args.Graphics.DrawImage(i, m);
};
pd.Print();
因此可以无声打印.docx并能够选择打印机的纸盘吗?
没有人遇到同样的问题。在这方面有帮助。预先感谢。
我本人做了类似的事情,但是如果您可以选择纸盘,我从不查阅文档。我相信这些是在打印服务器上设置的(如果您使用的是一台),并且如果您的应用程序具有访问权限,它们将能够引用这些。
string PrinterName = @"\\Server\nameOfThePrinter";
ProcessStartInfo printProcessInfo = new ProcessStartInfo()
{
Verb = "PrintTo",
CreateNoWindow = true,
FileName = pdfFileName,
Arguments = "\"" + PrinterName + "\"",
WindowStyle = ProcessWindowStyle.Hidden
};
Process printProcess = new Process();
printProcess.StartInfo = printProcessInfo;
printProcess.Start();
printProcess.WaitForInputIdle();
printProcess.WaitForExit(10000);
if (printProcess.HasExited)
{
}else
{
printProcess.Kill();
}
return true;
此外,您可能想在https://www.codeproject.com/Tips/598424/How-to-Silently-Print-PDFs-using-Adobe-Reader-and处研究此文章>
干杯!
[我找到了一种解决方案,我无法以静默方式打印.docx,所以我之前将其转换为.png图像。