omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    4
    7
    2295
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • gojyuan
      gojyuan last edited by

      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.

      mikael 1 Reply Last reply Reply Quote 0
      • stephen
        stephen last edited by

        Have you tried using a data stream like BytesIO formatted as JPEG?

        1 Reply Last reply Reply Quote 0
        • gojyuan
          gojyuan last edited by

          Thank you, will give this a try. I am assuming i will be using this stream in the fileurl specified for the image.

          stephen 1 Reply Last reply Reply Quote 0
          • ccc
            ccc last edited by

            Do you have a GitHub repo for this code or can you provide code for a minimum example?

            1 Reply Last reply Reply Quote 1
            • stephen
              stephen @gojyuan last edited by

              @gojyuan

              If said image is already saved to a file you can open it from its file url as theio.BytesIO object. this object should be able to be transfered through the network.

              take a look at this post from stack here

              seems like it may help you also

              1 Reply Last reply Reply Quote 0
              • mikael
                mikael @gojyuan last edited by

                @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?

                1 Reply Last reply Reply Quote 0
                • gojyuan
                  gojyuan last edited by

                  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)
                  
                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Powered by NodeBB Forums | Contributors