是否可以使用windows后台处理程序API打印PDF文件。我试过下面的代码,但它不起作用。。。

int print_handle = 0;
OpenPrinter(pPrinterName, &print_handle, NULL);
if (print_handle == 0)
{
    return 0;
}
docinfo1.pDocName = (LPTSTR)("My PDF");
docinfo1.pOutputFile = NULL;
docinfo1.pDatatype = (LPTSTR)("RAW");
temp = StartDocPrinter(print_handle, 1, &docinfo1);
temp = StartPagePrinter(print_handle);
temp = WritePrinter(print_handle, (LPBYTE)filebuff, filelen, &bytes_written);
EndPagePrinter(print_handle);
EndDocPrinter(print_handle);

writeprint函数返回SUCCESS,但未打印任何内容。正在使用此API打印TXT和PRN文件。

最佳答案

Windows没有内置的打印PDF文件的能力。
您必须使用外部应用程序或库,例如Ghostscript
我应该注意到,因为您的代码使用“RAW”数据类型(如official sample),所以它直接将写入的作业数据发送到打印机。ASCII数据可以工作,因为几乎所有的打印机都可以接收和打印ASCII。如果打印机将PDF理解为PDL(页面描述语言-其他示例是PCL或PostScript),它将打印PDF。但对于所有其他打印机,PDF需要转换成打印机能理解的PDL。

关于c - 使用Windows Spooler API以编程方式打印PDF文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48439920/

10-11 22:41
查看更多