10-29-2021 03:39 AM - edited 10-29-2021 03:40 AM
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.
Solved! Go to Solution.
10-29-2021 07:49 AM - edited 10-29-2021 07:50 AM
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.
10-29-2021 08:25 AM - edited 10-29-2021 08:43 AM
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.
10-29-2021 08:45 AM
I forgot to say that it prints regularly a lot of special characters: I have just tested it with à è é ì ò ù @ # ç ° [ ] á í ó ¡ ¿
11-02-2021 04:12 AM
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
11-02-2021 06:16 AM - edited 11-02-2021 06:21 AM
Answer to the wrong person
11-02-2021 06:20 AM - edited 11-02-2021 06:25 AM
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
11-03-2021 05:05 AM
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.
11-03-2021 05:19 AM - edited 11-03-2021 05:20 AM
@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.
11-04-2021 05:51 AM
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.