print a text file

Discussion in 'Programmer's Corner' started by anhnha, Jan 16, 2016.

  1. anhnha

    Thread Starter Active Member

    Apr 19, 2012
    773
    47
    Mod note: moved to Programmer's Corner

    Hi,
    I have an MFC application on windows. The app will will create a log file with text extension, let's call log.txt.
    The computer is connected with an invoice printer ANTECH AP INVOICE PRINTER 250. Now I want to print that text file. Is there a simple way to do that? I mean we print automatically by some kinds of software or programming not manual.
    Each time a log file is created, it should be automatically sent to the invoice printer and print out.
     
    Last edited by a moderator: Jan 19, 2016
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,884
    1,005
  3. anhnha

    Thread Starter Active Member

    Apr 19, 2012
    773
    47
    Actually I already read that and several pages but I asked for people who are experienced so we can have a simple solution.
     
  4. sailorjoe

    Member

    Jun 4, 2013
    361
    63
    Can you open the text file with Wordpad or Textpad? Can you print from there?
    If that works, then you need a script that runs when some trigger event occurs, and opens Wordpad with the the file in question, and prints it. Then again, perhaps your script language can just print the file directly.

    I have to assume that you want to print the log file after it is closed, not when it is created, yes? Men it's created, it's blank. When it's closed could be your trigger event.
     
  5. Sam Matthews

    Member

    Jan 16, 2016
    178
    3
    This was my first thought. My natural instinct would be to advise you open the file after it has been created and then manually print it. Or was it that you wanted it to become an automated process in which case you might be able to automate a script to do such a thing, but that is way outside of my advisory scope.
     
  6. anhnha

    Thread Starter Active Member

    Apr 19, 2012
    773
    47
    Yes and yes.
    Yes, I also thought about that. After the file is closed, there should be some code lines for printing. However, I am not familiar with script language as you said. I think I will write it in C++.
     
  7. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,884
    1,005
    If you plan on using MFC then the .Net framework is the only way to do it. There is no "simple" solution.
     
  8. DNA Robotics

    Member

    Jun 13, 2014
    123
    26

    If that is YOUR MFC application that you can edit & rebuild,

    Printing and Print Preview
    Visual Studio 2015

    Other Versions
    MFC supports printing and print preview for your program's documents via classCView. For basic printing and print preview, simply override your view class'sOnDrawmember function, which you must do anyway. That function can draw to the view on the screen, to a printer device context for an actual printer, or to a device context that simulates your printer on the screen.

    You can also add code to manage multipage document printing and preview, to paginate your printed documents, and to add headers and footers to them.

    This family of articles explains how printing is implemented in the Microsoft Foundation Class Library (MFC) and how to take advantage of the printing architecture already built into the framework. The articles also explain how MFC supports easy implementation of print preview functionality and how you can use and modify that functionality.

    What do you want to know more about?

    Printing

    Print preview architecture

    Sample

    https://msdn.microsoft.com/en-us/library/df9f4ta6.aspx
     
  9. wayneh

    Expert

    Sep 9, 2010
    12,120
    3,046
    On a Mac, it's easy to program a script to take an action whenever a watched folder is modified, in this case by adding a file. Printing the newly added file would be trivial.

    I assume you don't care about a Mac solution, but I have to believe there is a comparable directory-watching capability in your system.
     
  10. anhnha

    Thread Starter Active Member

    Apr 19, 2012
    773
    47
    Thanks everyone. I programmed the MFC application so I can edit it. Mac solution is good but you are right I don't use Mac.
     
  11. Evanguy

    Member

    Dec 21, 2014
    81
    8
    Autoit script could do this. And its pertty simple to learn/piece together a script. also people on the forum love giving examples if you show you tried
     
Loading...