LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How print a text file included some encoded characters inside ?

Solved!
Go to solution

Hello,

 

In the past (very old Windows and LabWindows/CVI), to print an ASCII text file (like a simple * .txt report file), I used the "PrintTextFile" functions.

 

A few years later, until recently, I used the "NI report" functions.

But since LabWindows/CVI 2019 no longer supported the "NI report" functions, I came back (perhaps too quickly) to the "PrintTextFile" functions.

 

Today (W10, CVI 2020 f1), I have some problems with some encoded texts.

Only lines with a few encoded characters (é, î, ù, but also%, #, @) are not printed. I have a blank line instead.

The text file is completely filled, only printing is a problem.

I have tried some options of "SetPrintAttribute" (ATTR_PRINT_CHARACTER_SET, ATTR_PRINT_FONT_NAME), without success.

I thought of "PrintFile" ("CVI_AppPrintFile" with LabWindows/CVI ActiveX Server Interface). But I am not sure how to start using it. I'm going to do one of my tests ...

 

I don't want to use "Microsoft Office" ActiveX for a single ASCII text file.

 

If anyone has a proposal, I would be very happy to read it.

 

Thanks a lot for your help.

 

Best regards.


Certified LabWindows/CVI DEVELOPER (2004)
LabVIEW since 5.01 | LabWindows/CVI since 4.01
0 Kudos
Message 1 of 13
(3,249 Views)

Hye,

 

I tried the "NI LabWindows CVI Server 2020" ActiveX controller, to use the "CVI_AppPrintFile" function.

This is not good for me, because to be able to print, it requires opening the "LabWindows/CVI" software.

The final software that I will deliver, will only have the LabWindows/CVI RunTime, and not the LabWindows/CVI software.

 

So it could not be my solution.

 

 


Certified LabWindows/CVI DEVELOPER (2004)
LabVIEW since 5.01 | LabWindows/CVI since 4.01
0 Kudos
Message 2 of 13
(3,228 Views)

If you can go the PDF solution there are some libraries that can be linked to CVI. I'm currently using HARU Pdf library and find it lightweight, powerful and easy to use: here you can find a sample program I wrote using this library.

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 3 of 13
(3,223 Views)

I forgot to say that it prints regularly a lot of special characters: I have just tested it with à è é ì ò ù @ # ç °  [ ] á í ó ¡ ¿



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 4 of 13
(3,217 Views)

Dear Roberto,

To be honest, I was hoping it was you who answered ... as is often the case.

I will read carefully what you propose to me.

Thank you very much for your help.

Friendships


Certified LabWindows/CVI DEVELOPER (2004)
LabVIEW since 5.01 | LabWindows/CVI since 4.01
0 Kudos
Message 5 of 13
(3,143 Views)

Answer to the wrong person


Certified LabWindows/CVI DEVELOPER (2004)
LabVIEW since 5.01 | LabWindows/CVI since 4.01
0 Kudos
Message 6 of 13
(3,136 Views)

Dear Roberto,

 

Thank you for the PDF example, but unless I misunderstood, it does not allow to directly print the contents of the PDF file (except to go through the activeX of the viewer).

 

My problem does not concern the filling of the file but only its correct printing to a physical printer.

 

Example :

 

int status;
char strTmpPath[MAX_PATHNAME_LEN];
FILE *file = NULL;

 

strcpy (strTmpPath, "Temporary.txt");
if ((file = fopen (strTmpPath, "w")) != NULL)
{
     fputs ("à è é ì ò ù @ # ç ° [ ] á í ó ¡ ¿", file);

     status = fclose (file);

     file = NULL;


     // The content of the file is correct
     // (for example, use Notepad++ to open the file)

 

     status = SetPrintAttribute (ATTR_ORIENTATION, VAL_PORTRAIT);
     //status = SetPrintAttribute (ATTR_ORIENTATION, VAL_LANDSCAPE);
     status = SetPrintAttribute (ATTR_PRINT_AREA_WIDTH, VAL_INTEGRAL_SCALE);
     status = SetPrintAttribute (ATTR_PRINT_AREA_HEIGHT, VAL_USE_ENTIRE_PAPER);
     status = SetPrintAttribute (ATTR_SHOW_DATE, True);
     status = SetPrintAttribute (ATTR_SHOW_TIME, True);
     //status = SetPrintAttribute (ATTR_SHOW_FILE_NAME, True);
     status = SetPrintAttribute (ATTR_SHOW_LINE_NUMBERS, True);
     status = SetPrintAttribute (ATTR_SHOW_PAGE_NUMBERS, True);
     status = SetPrintAttribute (ATTR_PRINT_FONT_NAME, VAL_MESSAGE_BOX_FONT);
     //status = SetPrintAttribute (ATTR_PRINT_POINT_SIZE, 11);

 

     // To print to the default printer (with encoded problems)
     status = PrintTextFile (strTmpPath, "");

 

     // To delete the temporary file
//     status = DeleteFile (strTmpPath);
}
else
     MessagePopup ("Error", "Impossible to create the template file");

 

Friendships


Certified LabWindows/CVI DEVELOPER (2004)
LabVIEW since 5.01 | LabWindows/CVI since 4.01
0 Kudos
Message 7 of 13
(3,132 Views)

I wonder if this kind of problems lies in CVI or elsewhere: since you have correctly generated a text file, what happens if you print if from Notepad? There are a number of different layers and processes involved in printing data which include handling of codepages and fonts in several of them, which means we must discriminate each step result to understand where to operate to address this problem.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 8 of 13
(3,082 Views)

@Pims  ha scritto:

Dear Roberto,

 

Thank you for the PDF example, but unless I misunderstood, it does not allow to directly print the contents of the PDF file (except to go through the activeX of the viewer).

There actually is a way to print the PDF file without using ActiveX: the following code is a port with modifications of OpenDocumentInDefaultFolder code in the Programmer's Toolbox:

 

HMODULE			g_hSHELL32 = NULL;
SHELLEXECUTEINFO	seInfo;
BOOL 			shellExecuteSucceeded = FALSE;
BOOL (WINAPI *g_pShellExecuteEx)    (LPSHELLEXECUTEINFO lpExecInfo);

memset(&seInfo, 0, sizeof(seInfo));

seInfo.cbSize = sizeof(seInfo);
seInfo.fMask = SEE_MASK_FLAG_NO_UI;
seInfo.lpVerb = "print";
seInfo.lpFile = file;	// Pathname of the file to print
seInfo.nShow = SW_HIDE;
if (!(g_hSHELL32 = LoadLibrary ("shell32.dll"))) {
	error = ToolErr_ErrorLoadingDLL;
	goto Error;
}
if (!(g_pShellExecuteEx = (void*)GetProcAddress (g_hSHELL32, "ShellExecuteExA"))) {
	error = ToolErr_FuncNotFound;
	goto Error;
}

(*g_pShellExecuteEx)(&seInfo);

error = 0; line = __LINE__;
if ((int)seInfo.hInstApp <= 32) {
	switch((int)seInfo.hInstApp) {
		case SE_ERR_FNF:		error = UIEFileWasNotFound; break;
		case SE_ERR_PNF:		error = UIEFileWasNotFound; break;
		case SE_ERR_ACCESSDENIED:	error = UIEAccessDenied; break;
		case SE_ERR_OOM:		error = UIEOutOfMemory; break;
		case SE_ERR_DLLNOTFOUND:	error = ToolErr_ErrorLoadingDLL; break;
		case SE_ERR_SHARE:		error = UIEAccessDenied; break;
		case SE_ERR_ASSOCINCOMPLETE:	error = ToolErr_FileAssociationNotAvailable; break;
		case SE_ERR_DDETIMEOUT:		error = ToolErr_UnknownSystemError; break;
		case SE_ERR_DDEFAIL:		error = ToolErr_UnknownSystemError; break;
		case SE_ERR_DDEBUSY:		error = ToolErr_UnknownSystemError; break;
		case SE_ERR_NOASSOC:		error = ToolErr_FileAssociationNotAvailable; break;
		default: 			error = ToolErr_UnknownSystemError; break;
	}
}

 

 

A problem in this code is that it actually leaves an instance of the PDF viewer open: this is not important to me so I didn't addressed this item.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 9 of 13
(3,079 Views)

Hello Roberto,

 

If I print the text file with an other software (Notepad++, Word, etc...), the printing is fully correct.

 

My friend tried another solution, using some Windows low layer features :

#include <winspool.h> and these functions :

GetDefaultPrinter, OpenPrinter, StartDocPrinter, StartPagePrinter, WritePrinter , EndPagePrinter, EndDocPrinter, ClosePrinter.

It did print successfully, but with a few other bad characters encoded (not the same), so no success.

 

Yesterday, I used the functions of Microsoft Word (.txt, .log, etc...) and Excel (.csv) with success.

But using Microsoft Office for a simple text file is killing me.

 

Before no longer supported the "NI report" functions, National Instruments, and especially LabWindows/CVI teams, should have thought about the alternative.

Not to mention the non-functional examples (especially those linked to activeX, like RichTextBox, etc...).

 

Thank you very much for your help, I will look at your other post.

 

Best regards.


Certified LabWindows/CVI DEVELOPER (2004)
LabVIEW since 5.01 | LabWindows/CVI since 4.01
0 Kudos
Message 10 of 13
(3,067 Views)