我想无声打印一个.docx文件,并能选择打印机的托盘。
起初,我尝试使用Microsoft.Office.Interop.Word打印.docx文件,但是Word会打开...
之后,我将.docx文件转换为图像,并使用ProcessStartInfo打印,但它会向用户显示一个打印窗口。
起初,我尝试使用Microsoft.Office.Interop.Word打印.docx文件,但是Word会打开...
之后,我将.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 文件并能够选择打印机的托盘?
有人遇到过同样的问题吗?在此先感谢任何帮助。