karnov / htmltoword

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

Change xsltMaxDepth (--maxdepth) value? - where? #50

Open Roko131 opened 8 years ago

Roko131 commented 8 years ago

Hi, I'm using Rails 3.2.12 with your Gem to create a big docx file containing the site's users with their details.

It works great with a few users, but when there are more than a few I'm getting the following error:

xsltApplyXSLTTemplate: A potential infinite template recursion was detected.
You can adjust xsltMaxDepth (--maxdepth) in order to raise the maximum number of nested template calls and variables/params (currently set to 3000).

I'm not familiar with xslt, I didn't find where I should add the maxdepth parameter- Any ideas?

Thank you.

Full error, and what I'm trying to do below:

RuntimeError: runtime error: file C:/row/Ruby21/lib/ruby/gems/2.1.0/gems/htmltoword-0.5.1/lib/htmltoword/xslt/inline_elements.xslt line 7 element copy
xsltApplyXSLTTemplate: A potential infinite template recursion was detected.
You can adjust xsltMaxDepth (--maxdepth) in order to raise the maximum number of nested template calls and variables/params (currently set to 3000).
Templates:
#0 name node()|@*
#1 name node()|@*
#2 name node()|@*
#3 name node()|@*
#4 name node()|@*
#5 name node()|@*
#6 name node()|@*
#7 name node()|@*
#8 name node()|@*
#9 name node()|@*
#10 name node()|@*
#11 name node()|@*
#12 name node()|@*
#13 name node()|@*
#14 name node()|@*
Variables:
from C:/row/Ruby21/lib/ruby/gems/2.1.0/gems/htmltoword-0.5.1/lib/htmltoword/document.rb:88:in `transform'

More details:

I'm trying to send a mail with the docx file as attachment (It does work, but not with many users):

class MyMailer < ActionMailer::Base
  default from: "noreply@mail.net"
  default to: "mail@gmail.com"

  def send_word_files(users)
    body = ''
    users.each do |user|
      user.fields.each do |field|

        body << "<h2>#{field.label_name}:</h2>"
        body << "</p>#{user.field_value(field)}</p>"
      end
      body << '<div class="-page-break"></div>'
    end
    attachments["users.docx"] = Htmltoword::Document.create("<html><head></head><body>#{body}</body></html>")

    mail(subject: "word file", body: 'enjoy')
  end

end
adamtomecek commented 7 years ago

Did you find a solution to this?

Roko131 commented 7 years ago

No, what I ended up doing was making a docx file for every 50 users- so I got like 10 docs files for 500 users...

Please let me know if you find another solution.

Or if you couldn't find one, take a look at this Gem: Caracal

adamtomecek commented 7 years ago

Well my solution is to create wrapper div for every group of 3000 nodes, which gives you enough space to overcome this limitation.

JenniferSpry commented 5 years ago

@adamtomecek Your comment just saved my day! Adding a seemingly useless div also solved this for me.