Discussions related to Visual Prolog
User avatar
abdelrahman
Posts: 14
Joined: 13 Sep 2009 6:23

how to print Text file and simple string

Unread post by abdelrahman »

I Need to know the simplest way to print a text File and a string via my local Printer
I am using VIP 10.2 CE .
Idon't know how to use Veprint class .
User avatar
Thomas Linder Puls
VIP Member
Posts: 1401
Joined: 28 Feb 2000 0:01

Re: how to print Text file and simple string

Unread post by Thomas Linder Puls »

Printing is somewhat complex/difficult. The fundamental problem is that there is not a simple transformation from a piece of text to a printed document. The printer has a resolution and the pages some size, you must choose font(s), text should be divided into lines and lines into pages, headers and footers should potentially be added.

The PFC support uses the printDocument class. You will open/close the document and open/close each page, and inside each page you will use the windowGDI operations (setFont, setForeColor, drawText, ...) to "draw" your page.
Regards Thomas Linder Puls
PDC
Harrison Pratt
VIP Member
Posts: 443
Joined: 5 Nov 2000 0:01

Re: how to print Text file and simple string

Unread post by Harrison Pratt »

In the remote past when I needed a very quick print of text I wrote the text to a temporary file and then called NotePad with the "\P' option in the command line to print it, and then deleted the temporary file. You probably have other installed applications that you could invoke to print as well.

https://answers.microsoft.com/en-us/win ... 1208e1b389

You can also print from the Windows command prompt. That might entail having your application write a batch file to do that.

https://www.scaledeskit.net/post/How-ca ... ss%20Enter.

These are some rough ideas -- I don't have code to share on how to do these things.
Kari Rastas
Active Member
Posts: 37
Joined: 4 Mar 2000 0:01

Re: how to print Text file and simple string

Unread post by Kari Rastas »

To write the VIP code for printing from your own made program is “worth” only if the users of that program would use that printing rather much. If it is worth the time you can make the code to print very sophisticated documents directly from the VIP program. But as said it is a considerable “investment”.

The easiest way to write fast the VIP code to produce a document with charts, different fonts, headers, lists etc, is to make the code to write the different pieces with the needed html codes in a file. Then the formed html-file is easy to be printed with numerous different programs and to be send as email or put on your internet site.

Here is an example how I made the code for the html page of EU countries import/export development with USA, China and Russia.
https://karirast.com/euros/GB/EU_geoPol_countries.html

Code: Select all

predicates     makeEUgeoPoliticalPage:(string LANG,string* Countries).   clauses     makeEUgeoPoliticalPage(Language,Countries):-         O= outputStream_file::createUtf8(string::format("%s%\\EU_geoPol_countries.html",uljasCore::euroTulosteet,Language)),         FLName="EU_geoPol_countries.html",         htmlStuff::htmlStart(O,Language),         O:write(@"<style> table, th, td {   border: 1px solid black;   } img.pictures {   width: 60%;   margin: auto;   display: block;} </style>"),             if Language = "FIN" then                 O : write("<title>EU maiden vienti ja tuonti suurvaltojen USA, Kiina ja Venäjä kanssa</title>\n")             else                 O : write("<title>EU countries' exports and imports with the great powers, USA, China and Russia</title>\n")             end if,             htmlStuff::metaViewport(O),             htmlStuff::htmlContent(O,Language),             O : write("\n</head>"),             O : write("\n<body>"),             htmlStuff::topRowEU(O,"Trade",Language),             htmlStuff::languageEurostatLink(O,Language,FLName),               if Language = "FIN" then                 O : write("\n<H1>EU maiden vienti ja tuonti suurvaltojen USA, Kiina ja Venäjä kanssa</H1>\n")             else                 O : write("<H1>EU countries' exports and imports with the great powers, USA, China and Russia</H1>\n")             end if,           foreach G in Countries do             O:writef("\n<li><a href=\"#%\">%s (%)</a>",G,getCountryName(G,Language),G)         end foreach,           foreach C in Countries do             O:writef("\n<br><hr><a name=\"%\"><H1>% (%)</H1>",C,getCountryName(C,Language),C),             O:writef("\n<BR><img class=pictures src=\"gpol_%.png\" alt=\"%s\" class=\"center\"/>\n<p>\n<p>",getCountryName(C,Language),Language)         end foreach,         O:write("\n</BODY>\n</HTML>"),         O:close().    
     
        
Harrison Pratt
VIP Member
Posts: 443
Joined: 5 Nov 2000 0:01

Re: how to print Text file and simple string

Unread post by Harrison Pratt »

Nice work, Kari!

Are you creating the graph images in your Visual Prolog app or using another product to make them?
Kari Rastas
Active Member
Posts: 37
Joined: 4 Mar 2000 0:01

Re: how to print Text file and simple string

Unread post by Kari Rastas »

Yes Harrison all the graph images are produced with my graph making DLL.

To add to my earlier comment in order to encourage others to use VIP to produce documents to be printed from their VIP apps.

I had rather much experience with printing from own VIP apps. Here is an example from the year 1997. An automatic computer made analysis of Nokia and printed in a PDF file using Adobe Acrobat as the printer. My program made yearly tens of thousands such prints from numerous Finnish companies in Finnish, Swedish and English. I used several normal printers and these pdf-printer programs for the prints in internet sites. VIP is also an excellent tool to create sophisticated prints and when the coding is done, you can produce as much prints as you (and your clients) want.

https://karirast.com/nokiate.pdf
Harrison Pratt
VIP Member
Posts: 443
Joined: 5 Nov 2000 0:01

Re: how to print Text file and simple string

Unread post by Harrison Pratt »

A simple text file print to your default printer using Notepad. Notepad closes itself automatically when the print job is complete.
In practical use one will want to add error checking for file-not-found, printer-not-working, etc.

Code: Select all

predicates     onFilePrint : window::menuItemListener. clauses     onFilePrint(_Source, _MenuTag) :-         /* Notepad command switches             /A <filename> open file as ansi             /W <filename> open file as unicode (Wide)             /P <filename> print filename             /PT <filename> <printername> <driverdll> <port> print filename to designated printer             There is no switch to disable file menu functionality.         */         TextFile = @"..\main.pack",         Cmd = string::format("Notepad /P %", TextFile),         EXE = useExe::new(Cmd),         EXE:run(),         std::repeat(),         _Code = Exe:tryGetExitCode(), % If you can get the code, the process is done.         !.         % Exe:terminate(Code), % If you can get the ExitCode then you can't terminate it!     onFilePrint(_, _) :-         nothing("").
Post Reply