Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Cannot print images in html
-
Hi,
I am a beginner in Pythonista and ios ( 2 months ) coming from a windows c# environment ( 37 years )
I am converting an existing c# application and trying to create printable html reports and forms ( not really sure what other options I have).I am printing the reports by opening the html template and using airprint code that I have found on this forum ( print_html_orientation )
So far all has been good but now I am trying to include images and not having much luck. My application path structure has all of the html files in a separate directory..
I have seen threads that suggest that the script and images be in the same directory but this hasn’t worked. I have tried to use a file url in the HTML base element and also a file url when specifying the name of the image but this does not work as well.
Am I missing something regarding how the html is interpreted prior to printing.
-
Have you tried using a data stream like BytesIO formatted as JPEG?
-
Thank you, will give this a try. I am assuming i will be using this stream in the fileurl specified for the image.
-
Do you have a GitHub repo for this code or can you provide code for a minimum example?
-
-
@gojyuan, do I understand you correctly: you want to print generated HTML pages with images, and presumably there are many, or there is some other reason not to print them manually?
Are you opening just an HTML file, or what, and how?
-
Thank you everyone for your suggestions. I finally have it working, including a form that has a background image. The styling is very touch and go - very easy to have it working one moment and not the next.
My application is a hospitality reservation / crm system ( my own business ). I was surprised at the comments regarding printing - is there another alternative that I am not aware of. Are most pythonista apps technical or gaming?
I use a lot of html for email layouts so to be able to use the same for printing is very convenient. and the app allows me to modify the template anytime.
<body> <img src="{logo}" alt="logo.jpg" width="50" height="50"> <h1>Guest Details</h1> <hr> <table> <tr> ... template = utils.template_path + '/GuestCheckIn.html' text = None with open(template,'r', encoding='utf-8') as infile: txt = infile.read() if txt is not None: txt = txt.replace('{logo}',utils.get_file_url(utils.template_path + '/' + 'logo.jpg')) txt = txt.replace('{fullname}', self.booking.customer.full_name) txt = txt.replace('{fulladdr}', self.booking.customer.full_address(' ')) ... utils.print_html_orientation(txt)