我有4个HTML内容,其中第二个HTML有大表数据。一旦PDF生成第二个HTML相关内容分为PDF格式的3页。但是页面编号没有显示为第一个2.对于第二个HTML我在生成时以pdf旋转页面。
PDF显示如下:
1 HTML - 第1页 - 第1页,共5页
2 HTML
- page 2 - ***...no page number...***
- page 3 - ***...no page number...***
- page 4 - 4 of 5
3 HTML - 第5页 - 第5页,共5页
public void HTMLToPdfCMC(string[] HTML, string fileName, string folderPath, string physicalApplPath, string requestNumber = "")
{
try
{
Document document = new Document();
PdfWriter pdfwriter = PdfWriter.GetInstance(document, new FileStream(physicalApplPath + folderPath + "\\" + fileName + ".pdf", FileMode.Create));
TableHeader tevent = new TableHeader();
tevent.Header = requestNumber;
pdfwriter.PageEvent = tevent;
document.SetPageSize(PageSize.A4);
document.Open();
Storage.rotationPage = "";
iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
foreach (string htmlPage in HTML)
{
if (!string.IsNullOrEmpty(requestNumber) && requestNumber.Contains("CMC") && HTML[1] != null && HTML[1] == htmlPage)
{
//do page rotation
document.SetPageSize(PageSize.A4.Rotate());
document.NewPage();
hw.Parse(new StringReader(htmlPage));
Storage.rotationPage = "true";
}
else
{
document.SetPageSize(PageSize.A4);
document.NewPage();
hw.Parse(new StringReader(htmlPage));
Storage.rotationPage = "false";
}
}
document.Close();
}
catch (Exception ex)
{
LogUtil.PublishException("Error in HTMLToPdf EmailHelper - " + ex.Message, ex, null, 8); ;
}
}
//代码
public override void OnEndPage(PdfWriter writer, Document document)
{
PdfPTable table = new PdfPTable(3);
try
{
table.SetWidths(new int[] { 24, 24, 2 });
table.TotalWidth = 527;
table.LockedWidth = true;
table.DefaultCell.FixedHeight = 20;
table.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER;
iTextSharp.text.Font fontH1 = new iTextSharp.text.Font(FontFactory.GetFont("arial", 8));
PdfPCell headerCell = new PdfPCell(new Phrase(Header, fontH1));
headerCell.Border = iTextSharp.text.Rectangle.NO_BORDER;
headerCell.HorizontalAlignment = Element.ALIGN_CENTER;
headerCell.PaddingLeft = 180;
table.AddCell(headerCell);
PdfPCell cell2 = new PdfPCell(new Phrase(string.Format("Page {0} of", writer.PageNumber), fontH1));
cell2.Border = iTextSharp.text.Rectangle.NO_BORDER;
cell2.HorizontalAlignment = Element.ALIGN_RIGHT;
BaseFont bfTimes = BaseFont.CreateFont();
PdfPCell cell = null;
if (Storage.rotationPage == "true")
{
//totalH.SetFontAndSize(bfTimes, 10);
cell = new PdfPCell(iTextSharp.text.Image.GetInstance(total), true);
}
else
{
//total.SetFontAndSize(bfTimes, 12);
cell = new PdfPCell(iTextSharp.text.Image.GetInstance(total), true);
}
cell.Border = iTextSharp.text.Rectangle.NO_BORDER;
table.AddCell(cell2);
table.AddCell(cell);
if (Storage.rotationPage == "true")
{
table.TotalWidth = 790;
table.WriteSelectedRows(0, -1, 34, 570, writer.DirectContent);
}
else
{
table.WriteSelectedRows(0, -1, 34, 815, writer.DirectContent);
}
//float floatx = 20;
//float floaty = 50;
//table.WriteSelectedRows(0, -1, floatx, floaty, writer.DirectContent);
}
catch (DocumentException de)
{
throw de;
}
}
请求我告诉我我失踪的地方。
答案 0 :(得分:1)
刚刚重新安排了storage.rotation行。 谢谢MKL。
.arc:hover path {
fill: red !important;
stroke: red;
}