gpt4 book ai didi

html - Python PDFkit 缩小 HTML 并且无法正确显示数字

转载 作者:行者123 更新时间:2023-12-04 13:59:27 25 4
gpt4 key购买 nike

我有一个用 Jinja2 创建的本地 html 文件,我试图将其导出为 PDF。我的浏览器中的 HTML 看起来是正确的(click here 用于屏幕截图),但是,当使用 pdfkit 导出时,似乎整个文档都在缩小并且文本困惑(主要是数字)。

可以找到我的 pdf 输出 here.

我的python代码如下:

import pdfkit
import os
import sys

path_wkthmltopdf = r'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
options = {
'dpi': 300,
'page-size': 'Letter',
'margin-top': '0.25in',
'margin-right': '0.25in',
'margin-bottom': '0.25in',
'margin-left': '0.25in',
'encoding': "UTF-8",
'custom-header' : [
('Accept-Encoding', 'gzip')
],
'no-outline': None
}
pdfkit.from_file('brochure.html','brochure.pdf', configuration = config, options= options)

我的 HTML 和 CSS 文件如下(某些文本因隐私而更改, @fontface 未在 CSS 中显示):

@media print {
-webkit-print-color-adjust: exact;
@page
{
width: 8.5in;
height: 11in;
margin: 0.25in;
}
body{
margin: 0.25in;
}

}


body, div, dl, dt, dd, h1, h2, h3, h4, h5, h6, p, pre, code, blockquote {
margin:0;
padding:0;
border-width:0;
}
body {
margin: 0.25in;
width: 8.5in;
height: 11in;

}
/* Begin Header */

header{
width: 8in;
height: 1in;
background-image: url("../Pics/header-bg.JPG")!important;
background-position: center;
background-size: cover;
}

.wrapper{
margin: 0.25in;
position: relative;
min-height: 100%;
}

#head_desc{
width: 1.9in;
height: 100%;
display:inline-block;
overflow: hidden;
}
#head_desc h2{
padding: 8% 4% 0% 8%;
margin-bottom: 1%;
color:white;
font-family:"Gotham Narrow Medium", sans-serif;
text-transform: uppercase;
font-size:19px;
font-style:normal;
font-weight:500;
transform: scale(1, .9);
-webkit-transform: scale(1, .9);
-moz-transform: scale(1, .9);
-ms-transform: scale(1, .9);
-o-transform: scale(1, .9);
}

#head_desc p{
padding: 0% 4% 0% 8%;
margin-top: 0px;
color: white;
font-family: "Gotham Narrow Light", sans-serif;
/* text-transform: uppercase; */
font-size: 17px;
font-style: normal;
font-weight: 400;
transform: scale(1, .9);
-webkit-transform: scale(1, .9);
}
html {
position: relative;
min-height: 100%;
}
#head_address{
display: inline-block;
float:right;
text-align: right;
height: 100%;
width: 50%;
overflow: hidden;
}

#head_address h1{
padding: 4% 4% 0% 8%;
margin-top: 0px;
font-family:"Gotham Narrow Light";
font-size: 30px;
color: #c10230;
font-style:normal;
transform: scale(1, .9);
-webkit-transform: scale(1, .9);
font-weight:500;
}

#head_address h2{
padding: 0% 4% 0% 8%;
font-family:"Gotham Narrow Light";
font-size: 19px;
color: #c10230;
font-style:normal;
transform: scale(1, .9);
-webkit-transform: scale(1, .9);
font-weight:500;
}

.images{
width: 100%;
height: 4.8in;
overflow: hidden;
margin-top: 1%;
margin-bottom: 1%;
}
.hero-image{
width:64%;
float:left;
display: inline-block;
}
.second-image, .third-image{
display: inline-block;
/* width: 34%;
height: 48%; */
float: right;
}

.third-image{
margin-top: 1.5%;
}

.fillwidth {
width: 100%;
height: auto;
}
.fillheight {
height: 100%;
width: auto;
}


.trailerleft {
overflow: hidden;
width: 64.5%;
height: 100%;
display:flex;
align-items:center;
justify-content:center;
}

.trailerright {
overflow: hidden;
width: 34%;
height: 48.7%;
display:flex;
align-items:center;
justify-content:center;
}

/* .fill{
display: flex;
justify-content: center;
align-items: center;
overflow: hidden
}

.fill img {
flex-shrink: 0;
min-width: 100%;
min-height: auto;
} */

#greybar{
width: 5.4in;
height: 0.3in;
float: right;
background-color:#6d6e71;
border-width:0px;
}

#pspecs{
color:white;
float: left;
margin-left: 4%;
margin-top: 0.5%;
font-family: "Gotham Narrow Book";
transform: scale(1, .9);
text-transform: uppercase;
-webkit-transform: scale(1, .9);
font-size: 20px;
}

#contact-section{
display: inline-block;
float: left;
width: 1.8333in;
font-size: 10px;
margin-top: 10%;
}

.moreinfo{
font-family: "Gotham Rounded Light Italic";
font-size: 11px;
margin-bottom: 10%;
}

.contact-info{
margin-top:4%;
}

.name{
font-family: "Gotham Narrow Book";
text-transform: uppercase;
color: #c10230;
font-size: 11px;
}
.title{
font-family: "Gotham Rounded Book Italic";
color: black;
}

.phone,.email{
font-family: "Gotham Rounded Book";
}

.con-address{
margin-top: 10%;
font-family: "Gotham Rounded Book";
font-size: 9px;
}

.con-address span{
font-family: "Gotham Narrow Book";
font-size: 11px;
}
.disclaimer{
font-family: "Gotham Rounded Light";
margin-top: 8%;
font-size: 9px;
}

#propertyinfo{
float: right;
width: 5.3in;
margin-top: 1%;
}

#pitable{
width: 100%;
}




.leftcell{
color: #c10230;
font-family: "Gotham Rounded Book", sans-serif;
font-size: 12px;
font-style: normal;
vertical-align: middle;
font-weight: 300;
width: 35%;
padding: 2%;
border-bottom: solid black .5px;
}



.rightcell{
color: #000000;
font-family: "Gotham Rounded Book", sans-serif;
font-size: 12px;
font-style: normal;
font-weight: 300;
padding: 2% 0% 2% 0%;
border-bottom: solid black .5px;
}

.rightcell.comments, .leftcell.comments{
border-bottom: 0px !important;
}

.rightcell ul{
padding-left: 5%;
margin: 0;
}

footer{
position:absolute;
height: 0.52in;
overflow: hidden;
width: 100%;
bottom: 0;
}
.footerimage{
width: 100%;
height: 50%;
}
.footerimage img{
height: 100%;
width: auto;
float: right;
}
.footerline{
margin-top:.4%;
margin-bottom:.2%;
height: .5%;
border-top: .3px solid #58585b;
}
#footerlink{
float:right;
height: .5%;
font-family: "Gotham Narrow Book";
font-size: 12px;
color: #c10230;
}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<title>Off-Market-Template</title>
<link href="./css/idGeneratedStyles.css" rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="./js/script.js" />
</script>
</head>

<body id="offmarketbrochure-template" lang="en-US">
<div class="wrapper">
<header>
<div id="head_desc">
<h2>Off-market</h2>
<p>Confidential </br> Sale Offering</p>
</div>
<div id="head_address">
<h1>Test Address</h1>
<h2>Chicago IL, 60607</h2>
</div>
</header>


<div class="images">
<div class="hero-image trailerleft">
<img src="./Pics/image1.jpg" alt="" class="fillheight" />
</div>
<div class="second-image trailerright">
<img src="./Pics/streetview.jpg" alt="" class="fillwidth" />
</div>
<div class="third-image trailerright">
<img src="./Pics/mapview.png" alt="" class="fillheight" />
</div>
</div>

<div id="greybar" class="Basic-Graphics-Frame _idGenObjectStyleOverride-2">
<p id="pspecs">
Property Specifications
</p>
</div>

<div id="contact-section">
<p class="moreinfo">
For more information, please contact:
</p>


<div class="contact-info">
<h3 class="name">BROKER 1, SIOR</h3>
<p class="title">Principal</p>
<p class="phone">312-111-1111</p>
<p class="email">BROKER EMAIL</p>
</div>


<div class="contact-info">
<h3 class="name">BROKER 2</h3>
<p class="title">Principal</p>
<p class="phone">312-111-1111</p>
<p class="email">BROKER EMAIL</p>
</div>


<p class="con-address">
<span>Company <br /></span>
Address <br />
Chicago, IL
</p>
<p class="disclaimer">
All information contained herein is from sources deemed reliable and is submitted subject to errors, omissions and to change of price or terms without notice.
</p>

</div>
<div id="propertyinfo">
<table id="pitable" cellspacing="0">
<tbody>
<!-- Max amount of rows not including comments should be 8 -->
<!-- Building Size Row -->



<tr>
<td class="leftcell">
Building Size
</td>
<td class="rightcell">
28,106 SF
</td>
</tr>


<!-- Land Size Row -->


<tr>
<td class="leftcell">
Land Size
</td>
<td class="rightcell">
17,860 SF
</td>
</tr>


<!-- Stories Row -->


<tr>
<td class="leftcell">
Stories
</td>
<td class="rightcell">
3
</td>
</tr>


<!-- Drive in Row -->


<!-- Docks Row -->


<tr>
<td class="leftcell">
Loading Docks
</td>
<td class="rightcell">
4 ext
</td>
</tr>


<!-- Construction Row -->


<tr>
<td class="leftcell">
Construction
</td>
<td class="rightcell">
Masonry
</td>
</tr>


<!-- Ceiling Height Row -->


<tr>
<td class="leftcell">
Ceiling Height
</td>
<td class="rightcell">
12'
</td>
</tr>


<!-- Elevators Row -->
<!-- -->

<!-- Cranes Row -->
<!--

<tr>
<td class="leftcell">
Cranes
</td>
<td class="rightcell">
None
</td>
</tr>
-->

<!-- Power Row -->
<!-- -->

<!-- Parking Row -->
<!--

<tr>
<td class="leftcell">
Parking
</td>
<td class="rightcell">
8 free Surface Spaces are available; Ratio of 0.28/1,000 SF
</td>
</tr>
-->

<!-- Ward Row -->


<!-- Zoning Row -->


<tr>
<td class="leftcell">
Zoning
</td>
<td class="rightcell">
C1-3
</td>
</tr>


<!-- Taxes Row -->


<tr>
<td class="leftcell">
2017 Taxes
</td>
<td class="rightcell">
$46,266.56
</td>
</tr>


<!-- Pins Row -->



<!-- Sale Row -->


<tr>
<td class="leftcell">
Sale Price
</td>
<td class="rightcell">
$2,000,000
</td>
</tr>



<!-- lease Row -->


<!-- Comments section -->
<tr>
<td class="leftcell comments">
Comments
</td>
<td class="rightcell comments">
<ul>
<li>
<p>
Easily accessible via Ashland Station (Green, Pink Lines), located 0.5 miles away
</p>
</li>
<li>
<p>
Located 1.0 miles from the Chicago Ogilvie Transportation Center Commuter station
</p>
</li>
<li>
<p>
Excellent location on W Randolph Street
</p>
</li>
</ul>
</td>
</tr>
</tbody>
</table>


</div>
<footer>

<div class="footerimage">
<img src="./Pics/footerlogo.jpg" />
</div>
<div class="footerline">

</div>
<p id="footerlink">
www.Website.com
</p>
</footer>
</div>


</body>
</html>


非常感谢您的帮助!

最佳答案

在我的情况下,在 pdfkit 选项中调整 dpi 可以解决问题:

options = {
'dpi': 300 # adjust till it fits (try like 250 or 350)
}

pdfkit.from_file('a.html', 'a.pdf', options = options)

关于html - Python PDFkit 缩小 HTML 并且无法正确显示数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53542783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com