vgalin / html2image

A package acting as a wrapper around the headless mode of existing web browsers to generate images from URLs and from HTML+CSS strings or files.
MIT License
344 stars 44 forks source link

Trouble using in Aandroid platform #148

Closed MusienkoAnton closed 1 month ago

MusienkoAnton commented 3 months ago

Hello, I`m try to use html2image in Android apk and have error with rights to use '/tmp' folder. Could you add temp_dir for Android?

vgalin commented 3 months ago

Hello, are you trying to use the package or the CLI ?

If you're using the package, you can use the temp_path parameter like so :

from html2image import Html2Image
hti = Html2Image(temp_path='/your/path/')
...
MusienkoAnton commented 3 months ago

Thanks I try to use

from html2image import Html2Image
hti = Html2Image(temp_path='/cache/')
...

And get another error on Android:


Traceback (most recent call last):
  File "<string>", line 43, in <module>
  File "<frozen runpy>", line 229, in run_module
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\sa090\AppData\Local\Temp\serious_python_temp1cde2046\main.py", line 5, in <module>
  File "C:\Users\sa090\AppData\Local\Temp\serious_python_temp1cde2046\routes.py", line 5, in <module>
  File "C:\Users\sa090\AppData\Local\Temp\serious_python_temp1cde2046\newprereg_view.py", line 13, in <module>
  File "C:\Users\sa090\AppData\Local\Temp\serious_python_temp1cde2046\pypackages\html2image\html2image.py", line 106, in init
  File "C:\Users\sa090\AppData\Local\Temp\serious_python_temp1cde2046\pypackages\html2image\browsers\chrome.py", line 184, in init
  File "C:\Users\sa090\AppData\Local\Temp\serious_python_temp1cde2046\pypackages\html2image\browsers\chromium.py", line 8, in init
  File "C:\Users\sa090\AppData\Local\Temp\serious_python_temp1cde2046\pypackages\html2image\browsers\chrome.py", line 192, in executable
  File "C:\Users\sa090\AppData\Local\Temp\serious_python_temp1cde2046\pypackages\html2image\browsers\chrome.py", line 158, in _find_chrome
FileNotFoundError: Could not find a Chrome executable on this machine, please specify it yourself.

In this Android I have Chrome Browser

vgalin commented 3 months ago

I see. html2image needs a browser executable that can be used in headless mode to take screenshots. I could be mistaken, but I don't this this is possible with a classic install of a Chrome apk. It may be doable if you install the desktop (and not mobile) version of Chrome/Chromium via command line, but I don't know if it is possible.

MusienkoAnton commented 3 months ago

If this could work at Android it will be great