Python Forum
Requirements for html5print module
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Requirements for html5print module
#1
In my quest to create QR Code based labels with text I have gotten to the point now where I can display the intended label in a web browser.

[Image: 2020-03-11-5-00-31.png]

Don't let the left and right tire designations confuse the issue. The label is rendering what I want it too on in html.

I would have preferred to render to a label printer and bypass the displaying of the image to the screen but at this point the cleanest way for me to format these labels in the manner I desire is to pop the QR Code into some html code and pull it up in a browser.

My next step I was trying to find a way to take the small image of the label from the browser and send that composite image of both text and graphics to the printer... enter html5print! (or so I thought)

The problem is that I wrestled for about 4 hours yesterday, fulfilling all known (and undocumented) requirements to html5print, but the module doesn't build properly. Below is my last output from running: python setup.py install.

Error:
copying html5print.egg-info\SOURCES.txt -> build\bdist.win32\egg\EGG-INFO copying html5print.egg-info\dependency_links.txt -> build\bdist.win32\egg\EGG-INFO copying html5print.egg-info\requires.txt -> build\bdist.win32\egg\EGG-INFO copying html5print.egg-info\top_level.txt -> build\bdist.win32\egg\EGG-INFO zip_safe flag not set; analyzing archive contents... creating 'dist\html5print-0.1.2-py3.6.egg' and adding 'build\bdist.win32\egg' to it removing 'build\bdist.win32\egg' (and everything under it) Processing html5print-0.1.2-py3.6.egg Removing c:\python\lib\site-packages\html5print-0.1.2-py3.6.egg Copying html5print-0.1.2-py3.6.egg to c:\python\lib\site-packages html5print 0.1.2 is already the active version in easy-install.pth Installing html5-print script to C:\Python\Scripts Installed c:\python\lib\site-packages\html5print-0.1.2-py3.6.egg Processing dependencies for html5print==0.1.2 Searching for ply==3.4 Reading https://pypi.org/simple/ply/ Download error on https://pypi.org/simple/ply/: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond -- Some packages may not be found! Couldn't retrieve index page for 'ply' Scanning index of all packages (this may take a while) Reading https://pypi.org/simple/ Download error on https://pypi.org/simple/: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond -- Some packages may not be found! No local packages or working download links found for ply==3.4 error: Could not find suitable distribution for Requirement.parse('ply==3.4')
This appears to me to be insisting on phy == 3.4. I have installed 3.11 and 3.9 which I thought would cover me. but it doesn't. the install finishes without completing either the command line syntax or the python module.

My best guess is that this is the last piece of the puzzle for getting html5print up and going. At that point I think i will be able to pragmatically direct the output to the printer.

Your thoughts?
Through a cloudy window,
Kip...

“Progress means getting nearer to the place you want to be. And if you have taken a wrong turn, then to go forward does not get you any nearer.
If you are on the wrong road, progress means doing an about-turn and walking back to the right road; and in that case the man who turns back soonest is the most progressive man.” ― C.S. Lewis
Reply
#2
Well since my version of ply was greater than 3.4 I modified the requirements.txt file with the following change (click hide/show):
Then added this to the list Language list in setup.py under the 3.4 version of python(click hide/show):
I uninstalled the prior attempt and then installed html5print with 'python setup.py install'. This ran without error.

The outcome of this is that I haven't been able to do the command line version of html5-print nor have I been successful with any of the code examples using the IDE. The only reference to html5print in the /python/scripts folder is a file named the same that has no extension on it. The file in question has the following 4 lines:
#!C:\Python\python.exe
# EASY-INSTALL-SCRIPT: 'html5print==0.1.2','html5-print'
__requires__ = 'html5print==0.1.2'
__import__('pkg_resources').run_script('html5print==0.1.2', 'html5-print')
Each time I attempt to invoke the module in python I get this error:
Error:
cmd /C "set "PYTHONIOENCODING=UTF-8" && set "PYTHONUNBUFFERED=1" && C:\Python\python.exe c:\Users\cartken\.vscode\extensions\ms-python.python-2020.2.64397\pythonFiles\ptvsd_launcher.py --default --client --host localhost --port 63492 c:\Users\cartken\Downloads\py\blabel\htmlprinttest.py " Traceback (most recent call last): File "c:\Users\cartken\.vscode\extensions\ms-python.python-2020.2.64397\pythonFiles\ptvsd_launcher.py", line 48, in <module> main(ptvsdArgs) File "c:\Users\cartken\.vscode\extensions\ms-python.python-2020.2.64397\pythonFiles\lib\python\old_ptvsd\ptvsd\__main__.py", line 432, in main run() File "c:\Users\cartken\.vscode\extensions\ms-python.python-2020.2.64397\pythonFiles\lib\python\old_ptvsd\ptvsd\__main__.py", line 316, in run_file runpy.run_path(target, run_name='__main__') File "C:\Python\lib\runpy.py", line 261, in run_path code, fname = _get_code_from_file(run_name, path_name) File "C:\Python\lib\runpy.py", line 236, in _get_code_from_file code = compile(f.read(), fname, 'exec') File "c:\Users\cartken\Downloads\py\blabel\htmlprinttest.py", line 8 @media (-webkit-min-device-pixel-ratio:0) { ^ SyntaxError: invalid syntax
The example code I am using that generated this is as follows:
from html5print import CSSBeautifier
css = '''@media (-webkit-min-device-pixel-ratio:0) {
    h2.collapse { margin: -22px 0 22px 18px;
    }
    ::i-block-chrome, h2.collapse { margin: 0 0 22px 0; } }
    '''
print(CSSBeautifier.beautify(css, 4))
@media (-webkit-min-device-pixel-ratio:0) {
    h2.collapse {
        margin              : -22px 0 22px 18px;
    }
    ::i-block-chrome, h2.collapse {
        margin              : 0 0 22px 0;
    }
}
Now, I'm not sure if this module is just not compatible with Python 3.6 (only tested by creator to 3.4). Or if I'm doing something wrong in testing.



While looking for answers to this I ran across something that I thought might be a more elegant solution using pdfkit. So, I loaded up pdfkit v0.6.1 and did this test code:
import os 
import pdfkit

pdfkit.from_file("C:\Users\cartken\Downloads\py\blabel\pngtest.html", "out.pdf")
os.startfile("out.pdf", "print")
Which gave me the unicode error below:
Error:
File "c:\Users\cartken\Downloads\py\blabel\pdfkitprint.py", line 4 pdfkit.from_file("C:\Users\cartken\Downloads\py\blabel\pngtest.html", "out.pdf") ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
Any input that may be helpful for me resolving either issue would be greatly appreciated.

I'm working on Windows 10 with Python 3.6 32bit

(Mar-11-2020, 03:42 PM)KipCarter Wrote: While looking for answers to this I ran across something that I thought might be a more elegant solution using pdfkit. So, I loaded up pdfkit v0.6.1 and did this test code:
import os 
import pdfkit

pdfkit.from_file("C:\Users\cartken\Downloads\py\blabel\pngtest.html", "out.pdf")
os.startfile("out.pdf", "print")
Which gave me the unicode error below:
Error:
File "c:\Users\cartken\Downloads\py\blabel\pdfkitprint.py", line 4 pdfkit.from_file("C:\Users\cartken\Downloads\py\blabel\pngtest.html", "out.pdf") ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
Any input that may be helpful for me resolving either issue would be greatly appreciated.

I'm working on Windows 10 with Python 3.6 32-bit

I'm moving the reference above to a thread by itself. I had formatting errors causing the unicode errors. Once corrected another issue popped up, so it really belongs by itself.
Through a cloudy window,
Kip...

“Progress means getting nearer to the place you want to be. And if you have taken a wrong turn, then to go forward does not get you any nearer.
If you are on the wrong road, progress means doing an about-turn and walking back to the right road; and in that case the man who turns back soonest is the most progressive man.” ― C.S. Lewis
Reply
#3
Not sure if you resolved it, but make "C:\Users\cartken\Downloads\py\blabel\pngtest.html" a raw string:
r"C:\Users\cartken\Downloads\py\blabel\pngtest.html". Or use forward slash. \U is escape sequence
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
I think you got confused bye the name html5print.
It has nothing to with output html to a printer.
html5print reformat source of a web page code,so it dos not print or change anything that has been written only make eg html and css look nicer.

From your description i think you should look for a more web based solution.
Then can eg call pdfkit on back-end with a button.
So as this looked interesting i did write a test in Flask
I can post code so can look at it and see if it may be useful.
Folder/file setup:
to_print\
  |-- app.py
  |-- qr.html
  templates\
    |-- index.html
  static\
    |-- style.css  
app.py:
from flask import Flask, render_template, jsonify, request, flash
import pdfkit
import os
 
app = Flask(__name__)
app.secret_key = "super secret key"

@app.route('/')
def index():
   return render_template("index.html")
 
@app.route('/to_print/')
def to_print():
   options = {
         'dpi': 400,
         'page-size': 'A6',
         'margin-top': '0.25in',
         'margin-right': '0.25in',
         'margin-bottom': '0.25in',
         'margin-left': '0.25in',
         'encoding': "UTF-8",
         'custom-header' : [
            ('Accept-Encoding', 'gzip')
         ],
         'no-outline': None,
   }
   pdfkit.from_file('qr.html', 'out.pdf', options=options)
   #pdfkit.from_url('https://python-forum.io/index.php', 'out_forum.pdf')    
   os.startfile("out.pdf", "print")
   return '', 204

if __name__ == '__main__':
   app.run(debug=True)
index.html:
style.css:
In folder with app.py from command line run python app.py
In browser go to http://127.0.0.1:5000/.

Then it should look like this,when push button will send out.pdf to printer.
[Image: AYblKe.png]
Reply
#5
snippsat,
You are correct... I totally missed the purpose of html5print based on what you are telling me.

So it is on to flask I guess. I'm running out of clock for today, but will jump into it first thing tomorrow testing and understanding your example code.

This is just a proof of concept write up. When I've accomplished this I intend to link in a spreadsheet with data elements to be injected into a loop to process all rows and make adjustments to the layout (visibility and invisibility) based on having data present.

[Image: 2020-03-11-5-00-31.png]

This image was produced by screen capture of my web browser (chrome) I used html to mock up the way I wanted it laid out and now am trying to get it on the label stock. The production number and Q part number may not be present for a given label so I want to remove the data element and the heading for it.

I'm making progress, slowly. This is only my third python project so I'm having a big learning curve.

Do you think it's time to close this thread, since i'm departing the idea of using html5print?

Thinking if I have any issue with this new direction it should appear in a different thread.

Appreciate it.

(Mar-11-2020, 04:29 PM)buran Wrote: Not sure if you resolved it

Yep! I resolved that issue! I probably should have made a note of it here in the thread but didn't think of it at the time.

Thanks!
Through a cloudy window,
Kip...

“Progress means getting nearer to the place you want to be. And if you have taken a wrong turn, then to go forward does not get you any nearer.
If you are on the wrong road, progress means doing an about-turn and walking back to the right road; and in that case the man who turns back soonest is the most progressive man.” ― C.S. Lewis
Reply
#6
(Mar-12-2020, 04:29 PM)KipCarter Wrote: Do you think it's time to close this thread, since i'm departing the idea of using html5print?

Thinking if I have any issue with this new direction it should appear in a different thread.
We do not close Thread(only if there is issue that make it forced).

Do what you feel fit the best,continue here if question is related to what discussed here.
If mostly new stuff make a new Thread,can also like to this Thread in the new Thread,
if eg there is question about the Flask solution i posted.
Reply
#7
I have danced around this with several different modules and I just haven't been able to get to where I think I should be able to go.

I have a process to produce a label formatted in the manner I wish on html page. What I want to do now is rather than load the page in a browser to print the document directly from the html to a label printer. I'm coming up dry on this so I wanted to run it by everyone to see if anyone is aware of a module that would help me accomplish this.

I'm including the html that I'm using to render the label, but it is pretty straight forward. Since we don't have an 'insert HTML' option, I will insert it as output (forgive me please)...

Output:
<html> <head> </head> <body> <span class='label'> <table style="float: left"> <tr> <td><img src="famous-joke.png"></td> <tr> </table> <table style="float: left"> <tr> <td style = "font-variant:small-caps; font-size:small; text-align:right;">prod #: </td> <td style = "font-size:large; text-align:left;">64312345<br></td> </tr> <tr> <td style = "font-variant:small-caps; font-size:small;text-align:right;">q/pt #: </td> <td style = "font-size:large; text-align:left;">Q-FRONT LEFT TIRE<br></td> </tr> <tr> <td style = "font-variant:small-caps; font-size:small; text-align:right;">desc: </td> <td style = "font-size:large; text-align:left;">Tire front left</td> </tr> </table> </span> </body> </html>
Through a cloudy window,
Kip...

“Progress means getting nearer to the place you want to be. And if you have taken a wrong turn, then to go forward does not get you any nearer.
If you are on the wrong road, progress means doing an about-turn and walking back to the right road; and in that case the man who turns back soonest is the most progressive man.” ― C.S. Lewis
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with code / audio is playing randomly, not matching csv requirements Daniel_kcr 2 579 Sep-07-2023, 05:09 PM
Last Post: deanhystad
  when package built, requirements not installed sabuzaki 1 703 Apr-07-2023, 09:01 AM
Last Post: sabuzaki
  What to do when the requirements.txt file does not work Led_Zeppelin 2 6,170 Nov-04-2021, 06:51 PM
Last Post: snippsat
  Examples of Customer requirements ComputerAstronaut 1 1,807 Dec-08-2020, 03:22 AM
Last Post: Larz60+
  requirements file tdwinfre 7 2,668 Nov-06-2020, 06:01 AM
Last Post: tdwinfre
  How to allow user input only if certain requirements are met vininhosts 3 2,288 May-28-2020, 06:15 PM
Last Post: micseydel
  google-auth requirements.txt strange behavior randalpinto 3 3,669 Dec-21-2018, 02:03 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020