C# 在windows窗体应用程序中写入pdf并打印
我正在用c#在windows窗体应用程序中开发一个账单管理系统。 在订单表单中,我必须生成pdf格式的发票,保存pdf并触发打印。C# 在windows窗体应用程序中写入pdf并打印,c#,winforms,pdf,C#,Winforms,Pdf,我正在用c#在windows窗体应用程序中开发一个账单管理系统。 在订单表单中,我必须生成pdf格式的发票,保存pdf并触发打印。 有两个按钮GenerateBill和GenerateBill&Print。当我单击GenerateBill&Print时,订单详细信息应保存在数据库中并打印pdf。我需要在windows窗体中创建pdf的代码。你想问个问题吗?很好,所以?至少从发布一个帖子开始。所以不是一个代码生成网站。欢迎来到stackoverflow。不幸的是,这个问题,就目前而言,是离题的,因
有两个按钮GenerateBill和GenerateBill&Print。当我单击GenerateBill&Print时,订单详细信息应保存在数据库中并打印pdf。我需要在windows窗体中创建pdf的代码。你想问个问题吗?很好,所以?至少从发布一个帖子开始。所以不是一个代码生成网站。欢迎来到stackoverflow。不幸的是,这个问题,就目前而言,是离题的,因为你没有提出一个明确的问题。这听起来更像是项目要求,而这不是一个征求代码编写的网站。祝你的项目好运,不管怎样,我们可以得到以下图像格式的pdf输出吗
using System;
using System.Text;
using System.Windows.Forms;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace Full_Profile1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//This is the absolute path to the PDF that we will create
string outputFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Sample.pdf");
//Create a standard .Net FileStream for the file, setting various flags
using (FileStream fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write, FileShare.None))
{
//Create a new PDF document setting the size to A4
using (Document doc = new Document(PageSize.A4))
{
//Bind the PDF document to the FileStream using an iTextSharp PdfWriter
using (PdfWriter w = PdfWriter.GetInstance(doc, fs))
{
//Open the document for writing
doc.Open();
//Create a table with two columns
PdfPTable t = new PdfPTable(2);
//Borders are drawn by the individual cells, not the table itself.
//Tell the default cell that we do not want a border drawn
t.DefaultCell.Border = 0;
//Add four cells. Cells are added starting at the top left of the table working left to right first, then down
t.AddCell("R1C1");
t.AddCell("R1C2");
t.AddCell("R2C1");
t.AddCell("R2C2");
//Add the table to our document
doc.Add(t);
//Close our document
doc.Close();
}
}
}
this.Close();
}
}
}