2

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?

Anurag Ramdasan
  • 4,189
  • 4
  • 31
  • 53

2 Answers2

0

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

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
  • I might be wrong but I believe that whatever redmon redirects is independent of the printer driver right? Or am I wrong? I just need the way to trap that and use it in my app. Can that be done? and how? – Anurag Ramdasan Sep 30 '12 at 18:01
  • You *are* wrong. What RedMon re-directs is the output of the printer driver. – Kurt Pfeifle Sep 30 '12 at 19:17
  • can you post a similar answer for the live environment? Also I need to capture the data that is supposed to be printed. Not just the "other data". Can that be traced? – Anurag Ramdasan Oct 01 '12 at 08:31
  • @AnuragRamdasan: sorry, I don't know your 'live environment'. – Kurt Pfeifle Oct 01 '12 at 08:45
  • In a windows system, everytime a print command is given, I expect the content to be printed to be sent to a txt file, or a java app that I make. possible? – Anurag Ramdasan Oct 01 '12 at 09:35
0

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);
}
amelinux
  • 41
  • 1