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 able to convert html table to PDF using PDFMake #34

Closed
kiranpandhure opened this issue Jan 14, 2020 · 5 comments
Closed

Not able to convert html table to PDF using PDFMake #34

kiranpandhure opened this issue Jan 14, 2020 · 5 comments

Comments

@kiranpandhure
Copy link

Sr.TitleDESC
? ( Description )
1Test 1Test 1 Desc
Test 1 Desc 2
2Test 2Test 2 Desc
Test 2 Desc 2
@Aymkdn
Copy link
Owner

Aymkdn commented Jan 14, 2020

It would have been nice to use a greeting, followed by a sentence, and even maybe a "thank you" at some point.

This module is to transform HTML to PDFMake language, then PDFMake will do the hard work. The purpose of this tool is not to handle all CSS properties that exist today, especially when it becomes complicated design.

When I test your code, I can see you use a lot of CSS styles, and many of them are not compatible with what PDFMake support. Something as simple as border:none should be border:0 to make it work with PDFMake.

Also you use colgroup and col that are not supported... and to make things even worse, you use plenty of unnacessary nested tags and styles.

Long story short: your code is way too much complicated to be magically handled by html-to-pdfmake. It could be greatly simplify to make it work.

@Aymkdn Aymkdn closed this as completed Jan 14, 2020
@kiranpandhure
Copy link
Author

Thank you for your response but even after removing colgroup i am getting error

image

@Aymkdn
Copy link
Owner

Aymkdn commented Jan 14, 2020

As I said, colgroup is only one of the many problems.

Long story short: your code is way too much complicated to be magically handled by html-to-pdfmake. It could be greatly simplify to make it work.

@kiranpandhure
Copy link
Author

Thank for your response as per your findings i have removed colgroup and simplified html but still it gives me error of _calwidth as earlier i have posted with screenshot.

Sr. Title DESC
?( Description )
1 Test 1 Test 1 Desc
Test 1 Desc 2
2 Test 2 Test 2 Desc
Test 2 Desc 2

@Aymkdn
Copy link
Owner

Aymkdn commented Jan 15, 2020

You HTML code is still dirty.... The correct code is:

<table width="363">
    <tbody>
        <tr height="19">
            <td height="82" width="25">Sr.</td>
            <td width="212">Title</td>
            <td width="126">DESC<br>?( Description )</td>
        </tr>
        <tr height="42">
            <td height="84" rowspan="2" width="25">1</td>
            <td rowspan="2" width="212">Test 1</td>
            <td width="126">Test 1 Desc</td>
        </tr>
        <tr height="42">
            <td height="42" width="126">Test 1 Desc 2</td>
        </tr>
        <tr height="84">
            <td height="172" rowspan="2" width="25">2</td>
            <td rowspan="2" width="212">Test 2</td>
            <td width="126">Test 2 Desc</td>
        </tr>
        <tr height="88">
            <td height="88" width="126">Test 2 Desc 2</td>
        </tr>
    </tbody>
</table>

That renders as the below:

Sr. Title DESC
?( Description )
1 Test 1 Test 1 Desc
Test 1 Desc 2
2 Test 2 Test 2 Desc
Test 2 Desc 2

And in the PDF:
Capture

Please note that PDFMake doesn't support width and height on cells but it will only apply the same width or height to all columns/rows (see section "tables" from the PDFMake Playground).

So, in your case it might be necessary to play with special properties. Example:

<!-- the important part is the `data-pdfmake` that defines the width for each column ([25,212,126]) and the height each row ([19,42,42,42,42]) ––>
<table data-pdfmake="{&quot;widths&quot;:[25,212,126],&quot;heights&quot;:[19,42,42,42,42]}">
    <tbody>
        <tr height="19">
            <td height="82" width="25">Sr.</td>
            <td width="212">Title</td>
            <td width="126">DESC<br>?( Description )</td>
        </tr>
        <tr height="42">
            <td height="84" rowspan="2" width="25">1</td>
            <td rowspan="2" width="212">Test 1</td>
            <td width="126">Test 1 Desc</td>
        </tr>
        <tr height="42">
            <td height="42" width="126">Test 1 Desc 2</td>
        </tr>
        <tr height="84">
            <td height="172" rowspan="2" width="25">2</td>
            <td rowspan="2" width="212">Test 2</td>
            <td width="126">Test 2 Desc</td>
        </tr>
        <tr height="88">
            <td height="88" width="126">Test 2 Desc 2</td>
        </tr>
    </tbody>
</table>

The result in the PDF:
Capture

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

2 participants