alihassan143 / htmltopdfwidgets

Html To Pdf
https://pub.dev/packages/htmltopdfwidgets
Apache License 2.0
12 stars 19 forks source link

Not working #36

Open i-panov opened 1 week ago

i-panov commented 1 week ago

Hello! I tried to convert HTML to PDF using your library, but the resulting document is empty.

    final widgets = await htp_widgets.HTMLToPdf().convert(html);

    final doc = htp_widgets.Document()
      ..addPage(htp_widgets.MultiPage(build: (_) => widgets));

    final rawPdf = await doc.save();

    return pdf_print.PdfPreview(
      build: (format) => rawPdf,
      allowPrinting: false,
      allowSharing: false,
      canChangeOrientation: false,
      canChangePageFormat: false,
    );

P.S. htmltopdfwidgets: ^1.0.4, Android 14

alihassan143 commented 1 week ago

@i-panov provide html sample

i-panov commented 1 week ago

@alihassan143

<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <style type="text/css">
        <!--body { background-color: #ffffff; font-size: 18pt; font-family: "Courier New"; font-style: normal; font-weight: normal; color: #000000; text-decoration: none;}hr { color: #000000}body, table /* Normal text */{ font-size: 18pt; font-family: "Courier New"; font-style: normal; font-weight: normal; color: #000000; text-decoration: none;}-->
    </style>
</head>
<body bgcolor="#FFFFFF" text="#000000" font-family="Courier New" font-style=normal
      text-decoration=none font-size: 12pt>
<table cellspacing="2" cellpadding="2" border="0" width="720">
    <tbody>
    <tr align="left">
        <td><br></td>
    </tr>
    <tr align="left">
        <td>ООО "Рога и Копыта"<br></td>
    </tr>
    <tr align="left">
        <td>123456,г.Усть-задрищенск<br></td>
    </tr>
    <tr align="left">
        <td>ул.Говна,12<br></td>
    </tr>
    <tr align="left">
        <td>КАССИР:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Иванова
            Ольга<br></td>
    </tr>
    <tr align="left">
        <td>КАССА: 68&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ВСЧ:
            00017<br></td>
    </tr>
    <tr align="left">
        <td>ДАТА: 06.09.24&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ВРЕМЯ: 15:16<br></td>
    </tr>
    <tr align="left">
        <td>СМЕНА: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;123<br>
        </td>
    </tr>
    <tr align="left">
        <td>РН ККТ: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;123456789<br></td>
    </tr>
    <tr align="left">
        <td>ЗН ККТ:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;123456789<br></td>
    </tr>
    <tr align="left">
        <td>КАССОВЫЙ ЧЕК/ПРИХОД<br></td>
    </tr>
    <tr align="left">
        <td>ФН: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;123456789<br>
        </td>
    </tr>
    <tr align="left">
        <td>ИНН:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7804064663<br>
        </td>
    </tr>
    <tr align="left">
        <td>ПОКУПАТЕЛЬ:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+7912345678<br></td>
    </tr>
    <tr align="left">
        <td>Сайт
            ФНС:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;www.nalog.ru<br>
        </td>
    </tr>
    <tr align="left">
        <td>123456789&nbsp;&nbsp;ТРАНСПОРТНЫЕ УСЛУГИ<br></td>
    </tr>
    <tr align="left">
        <td>1.000 X 1299<br></td>
    </tr>
    <tr align="left">
        <td>=1299.00_A<br></td>
    </tr>
    <tr align="left">
        <td>012345678&nbsp;кресло Салют 660x600<br></td>
    </tr>
    <tr align="left">
        <td>1.000 X 924<br></td>
    </tr>
    <tr align="left">
        <td>=924.00_A<br></td>
    </tr>
    <tr align="left">
        <td>ИТОГО&nbsp;&nbsp;&nbsp;=2223.00<br></td>
    </tr>
    <tr align="left">
        <td>
            ЭЛЕКТРОННЫМИ&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=2223.00<br>
        </td>
    </tr>
    <tr align="left">
        <td>ПОЛУЧЕНО:<br></td>
    </tr>
    <tr align="left">
        <td> БАНКОВСКАЯ КАРТА&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=2223.00<br></td>
    </tr>
    <tr align="left">
        <td>А:СУММА НДС 20%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=370.50<br>
        </td>
    </tr>
    <tr align="left">
        <td>СНО:ОСН&nbsp;&nbsp;&nbsp;ФД:24420 ФП:12345678<br></td>
    </tr>
    </tbody>
</table>
</body>
</html>
alihassan143 commented 1 week ago

just remove the br tag from table than it will work

i-panov commented 6 days ago

@alihassan143

  1. HTML comes to the application from the server. Of course, I can try to automatically clean these tags in it, but it seems that this is not the best solution. On the other hand, I am not sure that I will be able to negotiate with the server so that they change the HTML on their side. Why can't your library just handle these tags correctly?

  2. I tried to remove the br tags. Now the document is not generated empty, but for some reason there are green fields around the edges. Where do they come from? There are none in HTML. Your library obviously adds them.

  3. Cyrillic characters are not processed correctly. The console writes errors on them. Judging by these errors, your library is trying to use the Helvetica font, which does not support Unicode. But the Courier New font is specified in HTML! Why is it not used automatically? I tried to specify the fontFallback parameter in the convert method, but it didn't help.

Helvetica has no Unicode support see https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management
Unable to find a font to draw "О" (U+41e) try to provide a TextStyle.fontFallback
alihassan143 commented 6 days ago

@i-panov there are some restrictions in the pdf library
but things can be improved with time I will try to create custom code embedder that allow developer to embed multiple tags handling code so they can customize their HTML code output but it will take time

i-panov commented 6 days ago

@alihassan143 I see, thanks! But what about the green fields and the font?