I recently got a new printer (specifically a HP Photosmart C6380 if that helps) that allows me to send text to port 9100 to print. Telnetting into it and typing text to print works fine, but I'm wondering if I could make a webpage using HTML and Javascript that can send text directly to it.
I'm currently using the code from the article Cross Site Printing (pdf), but the downside is that when it prints out it shows the entire POST request and not just the text.
So my question for you is am I able to send just the content of the POST request or strip the unneeded characters using only HTML and Javascript?
Note: The reason why it's limited to HTML and Javascript is because I'm hoping that I can use this on an iPhone or iPod Touch.
Edit: It appears that there's no way to get rid of the HTTP headers, so now my question is can I craft a custom POST request that will minimize on what is sent in the header? For example, can I not send the user agent since the printer doesn't care what the user agent is?
I recently got a new printer (specifically a HP Photosmart C6380 if that helps) that allows me to send text to port 9100 to print. Telnetting into it and typing text to print works fine, but I'm wondering if I could make a webpage using HTML and Javascript that can send text directly to it.
I'm currently using the code from the article Cross Site Printing (pdf), but the downside is that when it prints out it shows the entire POST request and not just the text.
So my question for you is am I able to send just the content of the POST request or strip the unneeded characters using only HTML and Javascript?
Note: The reason why it's limited to HTML and Javascript is because I'm hoping that I can use this on an iPhone or iPod Touch.
Edit: It appears that there's no way to get rid of the HTTP headers, so now my question is can I craft a custom POST request that will minimize on what is sent in the header? For example, can I not send the user agent since the printer doesn't care what the user agent is?
Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Jan 22, 2009 at 18:28 SeanSean 5,3446 gold badges30 silver badges27 bronze badges 5- Why are you opposed to creating a server-side script to handle your request and forward the data to the printer? It's like a couple lines of perl... – rmeador Commented Jan 22, 2009 at 19:04
- I want to avoid setting up a server and having a middleman forward the data. This is mainly for my personal use when I'm connected to my home network. I imagine a local webpage with a textarea that I can type in and press submit and it will print. – Sean Commented Jan 22, 2009 at 19:24
- Also, I envision downloading this to my iPod Touch using an app like Air Sharing so that I can type up some text and print it, since it lacks that capability. – Sean Commented Jan 22, 2009 at 19:25
- But if it's a solution for your home network, what's stopping you from setting up an only locally accessible webserver? Or even writing a basic one yourself - just drop the header (everything before \r\n\r\n), relay the rest to your printer port and send a '204 No Content' to the browser? – Christoph Commented Jan 22, 2009 at 20:55
- Nothing is stopping me from setting up a server, I just was hoping that I could make something entirely self contained in just HTML and Javascript. – Sean Commented Jan 22, 2009 at 21:47
2 Answers
Reset to default 4No, there's no way to get rid of the HTTP headers in client-side JavaScript. For that, you need to set up a server-side script which will then make the actual connection to the printer port.
Edit: The server-side script won't send a HTTP request to your printer: It should open a new socket and thus can fully controle what gets sent!
You can HTTP-Request from within JS, so you always have an HTTP-Header, regardless of the port to which you are sending. So the answer is: no.