html2image icon indicating copy to clipboard operation
html2image copied to clipboard

Cannot change browser after instanciating an Html2Image object

Open varnt opened this issue 2 years ago • 1 comments

i´m trying to convert html to png files, but it always return this error: Traceback (most recent call last): File "c:\Users...\CDCConverterWatchDog.py", line 8, in hti.screenshot_loaded_file(file=file) File "C:\Users...\Python\Python39\lib\site-packages\html2image\html2image.py", line 193, in screenshot_loaded_file self.browser.screenshot( AttributeError: 'str' object has no attribute 'screenshot' PS C:\Users\user>

code:---------------------------------------------------------------------------------- from html2image import Html2Image hti = Html2Image() hti.browser = 'chrome' hti.output_path = "C:/Users/ArntV" hti.size = (1080,1920) file = 'C:/CDC_template.html'

hti.screenshot_loaded_file(file=file) hti.screenshot_loaded_file(file=file,size=(1080,1920))

HTML file contents:----------------------------------------------------------------------------------

teste

Confira as nossas condições de *|MES|* de *|ANO|*

PRAZO (MESES)

TAXA%

(periocidade mensal)

TAXA%

(periocidade anual)

12

*|TAXAM12|*

*|TAXAA12|*

24

*|TAXAM24|*

*|TAXAA24|*

36

*|TAXAM36|*

*|TAXAA36|*

48

*|TAXAM48|*

*|TAXAA48|*

60

*|TAXAM60|*

*|TAXAA60|*

Vigência: até *|VIGENCIA|*


Carência: até 18 meses, de acordo com a safra do cliente


Forma de pagamento: mensal, bimestral, trimestral, quadrimestral, semestral ou anual

     </div>
     <div style="display: flex;padding-left: 10%;padding-top: 2%;padding-right: 10%;width:80%;height:20%; marign:0px;">
        <div style="padding-left: 5%;padding-right: 5%;width:70%;height:100%; marign:0px;">
           <p style="text-align: left;" ><span lang="PT-BR" style="font-size:18.0pt;font-family:&quot;Franklin Gothic Book&quot;,sans-serif;color:#ffffff;mso-ansi-language:PT-BR">
              Condições válidas para financiamentos através da linha CDC – Crédito Direto ao Consumidor. Condições válidas apenas para financiamentos com prazo de citados na tabela acima. Condições comerciais para Pessoas Físicas e Pessoas Jurídicas. Os vencimentos das parcelas serão ajustados em função dos finais de semana e/ou feriados; Para condições comerciais diferenciadas, consulte um representante comercial. Condições sujeitas a alterações em caso de flutuações de mercado e sem aviso prévio. Condições de CDC praticadas pelo Banco de Lage Landen Brasil S.A.. Condições sujeitas a aprovação de crédito pelo Banco De Lage Landen S.A.
              </span>
           </p>
        </div>
        <div style="width:20%;height:100%; marign:0px;">
          <img style="width: 100%;height: 100%;object-fit:scale-down;" src="http://www.agcofinance.com.br/portal_dll/campanhas/Comunicados/Imagens_RD_Station/CDC Template/AGCO_Finance_logo.png">
        </div>
     </div>
     <div style="display: flex;padding-left: 10%;padding-right: 10%;width:80%;height:1%; marign:0px;">
           <p style="text-align: center;" ><span lang="PT-BR" style="font-size:15.0pt;font-family:&quot;Franklin Gothic Book&quot;,sans-serif;color:#ffffff;mso-ansi-language:PT-BR">
             AGCO FINANCE é uma marca registrada e unidade de negócios do Banco De Lage Landen Brasil S.A.
              </span>
           </p>

     </div>
  </div>

varnt avatar Jul 30 '21 18:07 varnt

Hello, thanks for reporting this issue. There is indeed a problem when a browser is set after instanciating an Html2Image object. It will be fixed in a later release of the package.

For the moment, as chrome is the only browser available and is used by default, you can use the following code:

from html2image import Html2Image

hti = Html2Image()
# no need to set 'chrome' as the browser because it is the default option
hti.output_path = "C:/Users/ArntV"
hti.size = (1080,1920)
file = 'C:/CDC_template.html'

# use screenshote instead of screenshot_loaded_file
hti.screenshot(html_file=file)

Tell me if you still have any problem. Also please do not close the issue for the moment.

vgalin avatar Aug 01 '21 15:08 vgalin