Getting print data - Windows (Redmon)

1.4k views Asked by At

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. But all the tutorials I have seen online as of now relates to storing the data into a PDF using RedMon.

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.

I have been unsuccessful in finding a solution for this till now. Is this achievable?

2

There are 2 answers

0
amelinux On

Here a solution in 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);
}
5
Kurt Pfeifle On

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:

  • firstly, all these solutions use PostScript printer drivers;

  • 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.

So for your purpose you most likely don't need Ghostscript. Instead of running Ghostscript you can directly save the received data as is to file.

However, you can only continue to use PostScript if your printer really is a PostScript-capable device. And of course you've to be PostScript-savvy in order to 'edit its content'.

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. And of course you'll have to be able to understand the respective printer languag well enough in order to 'edit its content'...