Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working #36

Open
i-panov opened this issue Sep 18, 2024 · 10 comments
Open

Not working #36

i-panov opened this issue Sep 18, 2024 · 10 comments

Comments

@i-panov
Copy link

i-panov commented Sep 18, 2024

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
Copy link
Owner

@i-panov provide html sample

@i-panov
Copy link
Author

i-panov commented Sep 19, 2024

@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
Copy link
Owner

just remove the br tag from table than it will work

@i-panov
Copy link
Author

i-panov commented Sep 20, 2024

@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
Copy link
Owner

@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
Copy link
Author

i-panov commented Sep 20, 2024

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

@i-panov
Copy link
Author

i-panov commented Sep 27, 2024

@alihassan143 Did you have any ideas?

@alihassan143
Copy link
Owner

@i-panov
you can remove them buy adding styles in Table class

@alihassan143
Copy link
Owner

you can also get html styles from table and add them in HTML class accordingly

@auliaridhov
Copy link

auliaridhov commented Oct 1, 2024

Failed assertion: line 452 pos 14: 'false': Unknown node type: "html figure"

Is the tag above not supported yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants