html - pdfkit 生成小比例的 pdf

标签 html django wkhtmltopdf pdfkit

我正在使用 pdfkit 以从 html 字符串生成 pdf,由我的 Django View 呈现。

由于某种原因,输出的 pdf 很小。 我的 pdfkit 选项字典是 -

options = {
            'quiet': '',
            'page-size': 'A4',
            'margin-top': '0.75in',
            'margin-right': '0.75in',
            'margin-bottom': '0.75in',
            'margin-left': '0.75in',
            'disable-smart-shrinking': ''
        }

输出文件是here

HTML代码是-

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="pdfkit-orientation" content="Portrait"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Dribble</title>

    <!-- Bootstrap -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
    <!-- Google Font -->
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,700,800" rel="stylesheet">
    <!-- Custom Font -->
    <style>
        body {
            font-family: 'Open Sans', sans-serif;

        }

        p, a {
            color: #002f54;
        }

        .nav {
            background: #002f54;
            color: #FFFFFF;
            border-radius: 5px;
        }

        .ico {
            padding-right: 5px;
            top: 3px;
        }

        .nav > li p {
            text-align: center;
            font-size: 36px;
            font-weight: 800;
        }

        .right-align {
            float: right;
        }

        .pad-mar {
            font-size: 18px;
            padding-top: 10px;
            padding-bottom: 10px;
            margin-left: 30px !important;
            margin-right: 30px;
        }

        .pad-mar-middle {
            font-size: 18px;
            padding-top: 78px;
            padding-bottom: 25px;
            margin-left: 30px !important;
            margin-right: 30px;
        }

        .pad-mar-bottom {
            font-size: 18px;
            padding-top: 10px;
            padding-bottom: 90px;
            margin-left: 30px !important;
            margin-right: 30px;
        }

        .pad-mar-footer {
            padding-top: 20px;
            margin-left: 30px !important;
            margin-right: 30px;
        }

        .bor-bottom {
            border-bottom: 2px solid #ccc;
        }

        .no-pad {
            padding-left: 0;
        }

        .section {
            margin-top: 20px;
            margin-bottom: 20px;
        }

        .bold {
            font-weight: 700;
            color: #002f54;
        }

        .small {
            font-size: 14px;
        }

        .bolder {
            color: #002f54;
            font-weight: 800;
            font-size: 22px;
        }

        .normal {
            color: #002f54;
            font-weight: 700;
        }

        .smaller {
            font-size: 14px;
            font-weight: 700;
        }

        h3 .bold {
            margin-top: 0;
        }

        .neg-mar {
            margin-top: -25px;
        }

        .cus-img {
            max-width: 85px;
            margin-bottom: 10px;
        }

        .nav-stacked.mob > li {
            font-size: 16px;
            margin-left: 0px !important;
            margin-right: 0px;
            margin-bottom: 10px;
            padding-top: 5px;
            border: 1px solid #EB6C6D;
            border-radius: 5px;
            font-weight: 300;
            text-align: center;
            color: #EB6C6D;
        }

        .nav-stacked.mob > li p {
            color: #002f54;
        }

        .nav.mob {
            background: #FFFFFF;
        }

        .pad-mar-bottom.mob {
            margin-left: 0px !important;
            padding-bottom: 10px;
        }

        .pad-mar-footer.mob {
            margin-left: 0px !important;
            text-align: center;
            padding-top: 10px;
        }

        .l-mar {
            margin-left: 40px;
        }

        .titl {
            color: #EB6C6D;
            font-size: 16px;
        }

        .bot-mar {
            margin-bottom: 20px;
        }

        .container {
            max-width: 575px;
        }
    </style>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<section class="section">
    <div class="container">

        <div class="row bor-bottom bot-mar">
            <div class="col-xs-6 ">
                <img src="https://api.figo.me/assets/images/accounts/north_channel_bank_144.png"
                     class="img-responsive cus-img"/>
                <p> Commerzbank Service-BZ</p>
                <p>First line</p>
            </div>
            <div class="col-xs-6">
                <div class="right-align neg-mar">
                    <h3 class="bold">First line</h3>
                    <p class="bold">First line</p>
                    <p class="bold">First line</p>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="">
                <ul class="nav nav-stacked mob">
                    <li><span class="glyphicon glyphicon glyphicon-user ico"></span>From<p>Rewe GmbH</p></li>
                    <li><span class="glyphicon glyphicon glyphicon-credit-card ico"></span>Amount<p>$ 32,10 USD</p></li>
                    <li><span class="glyphicon glyphicon glyphicon-calendar ico"></span>Payment Date<p>Nov 5, 2017</p>
                    </li>
                </ul>
            </div>
        </div>

        <div class="row pad-mar-bottom mob bor-bottom">
            <p class="titl"><span class="glyphicon glyphicon-tag ico"></span>Payment Reference</p>
            <div class="l-mar">
                <p class="normal">Hello Ennio,</p>
                <p class="normal">You sent a payment of <span class="bolder">$20.00 USD</span> to Dribble. (<a
                        href="mailto:paypal@dribble.com">paypal@dribble.com</a>)</p>
                <div class="no-pad">
                    <p class="smaller">It may take a few moments for this transaction to appear in your account.</p>
                </div>
            </div>
        </div>
        <footer>
            <div class="row pad-mar-footer mob">
                <a class="smaller" href="#">This document was automatically generated by Koryo</a>
            </div>
        </footer>
    </div><!-- Container -->
</section>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

</body>
</html>

最佳答案

问题是关于设置 pdfkit 的 dpi 参数。

因此,如果您遇到同样的问题,请根据需要设置dpi。对我来说,这就是我所需要的

options = {
            'page-size': 'A4',
            'dpi': 400
        }

关于html - pdfkit 生成小比例的 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41924233/

相关文章:

php - 在在线服务器上使用 wkhtmltopdf 生成 pdf 时字体发生变化

css - 将html转换为pdf时如何防止文本溢出(并填充div)?

javascript - 单击关闭时如何制作 <ul> 列表 "retract"

django - PostgreSQL的报告工具

python - Django 迁移找不到 GDALRaster

Django Haystack - 如何在没有词干的情况下强制进行精确的属性匹配?

fpdf - wkhtmltopdf 与 fpdf 以及有关使用和性能的问题(HTML 到 PDF)

javascript - 将 jQuery 绑定(bind)到多个元素

javascript - 将 blob 附加到表单中类型文件的输入

jquery - 如何减小 jQuery UI 选项卡面板标题中的字体大小?