html-to-docx icon indicating copy to clipboard operation
html-to-docx copied to clipboard

width % causes parser error

Open BeanoKing opened this issue 2 years ago • 9 comments

I have a td tag that has a width attribute of 50% which creates this parsing error: InvalidCharacterError: The string contains invalid characters. Invalid XML name: @w

If I remove the % the parsing engine works fine. The exact markup I have that is causing the issue is:

Is this expected behavior and if so is there a workaround?

BeanoKing avatar Mar 26 '23 18:03 BeanoKing

i'm having the same problem. did you find out how to address this?

mgiraldo avatar Mar 29 '23 18:03 mgiraldo

Keeping an eye on this- I contributed some of the code to handle the widths and percents is not something I was thinking about calculating since its relative to the page size. But if you know the page size + margins to draw a box, it would adding a function to convert percents into EMUs (I believe) https://stackoverflow.com/questions/20194403/openxml-distance-size-units

nicolasiscoding avatar Mar 30 '23 04:03 nicolasiscoding

For my scenario it turned out I didn't need the % widths, but since it is valid CSS for a td it would be nice if the parser didn't error. I was fighting with it for a few hours trying to narrow down the issue and finally realized it was the % width causing it to crash.

BeanoKing avatar Mar 30 '23 12:03 BeanoKing

Facing the same, is there any solution to this?. I removed all the occurances of Width:100% or Width:50% still getting the same error.

abhinovpankaj avatar Aug 19 '23 08:08 abhinovpankaj

Try removing the spaces between the style fields. Let us know if it works for you

CarlaMck77 avatar Sep 06 '23 03:09 CarlaMck77

Same issue here @BeanoKing , did you find a solution?

maximesahagian avatar Jan 05 '24 14:01 maximesahagian

I didn't. Ended up moving to a paid solution instead from Apose

BeanoKing avatar Jan 06 '24 00:01 BeanoKing

@BeanoKing, @mgiraldo, @nicolasiscoding, @abhinovpankaj, @maximesahagian: I opened a PR to fix this at https://github.com/privateOmega/html-to-docx/pull/256

ad-si avatar Jan 21 '25 20:01 ad-si

^^ +1 on this

sanskar-19 avatar Apr 28 '25 11:04 sanskar-19