在单个pdf文件中添加三个表格 [英] Adding three tables in a single pdf
本文介绍了在单个pdf文件中添加三个表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在导出到Pdf,我需要在一个pdf文件中执行三个表.在新页面中的第一个表应同时启动第二个表和第三个表.我创建了一个数据表,并且仅执行了一个表的数据集.
问候
Balamurugan
Hi,
I''m Working On Export to Pdf i need to execute three tables in a single pdf.After first table in a new page second table should start as well as third table.I have created a datatable and dataset only one table is getting executed.
Regards
Balamurugan
推荐答案
数据表之后,我们需要遵循以下代码,
After the datatable we need to follow the below code,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using BObject;
using BusinessLogic;
using System.Threading;
using System.Data;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
namespace MultipleTable
{
public partial class ExportAll : Window
{
PIGbuslogic BL = new PIGbuslogic();
PIGBObject BO = new PIGBObject();
DataSet dsAllReportsData = new DataSet();
private ProgressbarImage pbw = null;
public delegate void OnWorkerMethodCompleteDelegate(string message);
public event OnWorkerMethodCompleteDelegate OnWorkerComplete;
public delegate void poplateLabelDelegate();
public ExportAll()
{
InitializeComponent();
OnWorkerMethodStart();
}
private void OnWorkerMethodStart()
{
OnWorkerComplete += new OnWorkerMethodCompleteDelegate(OnWorkerMethodComplete);
ThreadStart tStart = new ThreadStart(WorkerMethod);
Thread t = new Thread(tStart);
t.Start();
pbw = new ProgressbarImage();
pbw.ShowInTaskbar = false;
pbw.Owner = this.Owner;
pbw.ShowDialog();
}
private void OnWorkerMethodComplete(string message)
{
pbw.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
new Action(
delegate()
{
pbw.Close();
}
));
pbw.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
new Action(
delegate()
{
Global.customCaption = "PDF Export";
Global.customMessage = "PDF generated successfully..";
CustomMessageBox CMB = new CustomMessageBox();
CMB.ShowInTaskbar = false;
CMB.ShowDialog();
}
));
}
public void BindDatatoPDF(DataSet dsAllReportsData)
{
//Joint List Data
try
{
if (dsAllReportsData.Tables.Count > 0)
{
if (dsAllReportsData.Tables[0].Rows.Count > 0)
{
int pdfRowIndex = 1;
Document document = new Document(PageSize.LETTER);
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("C://Bala//Saibabapdf.pdf", FileMode.Create));
document.Open();
iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 7);
float[] columnDefinitionSize = { 10F, 15F, 10F, 10F, 10F, 10F, 8F, 8F, 9F, 10F };
PdfPTable table = null;
PdfPCell cell = null;
table = new PdfPTable(columnDefinitionSize);
table.WidthPercentage = 100;
cell = new PdfPCell(new Phrase("DefectNumber" + " AnomalyTypeName" + "Length" + "Width" + "Depth" + " Distance" + "Latitude" + "Longitude" + "Orientation" + "Comments"));
PdfPCell imageCell = new PdfPCell(new Phrase("Joint List Data"));
imageCell.Colspan = 10; // either 1 if you need to insert one cell
imageCell.Border = 0;
imageCell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
//imageCell.FixedHeight = 0.3f;
table.AddCell(imageCell);
PdfPCell CellActext = new PdfPCell(new Phrase(new Chunk("DefectNumber", FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.WHITE))));
CellActext.Colspan = 1;
CellActext.Border = 0;
CellActext.HorizontalAlignment = Element.ALIGN_LEFT;
CellActext.BackgroundColor = new iTextSharp.text.Color(24, 150, 191);
table.AddCell(CellActext);
//table.AddCell(new Phrase("DefectNumber", font5));
table.AddCell(new Phrase("AnomalyTypeName", font5));
table.AddCell(new Phrase("Length", font5));
table.AddCell(new Phrase("Width", font5));
table.AddCell(new Phrase("Depth", font5));
table.AddCell(new Phrase("Distance", font5));
table.AddCell(new Phrase("Latitude", font5));
table.AddCell(new Phrase("Longitude", font5));
table.AddCell(new Phrase("Orientation", font5));
table.AddCell(new Phrase("Comments", font5));
pdfRowIndex++;
for (int i = 0; i < dsAllReportsData.Tables[0].Rows.Count; i++)
{
table.AddCell(new Phrase(dsAllReportsData.Tables[0].Rows[i]["DefectNumber"].ToString(), font5));
table.AddCell(new Phrase(dsAllReportsData.Tables[0].Rows[i]["AnomalyTypeName"].ToString(), font5));
table.AddCell(new Phrase(dsAllReportsData.Tables[0].Rows[i]["Length"].ToString(), font5));
table.AddCell(new Phrase(dsAllReportsData.Tables[0].Rows[i]["Width"].ToString(), font5));
table.AddCell(new Phrase(dsAllReportsData.Tables[0].Rows[i]["Depth"].ToString(), font5));
table.AddCell(new Phrase(dsAllReportsData.Tables[0].Rows[i]["Distance"].ToString(), font5));
table.AddCell(new Phrase(dsAllReportsData.Tables[0].Rows[i]["Latitude"].ToString(), font5));
table.AddCell(new Phrase(dsAllReportsData.Tables[0].Rows[i]["Longitude"].ToString(), font5));
table.AddCell(new Phrase(dsAllReportsData.Tables[0].Rows[i]["Orientation"].ToString(), font5));
table.AddCell(new Phrase(dsAllReportsData.Tables[0].Rows[i]["Comments"].ToString(), font5));
pdfRowIndex++;
}
PdfPCell CellABC = new PdfPCell();
CellABC.AddElement(table);
CellABC.HorizontalAlignment = Element.ALIGN_CENTER;
CellABC.Border = 0;
CellABC.Colspan = 1;
table.AddCell(CellABC);
document.Add(table);
document.Add(Chunk.NEXTPAGE);
document.Add(table);
document.Add(Chunk.NEXTPAGE);
document.Add(table);
document.Close();
}
}
}
catch (Exception ex)
{
Global.customCaption = "PDF Export";
Global.customMessage = "Error while generarting PDF..";
CustomMessageBox CMB = new CustomMessageBox();
CMB.ShowInTaskbar = false;
CMB.ShowDialog();
}
}
public void WorkerMethod()
{
try
{
BO.RunId = 1;//Convert.ToInt32(Global.RunOpend);
//BO.DBPath = @"E:\Working Code\Project_August19\Project_Old\Project\bin\Debug\DB\Test Project.db";//Global.DBPath;
BO.DBPath = @"C:\Bala\Test Project.db";//Global.DBPath;
dsAllReportsData = BL.GetAllReportsData(BO);
BindDatatoPDF(dsAllReportsData);
OnWorkerComplete("Project Created Successfully");
}
catch (Exception ex)
{
pbw.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
new Action(
delegate()
{
pbw.Close();
}))
;
Global.customMessage = "Please Try Again"; DataTable pdftbl = new DataTable();
DataColumn c;
DataRow r;
Global.customCaption = "Alert";
Thread.Sleep(1000);
}
}
}
}
这篇关于在单个pdf文件中添加三个表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文