【发布时间】:2018-05-21 12:54:32
【问题描述】:
我正在使用 ASPOSE.HTML 从 HTML 创建 PDF。 我可以重复页眉但无法重复页脚,我们如何在其中添加页码。我正在关注这个例子 HTML to PDF 。 HTML sn-p如下
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<meta http-equiv='X-UA-Compatible' content='ie=edge'>
<title>Document</title>
<style>
@import url('https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900');
body {
margin: 0;
margin: 0 auto;
-webkit-margin-before: 0;
-webkit-margin-after: 0;
-webkit-margin-start: 0;
-webkit-margin-end: 0;
-webkit-padding-start: 0;
font-family: 'roboto' !important;
width: 816px;
}
.top-abc_abc-td {
vertical-align: top;
}
.abc_abc1-img {
background-color: #123664;
height: 105px;
margin: 8px 8px 8px 0px;
}
.col-1 {
width: 286px;
padding: 6px;
}
.col-2 {
width: 202px;
padding: 6px;
}
.col-div {
margin-bottom: 5px;
}
.sub-col-1 {
width: 100px;
}
.sub-col-2 {
width: 145px;
}
.col-3 {
width: 286px;
padding: 6px;
}
.col-border-right {
border-right: 3px solid #749db6;
}
.templateabc_abc {
background-color: #edece8;
}
p.templateabc_abcText {
font-weight: bold;
margin-top: 0px;
margin-bottom: 10px;
}
.abc {
padding-top: 30px;
}
.abc .abc_abc {
padding-bottom: 10px;
border-bottom: 1px solid #D8D8D8;
width: 774px;
font-size: 24px;
font-weight: 300;
}
.abc .description {
margin-top: 20px;
margin-bottom: 10px;
padding-bottom: 10px;
width: 774px;
}
.abcText {
font-weight: bold;
margin-right: 10px;
}
.text-circle {
background-color: #193661;
color: white;
border-radius: 50%;
padding: 2px;
margin-right: 10px;
font-size: 13px;
}
.text-tectangle {
color: white;
background-color: green;
border-radius: 4px;
padding: 2px;
font-size: 13px;
margin-right: 10px;
}
.template-table {
border-collapse: separate;
border-spacing: 6px;
}
.template-table td {
text-align: left;
vertical-align: top;
font-size: 100%;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<td>
<table class='top-abc_abc-td'>
<tr>
<td class='top-abc_abc-td'>
<img class='abc_abc1-img' src='WMC_logo_no_container_R-white_20170905_141629.png' alt=''>
</td>
<td class='top-abc_abc-td' style='width: 415px;'>
<h2>aaaaaa Name</h2>
<h2>aaaaaa1 Name</h2>
</td>
<td class='top-abc_abc-td'>
<div style='margin: 8px'>Date</div>
</td>
</tr>
</table>
</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<table class='template-table'>
<tr>
<td class='col-1 templateabc_abc'>
<p class='templateabc_abcText'>hjksdldasd</p>
hjksdldasdck. hjksdldasd shown in
<i>italics</i> are inactive.
</td>
<td class='col-2 templateabc_abc'>
<p class='templateabc_abcText'>aaaaaa hjksdldasd</p>
hjksdldasd.
</td>
<td class='col-3 templateabc_abc'>
<p class='templateabc_abcText'>hjksdldasd</p>
hjksdldasd the hjksdldasd falls in a top percentile.
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table class='abc'>
<thead>
<tr>
<td class='abc_abc'>
<span class='abcText'>xyzA, xyz1A</span>
</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<table class='template-table'>
<tr>
<td class='col-1 col-border-right'>
<table>
<tr>
<td class='sub-col-1'>
xyz, aaaaaa
</td>
<td class='sub-col-2'>
.
</td>
</tr>
<tr>
<td class='sub-col-1'>
xyz, aaaaaa
</td>
<td class='sub-col-2'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna.
</td>
</tr>
<tr>
<td class='sub-col-1'>
xyz, aaaaaa
</td>
<td class='sub-col-2'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna.
</td>
</tr>
<tr>
<td class='sub-col-1'>
xyz, aaaaaa
</td>
<td class='sub-col-2'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna.
</td>
</tr>
<tr>
<td class='sub-col-1'>
xyz, aaaaaa
</td>
<td class='sub-col-2'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna.
</td>
</tr>
<tr>
<td class='sub-col-1'>
xyz, aaaaaa
</td>
<td class='sub-col-2'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna.
</td>
</tr>
<tr>
<td class='sub-col-1'>
xyz, aaaaaa
</td>
<td class='sub-col-2'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna.
</td>
</tr>
<tr>
<td class='sub-col-1'>
xyz, aaaaaa
</td>
<td class='sub-col-2'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna.
</td>
</tr>
<tr>
<td class='sub-col-1'>
xyz, aaaaaa
</td>
<td class='sub-col-2'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna.
</td>
</tr>
<tr>
<td class='sub-col-1'>
xyz, aaaaaa
</td>
<td class='sub-col-2'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna.
</td>
</tr>
<tr>
<td class='sub-col-1'>
xyz, aaaaaa
</td>
<td class='sub-col-2'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna.
</td>
</tr>
<tr>
<td class='sub-col-1'>
xyz, aaaaaa
</td>
<td class='sub-col-2'>
.
</td>
</tr>
<tr>
<td class='sub-col-1'>
xyz, aaaaaa
</td>
<td class='sub-col-2'>
.
</td>
</tr>
<tr>
<td class='sub-col-1'>
xyz, aaaaaa
</td>
<td class='sub-col-2'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna.
</td>
</tr>
</table>
</td>
<td class='col-2 col-border-right'>
<div class='col-div'>
<span class='text-circle'>hjk</span>3xyz, aaaaaa</div>
<div class='col-div'>
<span class='text-circle'>hjk</span>3xyz, aaaaaa
</div>
</td>
<td class='col-3'>
<div class='col-div'>
<span class='text-tectangle'>hjk</span> 3xyz, aaaaaa
</div>
<div class='col-div'>
<span class='text-tectangle'>hjk</span> 3xyz, aaaaaa
</div>
<div class='col-div'>
<span class='text-tectangle'>hjk</span> 3xyz, aaaaaa
</div>
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table class='abc'>
<thead>
<tr>
<td class='abc_abc'>
<span class='abcText'>xyzB, xyz1B</span>
</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<table class='template-table'>
<tr>
<td class='col-1 col-border-right'>
<table>
<tr>
<td class='sub-col-1'>
xyz, aaaaaa
</td>
<td class='sub-col-2'>
.
</td>
</tr>
<tr>
<td class='sub-col-1'>
xyz, aaaaaa
</td>
<td class='sub-col-2'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna.
</td>
</tr>
<tr>
<td class='sub-col-1'>
xyz, aaaaaa
</td>
<td class='sub-col-2'>
.
</td>
</tr>
<tr>
<td class='sub-col-1'>
xyz, aaaaaa
</td>
<td class='sub-col-2'>
.
</td>
</tr>
<tr>
<td class='sub-col-1'>
xyz, aaaaaa
</td>
<td class='sub-col-2'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna.
</td>
</tr>
</table>
</td>
<td class='col-2 col-border-right'>
<div class='col-div'>
<span class='text-circle'>hjk</span>3xyz, aaaaaa</div>
<div class='col-div'>
<span class='text-circle'>hjk</span>3xyz, aaaaaa
</div>
</td>
<td class='col-3'>
<div class='col-div'>
<span class='text-tectangle'>hjk</span> 3xyz, aaaaaa
</div>
<div class='col-div'>
<span class='text-tectangle'>hjk</span> 3xyz, aaaaaa
</div>
<div class='col-div'>
<span class='text-tectangle'>hjk</span> 3xyz, aaaaaa
</div>
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table class='abc'>
<thead>
<tr>
<td class='abc_abc'>
<span class='abcText'>xyzC, xyz1C</span>
</td>
</tr>
</thead>
</table>
</td>
</tr>
<tr>
<td>
<table class='abc'>
<thead>
<tr>
<td class='abc_abc'>
<span class='abcText'>xyzD, xyz1D</span>
</td>
</tr>
</thead>
</table>
</td>
</tr>
<tr>
<td>
<table class='abc'>
<thead>
<tr>
<td class='abc_abc'>
<span class='abcText'>xyzE, xyz1E</span>
</td>
</tr>
</thead>
</table>
</td>
</tr>
</tbody>
</table>
</body>
</html>
我使用 aspose.html 进行此转换,代码如下
using System.IO;
using System;
namespace Aspose.Html.Examples.CSharp.Conversion
{
public class HtmlToPdf
{
public static void Run()
{
// ExStart:HtmlToPdf
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Data();
String InputHtml = dataDir + "input.html";
using (FileStream fs = File.Create(InputHtml))
using (StreamWriter sw = new StreamWriter(fs))
{
sw.Write(
@"
HTML code here
");
}
// File name for resultant PDF file
string Resultant_output = dataDir + "simple-any-page_out.pdf";
// Create PdfRendering Options object
Aspose.Html.Rendering.Pdf.PdfRenderingOptions pdf_options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions();
// The PageSetup also provides different properties i.e. FirstPage, LastPage, LeftPage, RightPage and they are used to setup (PageSize, Margin) for every page.
// In most cases, usage of setup any page is enough, but in some complicated cases, you may need to fine tune page settings. It can be done either by CSS styles or by using rendering options.
// the size for drawing is in pixels
pdf_options.PageSetup.AnyPage = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(816, 1344));
pdf_options.PageSetup.AnyPage.Margin = new Aspose.Html.Drawing.Margin(20);
// Instantiate PdfDevice object while passing PdfRenderingOptions and resultant file path as arguments
using (Aspose.Html.Rendering.Pdf.PdfDevice pdf_device = new Aspose.Html.Rendering.Pdf.PdfDevice(pdf_options, Resultant_output))
// Create HtmlRenderer object
using (Aspose.Html.Rendering.HtmlRenderer renderer = new Aspose.Html.Rendering.HtmlRenderer())
// Create HtmlDocument instance while passing path of already created HTML file
using (Aspose.Html.HTMLDocument html_document = new Aspose.Html.HTMLDocument(InputHtml))
{
// Render the output using HtmlRenderer
renderer.Render(pdf_device, html_document);
}
// ExEnd:HtmlToPdf
}
}
}
我该怎么做
- 为每一页重复页脚?
- 为每一页提供页码?
【问题讨论】:
-
我们在问题管理系统中记录了 ID 为 HTMLNET-1251 的调查票,以调查 PDF 文档每一页上的页脚重复。另一个 ID 为 HTMLNET-1252 的工单已被记录为在呈现 PDF 文档时添加页码的功能请求。调查票证后,我们将与您分享我们的调查结果。 PS:我与 Aspose 一起担任开发人员宣传员。
-
@FarhanRaza 是否有任何关于 HTMLNET-1251 和 HTMLNET-1252 门票的更新对我有帮助?
-
罚单目前正在等待调查。我们将在适当的时候安排他们。一旦这些票得到解决,您将收到通知。感谢您在这方面的耐心和理解。