c#-使用PrintDocument将图像打印到文件
作者:互联网
我有C#项目(ASP.NET MVC项目中的ClassLibrary)
我想使用PrintDocument将Image(System.Drawing.Image)打印到文件
private static void SendToPrinter(Image barkod)
{
PrintDocument pd = new PrintDocument();
pd.PrinterSettings = new PrinterSettings
{
PrinterName = "Microsoft XPS Document Writer",
PrintToFile = true,
PrintFileName = @"D:\f.jpg"
};
pd.PrintPage += (o, e) =>
{
Point loc = new Point(100, 100);
e.Graphics.DrawImage(barkod, loc);
};
pd.Print();
barkod.Dispose();
}
发生了什么事是在特定位置创建了文件,但是当我尝试打开图像时出现错误
Windows Photo Viewer can’t open this picture because either Photo Viewer doesn’t support this file format, or you don’t have the latest updates to Photo Viewer.
解决方法:
XPS Document Writer以* .xps或* .oxps格式打印.
您需要考虑将xps | oxps转换为.jpg
将文件更改为xps
PrintFileName = @"D:\f.xps"
标签:printdocument,c 来源: https://codeday.me/bug/20191024/1923932.html