Save UI data to pdf/hard copy
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.
@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)
Thankyou I think you did ! I’ll give it a go :)