简体   繁体   English

使用 Javascript 将页面导出为 PDF

[英]Export Page to PDF using Javascript

I'm trying to export a web page containing many tables as a .pdf file.我正在尝试将包含许多表格的网页导出为.pdf文件。 I figured out triggering the default print function using javascript might do the trick.我发现使用 javascript 触发默认打印功能可能会奏效。

the site is quite long and depeding on the loaded data might be shorter or even longer.该站点很长,根据加载的数据可能会更短甚至更长。

The site looks something like this ( example , the pink like indicates the printable area when pressing Strg+P , result here .)该站点看起来像这样(例如,按Strg+P时,粉红色表示可打印区域,结果在此处。)

The main issue here is, that the text gets kind of squished together (?) and get's cut off.这里的主要问题是,文本被挤压在一起(?)并被切断。

在此处输入图片说明

here's the code I'm trying to work on:这是我正在尝试处理的代码:

javascript itself is triggering the default print function javascript 本身正在触发默认的打印功能

<script>
  $("#employeePrintPage").click(function () {
    window.print();
  });
</script>

css is hiding everything I don't need (eg. logo and navigation bar) as well as trying to get page-break to work. css 隐藏了我不需要的所有内容(例如徽标和导航栏),并试图让分页符起作用。

 @media print {
    #loadcontainer {
        background-color: white;
        height: 100%;
        width: 100%;
        position: fixed;
        top: 0;
        left: 0;
        margin: 0;
        padding: 15px;
        font-size: 14px;
        line-height: 18px;
    }

    .navbar, nav, .navbar-menu-wrapper, .navbar-nav-right, .hideprint { display: none !important; }


    table { page-break-after:always !important }
    tr    { page-break-inside:avoid !important; page-break-after:auto !important }
    td    { page-break-inside:avoid !important; page-break-after:auto !important }
    thead { display:table-header-group !important }
    tfoot { display:table-footer-group !important }

  }

i tried to use a couple of jquery plugins but none of them worked with input fields.我尝试使用几个 jquery 插件,但没有一个与输入字段一起使用。

I am unable to open a new window because input fields don't adopt values.我无法打开新窗口,因为输入字段不采用值。

你可能想检查 html2pdf js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM