Jump to content

Recommended Posts

Posted

Excuse me.

I need to save a text file on client in a specific folder and then execute a .bat to print it.

Using

UniSession.SendFile(UniServerModule.StartPath + '\files\L24000003.eti', 'C:\ProvaLabels\ETIC.DAT');

does not work!!

I need to save a file on the client to then send it to a ZEBRA printer but there is no way to save the file !?!?!

Thanks

Posted

Hello,

Unfortunately, due to security restrictions in modern web technologies, it is not possible to directly save a file to a specific folder on a client machine from a web application. Browsers do not allow direct file system access to prevent security risks...

Posted
5 minutes ago, Stefano Biggi said:

Excuse me.

I need to save a text file on client in a specific folde.

Using

UniSession.SendFile(UniServerModule.StartPath + '\files\L24000003.eti', 'C:\ProvaLabels\ETIC.DAT');

does not work!!

I need to save a file on the client to then send it to a ZEBRA printer but there is no way to save the file !?!?!

Thanks

hi, maybe this can help you:

https://stackoverflow.com/questions/47850359/is-it-possible-to-create-txt-file-using-only-client-side-but-to-a-specific

https://dev.to/kendalmintcode/saving-text-to-a-client-side-file-using-vanilla-js-11ld

https://www.quora.com/How-do-I-save-files-directly-to-a-Windows-PC-folder-from-a-JavaScript-web-application

Posted
2 minutes ago, Stefano Biggi said:

But i'm a delphi developer and need to use UNIGUI.... 

There is something in UNIGUI?

Here is one possible potential solution.
Zebra Printer Direct Print: If the file is intended for a Zebra printer, consider using a library or tool that can directly send ZPL (Zebra Programming Language) commands to the printer. 
For instance:
Use tools like Zebra Setup Utilities to configure the printer.
Use Zebra's SDK to send files to the printer over the network.
If you're printing labels, there may also be browser-based solutions using JavaScript and Zebra's API to print directly without saving the file to the local machine...

Posted

my file is a text file with ZPL commands for print a label.

But i need to print on a client side printer that is not on a local lan.

So the first solution is to create a text file with commands and send it to the printer (with a copy or write.... is the same!)

 

 

 

 

 

Posted
9 minutes ago, Stefano Biggi said:

Thanks.

But i'm a delphi developer and need to use UNIGUI.... 

There is something in UNIGUI?

where is positioning this printer, on local network ?

Is it possible to save file to printer from server side ?

Posted
5 minutes ago, Stefano Biggi said:

But i need to print on a client side printer that is not on a local lan.

So the first solution is to create a text file with commands and send it to the printer (with a copy or write.... is the same!)

If the printer is not on a local LAN, creating a text file with ZPL commands is still a valid approach, but sending it directly to the client-side printer will require additional steps. One option is to use browser-based solutions, such as JavaScript with Zebra's Browser Print SDK, which allows direct printing to Zebra printers connected to the client machine. This avoids the need to manually save and transfer the file. Alternatively, consider using client-side scripting or utilities that handle file writing and sending commands to the printer on the client machine.

Posted
10 minutes ago, Stefano Biggi said:

my file is a text file with ZPL commands for print a label.

But i need to print on a client side printer that is not on a local lan.

So the first solution is to create a text file with commands and send it to the printer (with a copy or write.... is the same!)

 

 

 

 

 

Try to use Javascript with XMLHttpRequest request

https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
UniSession.AddJS (' const xhr = new XMLHttpRequest();'
                      + ' const method = "GET";'
                      + ' const url = "' + fURL + TRIM (cmd) + '";'   <----- you commands to printer
                      + ' xhr.open(method, url, true);'
//                    + '  xhr.withCredentials = true;' //Set Access-Control-Allow-Credentials: true header
//                    + '  xhr.timeout = 1000;' // time in milliseconds
//                    + '  xhr.setRequestHeader("Content-Type", "application/xml");'
//                    + '  xhr.setRequestHeader("Content-Type", "application/json");'
//                    + '  xhr.setRequestHeader("Access-Control-Allow-Origin", "*");'
//                    + '  xhr.setRequestHeader("Content-Type", "text/xml");'
                      + ' xhr.onreadystatechange = function() {'
                    // Get the raw header string
//                    + '    if (xhr.readyState === this.HEADERS_RECEIVED) {'
//                    + '           const headers = xhr.getAllResponseHeaders();'
                    // Convert the header string into an array
                    // of individual headers
//                    + '           const arr = headers.trim().split(/[\r\n]+/);'
//                    + '           alert ("headers:" + headers);'
//                    + '    };'
                      // In local files, status is 0 upon success in Mozilla Firefox
                      + '   if (xhr.readyState === XMLHttpRequest.DONE) {'
                      + '     const status = xhr.status;'
                      + '     if (status === 0 || (status >= 200 && status < 400)) {'
                      // The request has been completed successfully
                      + '         console.log(xhr.responseText); '
                      + '         var sRes = xhr.responseText;'
                      + '         if (sRes != "") {'
                      + '            ajaxRequest (' + myMemo.JSName    <----- get answer to Memo
                      + '                        , "FiscalAnswer", ["_value=" + "" + sRes + "","_cmd=" + "' + sCMD + '"]);'
                      + '         };' //if sRes <> ''
                      + '         document.getElementById("' + myMemo.JSName + '_id").innerHTML = xhr.responseText;'
//                      + '         alert("url:" + url + " responce:" + xhr.responseText);'
                      + '     } '
                      + '     else {'
                      // Oh no! There has been an error with the request!
                      + '         alert("error:" + xhr.responseText);'
                      + '           }'//else
                      + '   }'//if status === 0
                      + ' };'//onreadystatechange
                      + ' xhr.send(null);'
                      );

 

https://www.google.com/search?q=javascript+XMLHttpRequest+save+a+text+file+on+client+&sca_esv=360d606574466e04&ei=8dZSZ-y1D7eJxc8PlbSq0A4&ved=0ahUKEwis8orC_JKKAxW3RPEDHRWaCuoQ4dUDCA8&uact=5&oq=javascript+XMLHttpRequest+save+a+text+file+on+client+&gs_lp=Egxnd3Mtd2l6LXNlcnAiNWphdmFzY3JpcHQgWE1MSHR0cFJlcXVlc3Qgc2F2ZSBhIHRleHQgZmlsZSBvbiBjbGllbnQgSABQAFgAcAB4AZABAJgBAKABAKoBALgBA8gBAPgBAvgBAZgCAKACAJgDAJIHAKAHAA&sclient=gws-wiz-serp

 

Can I write to file using XMLHttpRequest or any other javascript method and how do I do that?

https://stackoverflow.com/questions/48096657/can-i-write-to-file-using-xmlhttprequest

Posted

You can try to use some local service (or App) and send request from Browser to .

This service (application) on client get data from browser and send it (or save it) to local directory.

This is real way !

Posted

"If you're printing labels, there may also be browser-based solutions using JavaScript and Zebra's API to print directly without saving the file to the local machine..."

Zebra has "SendfiletoPrinter" API - look in their developer portal under Data Services APIs.

Easy to use it for cloud based printing.

https://stackoverflow.com/questions/16523194/printing-from-web-application-using-zebra-technologies-printers

Posted

I realized that in practice it is not possible! 
The text file has the commands to send to the printer.

The printer is shared locally so just a using simple PRINT or COPY command it works.

But I need to have the command file available on the client!

Is not possible to send a file to download?????

 

Posted
5 minutes ago, Stefano Biggi said:

Is not possible to send a file to download?????

is possible:

CopyFile(pchar(UniMainModule.folderPath+QBiayaNama_File.AsString),pchar(UniServerModule.LocalCachePath+'\'+QBiayaNama_File.AsString),false);
pathfile:=trim( Copy(UniServerModule.LocalCachePath,AnsiPos('cache',UniServerModule.LocalCachePath),length(UniServerModule.LocalCachePath)));
UniSession.SendFile(UniServerModule.LocalCachePath+'\'+QBiayaNama_File.AsString);
 

 

Posted
3 minutes ago, Stefano Biggi said:

Excuse me.. can explain with VAR and definition ?  QBiayaNama_File ?


thank you very much

part of first shared topic 

CopyFile(pchar(UniMainModule.folderPath+FileName),pchar(UniServerModule.LocalCachePath+'\'+FileName),false);
pathfile:=trim( Copy(UniServerModule.LocalCachePath,AnsiPos('cache',UniServerModule.LocalCachePath),length(UniServerModule.LocalCachePath)));
UniSession.SendFile(UniServerModule.LocalCachePath+'\'+FileName);

Posted

My two cents...
As @sherzod  said, I add: there is no 1-fits-all solution. A printer is just I/O device and as you "can" access a printer at the client side, you could access any device attached. So, is a basic web/browser/security problem. No way. You can use an specific device with special tech like websocket, embedded http servers or any likewise solution.

Embedded http server API are on the rise across all brands. Like wise POS solutions and integrator. Basically all new Chinese printers comes with all of this with minimalist API to print directly from web. Very cheap and easy to adapt. Google it.

All other approaches will not work in all device, not  work in all browser, versions, devices and environment. Worst case is in apple OS and devices. Not counting Antivirus, security 3rd party software and TI management/rules.

That is why you have massive solutions like EPSON JS SDK, mobile to printer solution and others. But all requires installing  extension, plugins, app etc. Google tried solve this in chrome but, as always, Apple said "no way jose". As it did with PWAs. As US market has a bigger Apple presence, never will be supported in Safari.

My advice: if you´re making one solution to a client, pick up a printer that fits you printing needs, best connection option and present to your client.  Otherwise, make a print server. There a tons of solutions in this area.

All big techs has OS printer server solutions based in domains/services and works really flawless. But in this case, is always a big cia environment and their "IT crowd" has already solved it.  People print from their homeoffice directly in the mega blaster colored laser printer. And next morning, all folks got their reports at their desk. Yes, cia. still prints a lot !

tlds; This is not  uniGUI limitation. Is browser and internet issue.
 

Posted

Hi Stefano, 
you are italian?
(for tallk directly)
The solution is simple:
Another unigui project, that run on client at localhost:xxx with parameters and that manage all you want and that monitor you calls (http://localhost:6700/execwhatyouwant) with data in body. This project can talk with printers, drivers, local application, etc.
Of course this "utility app" must be installed and run on client.


 

Posted
On 12/9/2024 at 10:17 AM, Stemon63 said:

Hi Stefano, 
you are italian?
(for tallk directly)
The solution is simple:
Another unigui project, that run on client at localhost:xxx with parameters and that manage all you want and that monitor you calls (http://localhost:6700/execwhatyouwant) with data in body. This project can talk with printers, drivers, local application, etc.
Of course this "utility app" must be installed and run on client.


 

Yes, i'm italian. 

The solution is not simple! the PC that runs the project is not my PC. Is a public project! I don't have to install any other applications!

The real solution was to make the project in PHP and there were no problems whatsoever!! but I lost the project!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...