简体   繁体   English

获取打印数据-Windows(Redmon)

[英]Getting print data - Windows (Redmon)

I am trying to develop an app to retrieve print data, edit its content and then print the data. 我正在尝试开发一个应用程序以检索打印数据,编辑其内容,然后打印数据。 I am using RedMon for that purpose. 我正在为此目的使用RedMon But all the tutorials I have seen online as of now relates to storing the data into a PDF using RedMon . 但是,到目前为止,我在网上看到的所有教程都涉及使用RedMon将数据存储到PDF中。

I want to be able to configure RedMon on a windows platform such that it writes the entire print data(the data that is bound to appear on the printing paper) as it is into a .txt file or maybe provide directly as an input to the java app that I have made. 我希望能够在Windows平台上配置RedMon ,这样它就可以将整个打印数据(必然会出现在打印纸上的数据)写入.txt文件中,或者直接作为输入提供给我制作的java应用程序。

I have been unsuccessful in finding a solution for this till now. 到目前为止,我一直没有找到解决方案。 Is this achievable? 这可以实现吗?

You are aware that your 'print data' isn't the same for all printers, are you? 您知道所有打印机的“打印数据”并不相同,是吗? Its file format depends on the printer driver used for the specific print queue. 其文件格式取决于用于特定打印队列的打印机驱动程序。

If you really followed all the RedMon tutorials that teach who to store the print data into PDF, you'll surely have noticed 2 things: 如果您真的遵循了所有RedMon教程,这些教程教谁将打印数据存储为PDF,那么您肯定会注意到两件事:

  • firstly , all these solutions use PostScript printer drivers; 首先 ,所有这些解决方案都使用PostScript打印机驱动程序;

  • secondly , all these solutions use RedMon as a print monitor that captures the PostScript data and hands it over to Ghostscript to convert it to PDF. 其次 ,所有这些解决方案都使用RedMon作为打印监视器,该监视器捕获PostScript数据并将其移交给Ghostscript以将其转换为PDF。

So for your purpose you most likely don't need Ghostscript. 因此,出于您的目的,您很可能不需要Ghostscript。 Instead of running Ghostscript you can directly save the received data as is to file. 无需运行Ghostscript,您可以直接将接收到的数据保存为文件。

However, you can only continue to use PostScript if your printer really is a PostScript-capable device. 但是,如果您的打印机确实是具有PostScript功能的设备,则只能继续使用PostScript。 And of course you've to be PostScript-savvy in order to 'edit its content'. 当然,您必须精通PostScript才能“编辑其内容”。

Should your printer use another printer language (PCL, TIFF, ESC/P, ESC/POS or whatever), then you'll have to replace the PostScript printer driver by whatever is appropriate. 如果您的打印机使用另一种打印机语言(PCL,TIFF,ESC / P,ESC / POS或任何其他语言),则必须用适当的方式替换PostScript打印机驱动程序。 And of course you'll have to be able to understand the respective printer languag well enough in order to 'edit its content'... 当然,您必须能够充分理解相应的打印机语言才能“编辑其内容” ...

Here a solution in C: 这是C中的解决方案:

int main(int argc, char** argv)
{
    HANDLE handle;
    unsigned char ucBuffer[1024];
    FILE *pFileTarget;
    DeleteFile("c:\\toprint.txt");
    pFileTarget=fopen("c:\\toprint.txt","wb");
  handle = GetStdHandle(STD_INPUT_HANDLE);

    while (1)
    {
        DWORD dwBytesRead=0;
        if(ReadFile(  handle,ucBuffer,1024, &dwBytesRead,NULL) == 0)
    {
            break;
        }else
            fwrite(ucBuffer,dwBytesRead,1,pFileTarget);
    }
    fclose(pFileTarget);
  CloseHandle(handle);
    return (EXIT_SUCCESS);
}

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

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