且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将数据从sql server数据库保存到PDF文件中

更新时间:2023-02-07 11:03:10

从以下位置获取 iTextsharp lib nuget 并获取数据.使用来自SQL Server的数据制作PDF.这是一些示例代码:

Get the iTextsharp lib from nuget and get the data. Make a PDF with the data from the SQL server. Here is some sample code:

FileStream fs = new FileStream(filename, FileMode.CreateNew);
Document doc = new Document(PageSize.A4);
PdfWriter pdfWriter = PdfWriter.GetInstance(doc, fs);
PdfPage page = new PdfPage();
pdfWriter.PageEvent = page;
doc.Open();
PdfContentByte cb = pdfWriter.DirectContent;
doc.Add(new Paragraph("the data from sql server:"));
pdfWriter.CloseStream = true;            
doc.Close();
fs.Close();

ps.这只是一个片段.这不是来自itextsharp的PDF文件所需的最少代码量.关于在C#中创建pdf以及使用C#和sql server进行数据访问,有足够的文档.显示一些代码,或为我们提供有关实际问题的更多详细信息.

ps. it is just a snippet. It is not the minimal amount of code required for a PDF file from itextsharp. There is enough documentation about pdf creation in C# and data access with C# and sql server. Show some code, or give us more detail about the actual problem.