Область текста в рельсах wicked_pdf не изменяет размер автоматически

#ruby-on-rails #wkhtmltopdf

#ruby-on-rails #wkhtmltopdf

Вопрос:

Я создаю PDF-файл, используя wicked_pdf в Rail. В html у меня есть 10 строк для текста, но когда я показываю его в формате pdf, это всего 2 строки. Причина появления строк в данных динамична, поэтому я хочу автоматически изменить размер области текста pdf.

Я пытаюсь использовать javascript, но ничего не происходит. Это мой источник: application.js:

 import Rails from "@rails/ujs" import Turbolinks from "turbolinks" import * as ActiveStorage from "@rails/activestorage" import "channels" import 'jquery' import 'jquery-validation' import './localization/messages' import 'bootstrap' import '@popperjs/core' import './user/sign_up' import './user/show_list' import './user/edit' import './user/change_password' import * as message from "./localization/messages";  Rails.start() Turbolinks.start() ActiveStorage.start()  $(document).on('turbolinks:load', function(){  let current_language = $('#current-language').val();  current_language = current_language || 'jp'  $.extend($.validator.messages, eval(message.localize[current_language]));   $('textarea').each(function () {  this.setAttribute('style', 'height:'   (this.scrollHeight)   'px;overflow-y:hidden;');  }).on('input', function () {  this.style.height = 'auto';  this.style.height = (this.scrollHeight)   'px';  }); })  

Контроллер

 def generate_pdf  id = params[:id]  if validate_user(id.to_i)  log_out  redirect_to root_path  return  end   @user = User.find_by(id: id)  @profile = Profile.find_by(id_user: id)   @hash_tech_levels = Hash.new  TechLevel.where('id_user = '   id).find_each do |tech_level|  @hash_tech_levels[tech_level.id_tech] = tech_level  end    respond_to do |format|  format.html  format.pdf do  render pdf: "#{@user.name}",  page_size: 'A4',  template: "users/profile_pdf.html.erb",  layout: "pdf.html",  orientation: "Landscape",  lowquality: true,  zoom: 1,  dpi: 75,  encoding: "UTF-8",  javascript_delay: 200,  disable_javascript: false,  enable_plugins: true,  show_as_html: params.key?('debug')  end  end  end  

Pdf layout:

 lt;!DOCTYPE htmlgt; lt;htmlgt; lt;headgt;  lt;titlegt;PDFs - lt;%= @user.name %gt; lt;/titlegt;  lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /gt;  lt;%= wicked_pdf_stylesheet_link_tag "sessions" %gt;  lt;%= wicked_pdf_stylesheet_link_tag "application" %gt;  lt;%= wicked_pdf_javascript_include_tag "application" %gt; lt;/headgt; lt;bodygt;  lt;%= yield %gt; lt;/bodygt; lt;/htmlgt;  

users/profile_pdf.html.erb

 ... lt;div class="form-group mb-3 mx-auto w-50"gt;  lt;%= f.label :description, t('new_user_form.description'), class: "form-label" %gt;  lt;%= f.text_area :description , class: "form-control", :disabled =gt; true, :readonly =gt; true %gt;  lt;/divgt; ...  

for html, I see It auto increases row when I typing the text to textarea.enter image description here

in PDF: enter image description here