Printing Textarea Text - Full Length (Height)?

馋奶兔 提交于 2019-12-10 19:44:05

问题


I have a webform my client wants users to be able to print out. It works fine with a little styling using CSS, however, I have several textaear fields. If a user types more than the height of the textarea the type is cutoff when printed.

I have tried textarea{height:100%;} and textarea{height:auto;} in the print stylesheet but neither of those works.

Is there a way to resize the textarea field to the size of the text for the print only version? I would prefer a CSS solution if possible that I can insert into my print stylesheet. If this isn't possible javascript solution would work.

Screenshot Comparison:

Note: If I cannot affect just the print version I can considered using JS to auto-resize the textarea field as someone is typing.


回答1:


This worked for me (adapted from this JS and this jQuery):

function resizeAndPrint() {   
    var _print = window.print;
    window.print = function() {
        $('textarea').each(function() {
            $(this).height($(this).prop('scrollHeight'));
        });
        _print();
    }
    window.print();
}



回答2:


This problem exist in firefox browser.

Please open the html file in chrome browser for printing text between textarea tags. There is no need apply style and script for printing large text of textarea.

Steps to follow:

  1. open HTML file in chrome browser.
  2. Click Ctrl + P.
  3. Click on Save button ( Select PDF format ).
  4. Open PDF file ( See all text between textarea whether it is moves to second page if excess text contains)
  5. Click Print button.


来源:https://stackoverflow.com/questions/21978642/printing-textarea-text-full-length-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!