使用VC ++将Postscript文档发送到打印机 [英] Send Postscript Document to Printer using VC++

查看:555
本文介绍了使用VC ++将Postscript文档发送到打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个附言文件。如何使用Visual C ++将其发送到打印机?似乎应该很简单。

I have a postscript file. How can I send it to a printer using Visual C++? This seems like it should be simple.

推荐答案

如果打印机直接支持PostScript,则可以假脱机执行以下原始打印作业: / p>

If the printer supports PostScript directly you can spool a raw print jobs like this:

HANDLE ph;

OpenPrinter(&ph, "Printer Name", NULL);

di1.pDatatype = IsV4Driver("Printer Name") ? "XPS_PASS" : "RAW"; 
di1.pDocName = "Raw print document";
di1.pOutputFile = NULL;

StartDocPrinter(ph, 1, (LPBYTE)&di1);

StartPagePrinter(ph);

WritePrinter(ph, buffer, dwRead, &dwWritten);

EndPagePrinter(ph);

EndDocPrinter(ph)

重复执行WritePrinter,直到完成整个后台处理

Repeat the WritePrinter until you have spooled the whole file.

IsV4Driver()检查版本4驱动程序,在Windows 8和Server 2012中这是必需的:

IsV4Driver() Checks for version 4 drivers, this is necessary in Windows 8 and Server 2012:

bool IsV4Driver(wchar_t* printerName)
{
    HANDLE handle;
    PRINTER_DEFAULTS defaults;

    defaults.DesiredAccess = PRINTER_ACCESS_USE;
    defaults.pDatatype = L"RAW";
    defaults.pDevMode = NULL;

    if (::OpenPrinter(printerName, &handle, &defaults) == 0)
    {
        return false;
    }

    DWORD version = GetVersion(handle);

    ClosePrinter(handle);

    return version == 4;
}

DWORD GetVersion(HANDLE handle)
{
    DWORD needed;

    GetPrinterDriver(handle, NULL, 2, NULL, 0, &needed);

    std::vector<char> buffer(needed);

    return ((DRIVER_INFO_2*) &buffer[0])->cVersion;
}

这篇关于使用VC ++将Postscript文档发送到打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆