karnov / htmltoword

Ruby html to word gem
MIT License
179 stars 71 forks source link

Xml parsing error #67

Closed robingram closed 6 years ago

robingram commented 6 years ago

Hi, I'm trying to get Word generation working with v0.7.0 but the docx file generated always seems to be corrupt. I get the same error every time when trying to open the document in Word:

Xml parsing error
Location: Part: /word/document.xml, Line: 14, Column 6

I've unpacked the docx and examined the file and it seems fine to my uneducated eye. This is line 14:

<w:r xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">

I've tried opening in Word on both Mac and Windows with the same result.

I was initially trying this with an existing rails 5.1 app but when I hit this error I tried on clean installations of rails 5.1 and 4.2 with the same result. I based my controller action on the most basic examples from the docs too but still no joy:

respond_to :docx
def show
  respond_to do |format|
    format.docx do
      render docx: 'my_file.docx', content: '<html><body>some html</body></html>'
    end
  end
end

Any ideas?

robingram commented 6 years ago

Looks like this was due to invalid HTML in the documented example. I fixed it by changing the HTML in the Rails example to match that of the straight Ruby example, i.e. change:

'<html><body>some html</body></html>'

to:

'<html><head></head><body><p>Hello</p></body></html>'