我正在使用 python 使用下面的代码基于现有的 html 模板生成 pdf。pdf 打印正常,但它跳过了文本之间的所有间隙。例如,在第一页中,某些文本是页脚上的打印机,但在 pdf 中,它会立即打印页脚文本而没有间隙。但是,当我在浏览器中打开 html 时,底部会正确打印页脚!任何想法可能是什么问题?
类 GeneratePdf(webapp2.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'application/pdf' self.response.headers['Content-Disposition'] = 'attachment; filename=will.pdf' will = Will() will.name="Albus Dumbledore" will.children = "Aberforth Dumbledore" will.partner = "Harry Potter" will.address = "Hogwarts school of w & w." will.exec1_name = "西弗勒斯·斯内普" will.exec1_address = "萨里" will.guardian_name="Prongs" will.guardian_address="Dept of Mysteries" will.children="Ariana & Aberforth" will.funeral_preference="@hogwarts"
f=open('template.htm','r')
sourceHtml = f.read()
f.close()
sourceHtml = sourceHtml.replace('__name__',will.name)
sourceHtml = sourceHtml.replace('__address__',will.address)
sourceHtml = sourceHtml.replace('__partner1__',will.partner)
sourceHtml = sourceHtml.replace('__exec1_name__',will.exec1_name)
sourceHtml = sourceHtml.replace('__exec1_address__',will.exec1_address)
sourceHtml = sourceHtml.replace('__guardian_name__',will.guardian_name)
sourceHtml = sourceHtml.replace('__guardian_address__',will.guardian_address)
sourceHtml = sourceHtml.replace('__children__',will.children)
sourceHtml = sourceHtml.replace('__funeral_preference__',will.funeral_preference)
pisa.CreatePDF(sourceHtml,dest=self.response.out)
pisa.pisaDocument(sourceHtml,dest=self.response.out)
编辑:这是 template.htm 的开始方式:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META http-equiv="X-UA-Compatible" content="IE=8">
<TITLE>Created by BCL easyConverter SDK 3 (HTML Version)</TITLE>
<META name="generator" content="BCL easyConverter SDK 3.0.60">
<STYLE type="text/css">
body {margin-top: 0px;margin-left: 0px;}
#page_1 {position:relative; overflow: hidden;margin: 133px 0px 132px 120px;padding: 0px;border: none;width: 673px;}
#page_1 #id_1 {border:none;margin: 0px 0px 0px 0px;padding: 0px;border:none;width: 486px;overflow: hidden;}
#page_1 #id_2 {border:none;margin: 769px 0px 0px 0px;padding: 0px;border:none;width: 673px;overflow: hidden;}
#page_1 #dimg1 {position:absolute;top:68px;left:0px;z-index:-1;width:554px;height:1px;font-size: 1px;line-height:nHeight;}
#page_1 #dimg1 #img1 {width:554px;height:1px;}
#page_2 {position:relative; overflow: hidden;margin: 37px 0px 78px 120px;padding: 0px;border: none;width: 673px;}
#page_3 {position:relative; overflow: hidden;margin: 37px 0px 78px 120px;padding: 0px;border: none;width: 673px;}
#page_4 {position:relative; overflow: hidden;margin: 37px 0px 78px 120px;padding: 0px;border: none;width: 673px;}
#page_5 {position:relative; overflow: hidden;margin: 37px 0px 78px 120px;padding: 0px;border: none;width: 673px;}
#page_6 {position:relative; overflow: hidden;margin: 37px 0px 152px 0px;padding: 0px;border: none;width: 793px;}
#page_7 {position:relative; overflow: hidden;margin: 37px 0px 1043px 0px;padding: 0px;border: none;width: 793px;}
.ft0{font: 30px 'Arial';color: #00000a;line-height: 35px;}
.ft1{font: bold 16px 'Arial';color: #00000a;line-height: 19px;}
.ft2{font: 16px 'Arial';color: #00000a;line-height: 18px;}
.ft3{font: 15px 'Arial';color: #00000a;line-height: 17px;}
.ft4{font: bold 15px 'Arial';color: #00000a;margin-left: 9px;line-height: 18px;}
.ft5{font: bold 15px 'Arial';color: #00000a;line-height: 18px;}
.ft6{font: 15px 'Arial';color: #00000a;margin-left: 5px;line-height: 17px;}
.ft7{font: 15px 'Arial';color: #00000a;margin-left: 4px;line-height: 20px;}
.ft8{font: 15px 'Arial';color: #00000a;line-height: 20px;}
.ft9{font: 15px 'Arial';color: #00000a;margin-left: 2px;line-height: 20px;}
.ft10{font: 15px 'Arial';color: #00000a;margin-left: 1px;line-height: 19px;}
.ft11{font: 15px 'Arial';color: #00000a;line-height: 19px;}
.ft12{font: 15px 'Arial';color: #00000a;margin-left: 2px;line-height: 22px;}
.ft13{font: 15px 'Arial';color: #00000a;line-height: 22px;}
.ft14{font: 15px 'Arial';color: #00000a;margin-left: 1px;line-height: 22px;}
.ft15{font: 15px 'Arial';color: #00000a;margin-left: 3px;line-height: 19px;}
.ft16{font: 15px 'Arial';color: #00000a;line-height: 18px;}
.ft17{font: 12px 'Arial';color: #00000a;line-height: 15px;}
.ft18{font: 11px 'Arial';color: #00000a;line-height: 14px;}
.ft19{font: 16px 'Arial';color: #00000a;line-height: 20px;}
.ft20{font: 16px 'Arial';color: #00000a;line-height: 19px;}
.ft21{font: bold 15px 'Arial';color: #00000a;margin-left: 45px;line-height: 18px;}
.ft22{font: 15px 'Arial';color: #00000a;margin-left: 2px;line-height: 17px;}
.ft23{font: 15px 'Arial';color: #00000a;margin-left: 1px;line-height: 20px;}
.ft24{font: 15px 'Arial';color: #00000a;margin-left: 3px;line-height: 21px;}
.ft25{font: 15px 'Arial';color: #00000a;line-height: 21px;}
.ft26{font: 15px 'Arial';color: #00000a;margin-left: 1px;line-height: 21px;}
.ft27{font: 15px 'Arial';color: #00000a;margin-left: 3px;line-height: 20px;}
.ft28{font: 15px 'Arial';color: #00000a;margin-left: 1px;line-height: 18px;}
.ft29{font: 15px 'Arial';color: #00000a;margin-left: 4px;line-height: 17px;}
.ft30{font: 15px 'Arial';color: #00000a;margin-left: 20px;line-height: 17px;}
.ft31{font: 15px 'Arial';color: #00000a;margin-left: 6px;line-height: 20px;}
.ft32{font: 15px 'Arial';color: #00000a;margin-left: 1px;line-height: 17px;}
.ft33{font: 15px 'Arial';color: #00000a;margin-left: 7px;line-height: 22px;}
.ft34{font: 15px 'Arial';color: #00000a;margin-left: 2px;line-height: 18px;}
.ft35{font: bold 15px 'Arial';color: #00000a;margin-left: 2px;line-height: 18px;}
.ft36{font: bold 15px 'Arial';color: #00000a;margin-left: 1px;line-height: 18px;}
.ft37{font: bold 15px 'Arial';color: #00000a;margin-left: 4px;line-height: 18px;}
.ft38{font: bold 13px 'Arial';color: #00000a;line-height: 16px;}
.ft39{font: bold 12px 'Arial';color: #00000a;line-height: 15px;}
.p0{text-align: left;margin-top: 0px;margin-bottom: 0px;}
.p1{text-align: left;padding-left: 76px;margin-top: 0px;margin-bottom: 0px;}
.p2{text-align: left;margin-top: 6px;margin-bottom: 0px;}
.p3{text-align: left;margin-top: 39px;margin-bottom: 0px;}
.p4{text-align: justify;padding-left: 24px;margin-top: 26px;margin-bottom: 0px;}
.p5{text-align: justify;padding-left: 48px;margin-top: 20px;margin-bottom: 0px;}
.p6{text-align: left;padding-left: 75px;padding-right: 120px;margin-top: 19px;margin-bottom: 0px;text-indent: -27px;}
.p7{text-align: justify;padding-left: 24px;margin-top: 18px;margin-bottom: 0px;}
.p8{text-align: justify;padding-left: 72px;padding-right: 125px;margin-top: 20px;margin-bottom: 0px;text-indent: -24px;}
.p9{text-align: left;padding-left: 72px;padding-right: 131px;margin-top: 13px;margin-bottom: 0px;text-indent: -24px;}
.p10{text-align: justify;padding-left: 24px;margin-top: 21px;margin-bottom: 0px;}
.p11{text-align: justify;padding-left: 72px;padding-right: 131px;margin-top: 19px;margin-bottom: 0px;text-indent: -24px;}
.p12{text-align: justify;padding-left: 72px;padding-right: 130px;margin-top: 10px;margin-bottom: 0px;text-indent: -24px;}
.p13{text-align: left;padding-left: 72px;padding-right: 122px;margin-top: 9px;margin-bottom: 0px;text-indent: -24px;}
.p14{text-align: justify;padding-left: 24px;margin-top: 20px;margin-bottom: 0px;}
.p15{text-align: justify;padding-left: 48px;padding-right: 120px;margin-top: 23px;margin-bottom: 0px;}
.p16{text-align: left;margin-top: 0px;margin-bottom: 0px;white-space: nowrap;}
.p17{text-align: left;padding-left: 67px;margin-top: 0px;margin-bottom: 0px;white-space: nowrap;}
.p18{text-align: left;padding-left: 64px;margin-top: 0px;margin-bottom: 0px;white-space: nowrap;}
.p19{text-align: left;padding-left: 66px;margin-top: 0px;margin-bottom: 0px;white-space: nowrap;}
.p20{text-align: left;padding-left: 63px;margin-top: 0px;margin-bottom: 0px;white-space: nowrap;}
.p21{text-align: justify;padding-left: 48px;margin-top: 57px;margin-bottom: 0px;}
.p22{text-align: justify;padding-left: 24px;margin-top: 27px;margin-bottom: 0px;}
.p23{text-align: left;padding-left: 48px;padding-right: 128px;margin-top: 19px;margin-bottom: 0px;}
.p24{text-align: left;padding-left: 72px;padding-right: 123px;margin-top: 20px;margin-bottom: 0px;text-indent: -23px;}
.p25{text-align: left;padding-left: 72px;padding-right: 120px;margin-top: 13px;margin-bottom: 0px;text-indent: -23px;}
.p26{text-align: justify;padding-left: 24px;margin-top: 19px;margin-bottom: 0px;}
.p27{text-align: justify;padding-left: 72px;padding-right: 128px;margin-top: 19px;margin-bottom: 0px;text-indent: -24px;}
.p28{text-align: justify;padding-left: 72px;padding-right: 174px;margin-top: 13px;margin-bottom: 0px;text-indent: -24px;}
.p29{text-align: left;padding-left: 72px;padding-right: 128px;margin-top: 11px;margin-bottom: 0px;text-indent: -24px;}
.p30{text-align: justify;padding-left: 48px;margin-top: 11px;margin-bottom: 0px;}
.p31{text-align: left;padding-left: 72px;padding-right: 122px;margin-top: 43px;margin-bottom: 0px;}
.p32{text-align: justify;padding-left: 24px;margin-top: 22px;margin-bottom: 0px;}
.p33{text-align: left;padding-left: 48px;padding-right: 143px;margin-top: 23px;margin-bottom: 0px;}
.p34{text-align: left;padding-left: 72px;padding-right: 131px;margin-top: 14px;margin-bottom: 0px;text-indent: -24px;}
.p35{text-align: justify;padding-left: 72px;padding-right: 134px;margin-top: 10px;margin-bottom: 0px;text-indent: -24px;}
.p36{text-align: justify;padding-left: 72px;padding-right: 142px;margin-top: 12px;margin-bottom: 0px;text-indent: -24px;}
.p37{text-align: left;padding-left: 72px;padding-right: 139px;margin-top: 13px;margin-bottom: 0px;text-indent: -24px;}
.p38{text-align: justify;padding-left: 47px;margin-top: 19px;margin-bottom: 0px;}
.p39{text-align: justify;padding-left: 95px;margin-top: 8px;margin-bottom: 0px;}
.p40{text-align: justify;padding-left: 133px;padding-right: 139px;margin-top: 8px;margin-bottom: 0px;text-indent: -38px;}
.p41{text-align: justify;padding-left: 133px;padding-right: 147px;margin-top: 7px;margin-bottom: 0px;text-indent: -38px;}
.p42{text-align: justify;padding-left: 133px;padding-right: 178px;margin-top: 8px;margin-bottom: 0px;text-indent: -38px;}
.p43{text-align: left;padding-left: 133px;padding-right: 121px;margin-top: 8px;margin-bottom: 0px;text-indent: -38px;}
.p44{text-align: justify;padding-left: 133px;padding-right: 140px;margin-top: 7px;margin-bottom: 0px;text-indent: -38px;}
.p45{text-align: justify;padding-left: 72px;padding-right: 120px;margin-top: 15px;margin-bottom: 0px;text-indent: -24px;}
.p46{text-align: justify;padding-left: 48px;margin-top: 13px;margin-bottom: 0px;}
.p47{text-align: left;padding-left: 72px;padding-right: 121px;margin-top: 39px;margin-bottom: 0px;}
.p48{text-align: left;padding-left: 72px;padding-right: 124px;margin-top: 31px;margin-bottom: 0px;text-indent: -24px;}
.p49{text-align: justify;padding-left: 72px;padding-right: 172px;margin-top: 10px;margin-bottom: 0px;text-indent: -24px;}
.p50{text-align: justify;padding-left: 72px;padding-right: 137px;margin-top: 9px;margin-bottom: 0px;text-indent: -24px;}
.p51{text-align: left;padding-left: 72px;padding-right: 127px;margin-top: 10px;margin-bottom: 0px;text-indent: -24px;}
.p52{text-align: justify;padding-left: 24px;margin-top: 40px;margin-bottom: 0px;}
.p53{text-align: left;padding-left: 48px;margin-top: 20px;margin-bottom: 0px;}
.p54{text-align: justify;padding-left: 48px;margin-top: 19px;margin-bottom: 0px;}
.p55{text-align: justify;padding-left: 24px;margin-top: 37px;margin-bottom: 0px;}
.p56{text-align: justify;margin-top: 19px;margin-bottom: 0px;}
.p57{text-align: right;padding-right: 149px;margin-top: 0px;margin-bottom: 0px;}
.p58{text-align: left;padding-left: 120px;margin-top: 6px;margin-bottom: 0px;}
.p59{text-align: left;padding-left: 120px;margin-top: 57px;margin-bottom: 0px;}
.p60{text-align: right;margin-top: 0px;margin-bottom: 0px;white-space: nowrap;}
.p61{text-align: right;padding-right: 111px;margin-top: 0px;margin-bottom: 0px;white-space: nowrap;}
.p62{text-align: left;padding-left: 120px;margin-top: 66px;margin-bottom: 0px;}
.p63{text-align: left;padding-left: 120px;margin-top: 18px;margin-bottom: 0px;}
.p64{text-align: left;padding-left: 120px;margin-top: 37px;margin-bottom: 0px;}
.p65{text-align: right;padding-right: 105px;margin-top: 0px;margin-bottom: 0px;white-space: nowrap;}
.p66{text-align: left;padding-left: 120px;margin-top: 25px;margin-bottom: 0px;}
.p67{text-align: left;padding-left: 120px;margin-top: 4px;margin-bottom: 0px;}
.p68{text-align: left;padding-left: 120px;margin-top: 31px;margin-bottom: 0px;}
.p69{text-align: left;padding-left: 120px;margin-top: 54px;margin-bottom: 0px;}
.td0{padding: 0px;margin: 0px;width: 135px;vertical-align: bottom;}
.td1{padding: 0px;margin: 0px;width: 208px;vertical-align: bottom;}
.td2{padding: 0px;margin: 0px;width: 190px;vertical-align: bottom;}
.td3{padding: 0px;margin: 0px;width: 227px;vertical-align: bottom;}
.td4{padding: 0px;margin: 0px;width: 284px;vertical-align: bottom;}
.tr0{height: 19px;}
.tr1{height: 18px;}
.tr2{height: 27px;}
.tr3{height: 26px;}
.t0{width: 533px;margin-top: 81px;font: 12px 'Arial';color: #00000a;}
.t1{width: 533px;margin-top: 87px;font: 12px 'Arial';color: #00000a;}
.t2{width: 533px;margin-top: 80px;font: 12px 'Arial';color: #00000a;}
.t3{width: 533px;margin-top: 164px;font: 12px 'Arial';color: #00000a;}
.t4{width: 511px;margin-left: 120px;margin-top: 105px;font: 12px 'Arial';color: #00000a;}
.t5{width: 511px;margin-left: 120px;margin-top: 31px;font: 12px 'Arial';color: #00000a;}
.t6{width: 511px;margin-left: 120px;margin-top: 50px;font: 12px 'Arial';color: #00000a;}
</STYLE>
<!--prahlad
<style>
@page {
size: a4 portrait;
@frame header_frame {
-pdf-frame-content: header_content;
left: 50pt; width: 512pt; top: 50pt; height: 40pt;
}
@frame content_frame {
left: 50pt; width: 512pt; top: 90pt; height: 632pt;
}
@frame footer_frame {
-pdf-frame-content: footer_content;
left: 50pt; width: 512pt; top: 772pt; height: 20pt;
}
}
</style>-->
</HEAD>
<BODY>
<DIV id="page_1">
<DIV id="dimg1">
<IMG src="template_images/template1x1.jpg" id="img1">
</DIV>
<DIV id="id_1">
<P class="p0 ft0">This is the last Will and Testament of __name__</P>
</DIV>
<DIV id="id_2">
<P class="p0 ft1">Willys</P>
</DIV>
</DIV>
<DIV id="page_2">
<P class="p1 ft1">LAST WILL AND TESTAMENT OF __NAME__</P>
<P class="p2 ft2">2</P>
<P class="p3 ft3">This will is made by me __name__ of __address__.</P>
<P class="p4 ft5"><SPAN class="ft2">1.</SPAN><SPAN class="ft4">Last will and testament</SPAN></P>
<P class="p5 ft3">I revoke all prior wills and testamentary acts.</P>
<P class="p4 ft5"><SPAN class="ft2">2.</SPAN><SPAN class="ft4">Executor</SPAN></P>
<P class="p5 ft3"><SPAN class="ft2">(a)</SPAN><SPAN class="ft6">I appoint my partner __partner1__ to be the executor of my Will.</SPAN></P>
<P class="p6 ft8"><SPAN class="ft2">(b)</SPAN><SPAN class="ft7">If __partner1__ is unable or unwilling to act as my executor I appoint in the alternative __exec1_name__ of __exec1_address__, to act as my executor.</SPAN></P>
<P class="p7 ft5"><SPAN class="ft2">3.</SPAN><SPAN class="ft4">Guardians</SPAN></P>
<P class="p8 ft8"><SPAN class="ft2">(a)</SPAN><SPAN class="ft9">I appoint __guardian_name__ of __guardian_address__ to be guardian of any minor children I have at the time of my death.</SPAN></P>
<P class="p9 ft11"><SPAN class="ft2">(b)</SPAN><SPAN class="ft10">This appointment applies only if the other parent of any minor children I have at the time of my death does not survive me or is unable to care for them.</SPAN></P>
<P class="p10 ft5"><SPAN class="ft2">4.</SPAN><SPAN class="ft4">Beneficiaries</SPAN></P>
<P class="p11 ft13"><SPAN class="ft2">(a)</SPAN><SPAN class="ft12">If my partner survives me by 30 days, I give my entire estate to __partner__.</SPAN></P>
<P class="p12 ft13"><SPAN class="ft2">(b)</SPAN><SPAN class="ft14">If my partner does not survive me by 30 days I give the balance of my estate in equal shares to my children __children__.</SPAN></P>
<P class="p13 ft11"><SPAN class="ft2">(c)</SPAN><SPAN class="ft15">If any of my children die before any gift to them takes effect and they are survived by children of their own (i.e. my grandchildren) then I give the share of my estate that would have gone to my deceased child to their children in equal shares.</SPAN></P>
<P class="p14 ft5"><SPAN class="ft2">5.</SPAN><SPAN class="ft4">Alternative beneficiaries</SPAN></P>
<P class="p15 ft16">If the gifts above fail to take effect then and only then I give my estate in equal shares to __children__.</P>
<P class="p10 ft5"><SPAN class="ft2">6.</SPAN><SPAN class="ft4">Funeral directions</SPAN></P>
<TABLE cellpadding=0 cellspacing=0 class="t0">
<TR>
<TD class="tr0 td0"><P class="p16 ft17">___________________</P></TD>
<TD class="tr0 td1"><P class="p17 ft17">___________________</P></TD>
<TD class="tr0 td2"><P class="p18 ft18">___________________</P></TD>
</TR>
<TR>
<TD class="tr1 td0"><P class="p16 ft17">Testator sign</P></TD>
<TD class="tr1 td1"><P class="p19 ft17">Witness 1 sign</P></TD>
<TD class="tr1 td2"><P class="p20 ft17">Witness 2 sign</P></TD>
</TR>
</TABLE>
</DIV>
<DIV id="page_3">
<P class="p1 ft1">LAST WILL AND TESTAMENT OF __NAME__</P>
<P class="p2 ft2">3</P>
............