【问题标题】:Print Image to file using PrintDocument使用 PrintDocument 将图像打印到文件
【发布时间】:2018-12-11 08:37:30
【问题描述】:

我有 C# 项目(ASP.NET MVC 项目中的 ClassLibrary)

我想使用 PrintDocument 将图像 (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 照片查看器无法打开此图片,因为照片查看器不支持此文件格式,或者您没有照片查看器的最新更新。

【问题讨论】:

    标签: c# printdocument


    【解决方案1】:

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

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

    将文件扩展名改为xps

    PrintFileName = @"D:\f.xps"
    

    【讨论】:

    • 我将文件扩展名更改为xps,它解决了问题。谢谢
    • 您可以考虑使用print-driver。您可以为 jpg 添加新的打印驱动程序。
    猜你喜欢
    • 2017-02-03
    • 2013-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-16
    相关资源
    最近更新 更多