如何使用iTextsharp在单元格中生成PDF格式的报告 [英] How to generate PDF formatted reports in cells using iTextsharp

查看:80
本文介绍了如何使用iTextsharp在单元格中生成PDF格式的报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

铕preciso基拉嗯relatórioEM PDF,varrendo庵的DataGridView。

Porém淖巴斯达adicionar apenasparágrafos,奎罗阙无PDF基尔igual呐aplicação,quando executoØ的DataGridView。 Écustível?




谷歌翻译:

我需要通过扫描生成PDF报告一个DataGridView。

但是,不仅仅是添加段落,我希望PDF在应用程序中生成相同的内容,当我运行DataGridView时。这可能吗?



我尝试过:



文档doc =  new  Document(); 

// 打开窗口,保存pdf报告文件
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = Arquivo PDF(.pdf)| * .pdf; // 限制要保存的文件格式,并将扩展名设置为.pdf
saveFileDialog。 Title = Selecione aonde deseja salvar o arquivo; // 打开的复选框标题
saveFileDialog.ShowDialog(); // 打开复选框

PdfWriter writer = PdfWriter.GetInstance(doc , new FileStream(saveFileDialog.FileName,FileMode.Create));

// 打开文档
doc.Open();

// 参数创建以创建标题
段落paragrafo1 = new 段落(Font.BOLD);


paragrafo1.Add( Cliente);
paragrafo1.Add( Livro);
paragrafo1.Add( DatedeEmpréstimo);
paragrafo1.Add( DatadeDevolução);
paragrafo1.Add( Status);
paragrafo1.Add( Multa);

// 添加标题
doc.Add(paragrafo1) ;

// 创建pdfTable
PdfPTable pdfTable = new PdfPTable( 5 );

foreach (DataGridViewRow row in dataGrid.Rows)
{
// 填充pdfTable,其中包含作为参数传递的dataGrid当前行的信息
pdfTable.Rows.Add(row.DataBoundItem.ToString());

// 创建新段落
段落paragrafo = new 段落();

// 将PDFTable行添加到段落
paragrafo.AddAll (pdfTable.Rows.ToArray());

// 将段落添加到文档
doc.Add( paragrafo);
}

// 关闭文档
doc.Close();

解决方案

试试这些:

创建PDF表格[ ^ ]

使用C#创建PDF格式的表格iTextSharp [ ^ ]

iTextSharp - 介绍表 [ ^ ]

创建PDF以使用C#以表格格式显示文档 - BurnIgnorance [ ^ ]

Eu preciso gerar um relatório em PDF, varrendo um DataGridView.
Porém não basta adicionar apenas parágrafos, quero que no PDF gere igual na aplicação, quando executo o DataGridView. É possível?


Google translation:
I need to generate a PDF report by scanning a DataGridView.
But not just add paragraphs, I want the PDF to generate the same in the application, when I run the DataGridView. It's possible?

What I have tried:

Document doc = new Document();

// Open window where the pdf report file will be saved
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Arquivo PDF (.pdf)| *.pdf"; // restrict the file format to save, and set the extension as .pdf
saveFileDialog.Title = "Selecione aonde deseja salvar o arquivo"; // checkbox title that opens
saveFileDialog.ShowDialog(); // open the check box

PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(saveFileDialog.FileName, FileMode.Create));

// Open document
doc.Open();

// Parameter creation to create the header
Paragraph paragrafo1 = new Paragraph(Font.BOLD);

               
paragrafo1.Add("Cliente     ");
paragrafo1.Add("Livro         ");
paragrafo1.Add("Date de Empréstimo        ");
paragrafo1.Add("Data de Devolução        ");
paragrafo1.Add("Status       ");
paragrafo1.Add("Multa        ");
                
// adding header
doc.Add(paragrafo1);

// Creating pdfTable
PdfPTable pdfTable = new PdfPTable(5);

foreach (DataGridViewRow row in dataGrid.Rows)
{
    // Populated pdfTable with information from the current row of the dataGrid passed as parameter
    pdfTable.Rows.Add(row.DataBoundItem.ToString());

    // Creating new paragraph
    Paragraph paragrafo = new Paragraph();

    // Adding PDFTable Line to Paragraph
    paragrafo.AddAll(pdfTable.Rows.ToArray());

    // Adding paragraph to document
    doc.Add(paragrafo);
}

// Closing the document
doc.Close();

解决方案

Try these:
Creating PDF Tables using C# (.NET 2.0) and iTextSharp[^]
Create Table In PDF using C# And iTextSharp[^]
iTextSharp - Introducing Tables[^]
Create A PDF To Show Document In Table Format Using C# - BurnIgnorance[^]


这篇关于如何使用iTextsharp在单元格中生成PDF格式的报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆