4,816
社区成员
发帖
与我相关
我的任务
分享
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dtable = new DataTable();
DataColumn dtCol = new DataColumn();
DataColumn lineCol = new DataColumn();
DataColumn col = new DataColumn();
dtCol.ColumnName = "ReportName";
col.ColumnName = "PageNum";
dtable.Columns.Add(dtCol);
dtable.Columns.Add(col);
ReportService.ReportService g = new ScheduleReport.ReportService.ReportService();//引用webservices
for (int i = 1; i < 50; i++)
{
if (i >= 1 && i <= 18)
{
//这个方法是读数据库的一个表,里面保存报表名称和报表ID
string reprotName = g.GetReportTypeName(i);
//你也可以用别的方式,只要能够生成一个类似TestTable的数据就好了
DataRow dr;
dr = dtable.NewRow();
dr[0] = i.ToString() + "." + reprotName.ToString();
dr[1] = i.ToString();
dtable.Rows.Add(dr);
}
}
pdfStyle(dtable);
}
}
protected void pdfStyle(DataTable dt)
{
try
{
Document document = new Document(PageSize.A3.Rotate());
PdfWriter.GetInstance(document, new FileStream(Server.MapPath("ExportFile\\Chap01012.pdf"), FileMode.Create));
document.Open();
BaseFont bfChinese = BaseFont.CreateFont("E:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Font fontChinese = new Font(bfChinese, 13, Font.NORMAL, new Color(0, 0, 0));
Paragraph pTitle = new Paragraph("TABLE OF CONTENTS", FontFactory.GetFont(FontFactory.TIMES_BOLDITALIC, 28, new Color(0, 0, 0)));
pTitle.Alignment = 0;
document.Add(pTitle);
document.Add(new Paragraph(" "));
string content;
for (int i = 0; i < dt.Rows.Count; i++)
{
string s = dt.Rows[i][0].ToString() + "-----------------------------------------------------------------------------------------------------------------------------------------------------";
if (s.Length >= 150)
{
s = s.Substring(0, 150);
}
if (dt.Rows[i][1].ToString().Length == 1)
{
content = s + " " + dt.Rows[i][1].ToString();
}
else if (dt.Rows[i][1].ToString().Length == 2)
{
content = s + " " + dt.Rows[i][1].ToString();
}
else if (dt.Rows[i][1].ToString().Length == 3)
{
content = s + " " + dt.Rows[i][1].ToString();
}
else
{
content = s + " " + dt.Rows[i][1].ToString();
}
Anchor click = new Anchor(content, fontChinese);
//click.Reference = "http://www.whiteboardlabs.com";
click.Reference = "#target"+(i+1).ToString();// +dt.Rows[i][1].ToString();
Paragraph p1 = new Paragraph();
p1.Add(click);
p1.Alignment = 1;
//cell = new PdfPCell(new Phrase(click));
//cell.AddElement();
document.Add(p1);
//}
//cell.Border = 0;
//table.AddCell(cell);
//table.AddCell(new Phrase(dt.Rows[i][j].ToString(), fontChinese));
//}
}
for (int j = 1; j <= 18; j++)
{
Paragraph p2 = new Paragraph();
p2.Add(new Chunk("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"));
document.Add(p2);
Anchor target = new Anchor("This is the Target"+j.ToString());
target.Name = "target"+j.ToString();
Paragraph p3 = new Paragraph();
p3.Add(target);
document.Add(p3);
}
document.Close();
}
catch (DocumentException de)
{
Response.Write(de.ToString());
}
}