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.


    Save UI data to pdf/hard copy

    Pythonista
    2
    3
    1564
    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.
    • rb
      rb last edited by rb

      I have made a complex UI composed of many parts tables images etc- one of which containing the bulk of information being a scroll view ie bigger than the screen.
      If I wanted a method to save the contents of the scroll view UI as it appears on screen and/or print it to say PDF etc what would be best way of approaching this?
      Just looking for some pointers.
      Thanks
      Rich

      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @rb last edited by

        @rb not sure I correctly understood. If not, sorry and forget this

        import ui
        from   PIL import Image
        import io
        
        def ui2pil(ui_img):
        	return Image.open(io.BytesIO(ui_img.to_png()))
        
        sv = ui.ScrollView()
        sv.frame = (0,0,400,400)
        sv.content_size = (1200,1200)
        iv = ui.ImageView()
        iv.frame = (0,0,1200,1200)
        iv.image = ui.Image.named('test:Peppers')
        sv.add_subview(iv)
        sv.present('sheet')
        
        with ui.ImageContext(sv.width,sv.height) as ctx:
        	sv.draw_snapshot()
        	ui_image = ctx.get_image()
        pil_image = ui2pil(ui_image)
        if pil_image.mode == "RGBA":
        	pil_image = pil_image.convert("RGB")
        pil_image.save('x.pdf',"PDF",resolution=100.0)
        
        1 Reply Last reply Reply Quote 0
        • rb
          rb last edited by

          Thankyou I think you did ! I’ll give it a go :)

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors