繁体   English   中英

使用PrintDocument将图像打印到文件

[英]Print Image to file using 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不支持此文件格式,或者您没有Photo Viewer的最新更新。

在此输入图像描述

XPS Document Writer以* .xps或* .oxps格式打印。

您需要考虑将xps | oxps转换为.jpg

将文件的扩展名更改为xps

PrintFileName = @"D:\f.xps"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM