print a text file

Thread Starter

anhnha

Joined Apr 19, 2012
905
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:

Thread Starter

anhnha

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

sailorjoe

Joined Jun 4, 2013
364
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.
 

Sam Matthews

Joined Jan 16, 2016
178
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.
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.
 

Thread Starter

anhnha

Joined Apr 19, 2012
905
an you open the text file with Wordpad or Textpad? Can you print from there?
Yes and yes.
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.
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++.
 

DNA Robotics

Joined Jun 13, 2014
647
I have an MFC application on windows.

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
 

wayneh

Joined Sep 9, 2010
17,496
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.
 

Thread Starter

anhnha

Joined Apr 19, 2012
905
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.
 

Evanguy

Joined Dec 21, 2014
85
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
 
Top