使用 iTextSharp 将 TableLayoutPanels 复制到 pdf
Using iTextSharp to copy TableLayoutPanels to pdf
大家下午好。我有一个问题涉及在 tablelayoutpanel 中获取数据并使用 iTextSharp 将其放入 .pdf 中(除非有人知道更好的技术)。默认情况下,tableLayout 面板由 1 列和 1 行组成,并且根据数据 returns.
动态添加行
这是我要打印的内容:
private void btnPrint_Click(object sender, EventArgs e)
{
try
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Title = "Save file as...";
dialog.Filter = "Pdf File |*.pdf";
if (dialog.ShowDialog() == DialogResult.OK)
{
Document doc = new Document(PageSize.LETTER);
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(dialog.FileName, FileMode.Create));
doc.Open();
Paragraph entry1 = new Paragraph("Hello World!");
//Page 1 Printing
PdfPTable LegendsForTable = new PdfPTable(this.tblPnlLayLFT.ColumnCount);
doc.Add(entry1);
doc.Close();
MessageBox.Show("File saved");
}
}
catch (Exception exception)
{
MessageBox.Show(@"ERROR: Issue encountered while trying to print. " + Environment.NewLine
+ @"Contact ITSupport with the following the following error" + Environment.NewLine
+ exception);
}
}
有人知道将 tablelayoutpanel
复制到 .pdf 的方法吗?
我自己解决了这个问题。
第 1 步是创建一个循环遍历 table 布局面板,并将我想要的顺序放入列表中。
int 迭代器 = 1;
int replicateIterator = 1;
List<string> table1List = new List<string>();
for (int counter = 0; counter < 6; counter++)
{
while (reIterator < 7)
{
string currentLabel = "LblRE" + reIterator + "R" + replicateIterator;
Label reLabel = this.Controls.Find(currentLabel, true).FirstOrDefault() as Label;
if (reLabel.Text != null)
{
table1List.Add(reLabel.Text);
reIterator = reIterator + 1;
}
else
{
table1List.Add(reLabel.Text = "");
reIterator = reIterator + 1;
}
}
//Builds next row
if (reIterator == 7)
{
replicateIterator = replicateIterator + 1;
reIterator = 1;
}
}
然后使用 iTextSharp 我可以循环使用列表并将数据添加到 PDF。
大家下午好。我有一个问题涉及在 tablelayoutpanel 中获取数据并使用 iTextSharp 将其放入 .pdf 中(除非有人知道更好的技术)。默认情况下,tableLayout 面板由 1 列和 1 行组成,并且根据数据 returns.
动态添加行这是我要打印的内容:
private void btnPrint_Click(object sender, EventArgs e)
{
try
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Title = "Save file as...";
dialog.Filter = "Pdf File |*.pdf";
if (dialog.ShowDialog() == DialogResult.OK)
{
Document doc = new Document(PageSize.LETTER);
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(dialog.FileName, FileMode.Create));
doc.Open();
Paragraph entry1 = new Paragraph("Hello World!");
//Page 1 Printing
PdfPTable LegendsForTable = new PdfPTable(this.tblPnlLayLFT.ColumnCount);
doc.Add(entry1);
doc.Close();
MessageBox.Show("File saved");
}
}
catch (Exception exception)
{
MessageBox.Show(@"ERROR: Issue encountered while trying to print. " + Environment.NewLine
+ @"Contact ITSupport with the following the following error" + Environment.NewLine
+ exception);
}
}
有人知道将 tablelayoutpanel
复制到 .pdf 的方法吗?
我自己解决了这个问题。
第 1 步是创建一个循环遍历 table 布局面板,并将我想要的顺序放入列表中。
int 迭代器 = 1; int replicateIterator = 1;
List<string> table1List = new List<string>();
for (int counter = 0; counter < 6; counter++)
{
while (reIterator < 7)
{
string currentLabel = "LblRE" + reIterator + "R" + replicateIterator;
Label reLabel = this.Controls.Find(currentLabel, true).FirstOrDefault() as Label;
if (reLabel.Text != null)
{
table1List.Add(reLabel.Text);
reIterator = reIterator + 1;
}
else
{
table1List.Add(reLabel.Text = "");
reIterator = reIterator + 1;
}
}
//Builds next row
if (reIterator == 7)
{
replicateIterator = replicateIterator + 1;
reIterator = 1;
}
}
然后使用 iTextSharp 我可以循环使用列表并将数据添加到 PDF。