C# C、 Winform-创建PDF

C# C、 Winform-创建PDF,c#,winforms,visual-studio,pdf,C#,Winforms,Visual Studio,Pdf,我对编程还是有点陌生,但我想创建一个可以创建PDF的程序,其中包含一些信息 有人能推荐一种简洁的方法吗?我有点需要创建一个普通的A4纸页面,上面有一张桌子。。以及其他一些信息 可以从VisualStudio2010中创建它吗?或者我需要类似的插件吗 您可能希望使用一个库,例如,它将允许您以编程方式构建PDF文档 现在还不清楚从VisualStudio2010中创建它是什么意思-如果你期待一个视觉设计师,我想你会失望的;我不知道有什么能让你这么容易做到。但是,听起来您没有特别复杂的要求,因此编写代

我对编程还是有点陌生,但我想创建一个可以创建PDF的程序,其中包含一些信息

有人能推荐一种简洁的方法吗?我有点需要创建一个普通的A4纸页面,上面有一张桌子。。以及其他一些信息


可以从VisualStudio2010中创建它吗?或者我需要类似的插件吗

您可能希望使用一个库,例如,它将允许您以编程方式构建PDF文档


现在还不清楚从VisualStudio2010中创建它是什么意思-如果你期待一个视觉设计师,我想你会失望的;我不知道有什么能让你这么容易做到。但是,听起来您没有特别复杂的要求,因此编写代码来完成这项工作应该不会太难。

您可能希望使用一个库,例如,它可以让您以编程方式构建PDF文档


现在还不清楚从VisualStudio2010中创建它是什么意思-如果你期待一个视觉设计师,我想你会失望的;我不知道有什么能让你这么容易做到。但是,听起来您并没有特别复杂的需求,因此编写代码来完成它应该不会太难。

有几个库可用于此目的。以下是一些:


有几个图书馆可用于此目的。以下是一些:


我曾经使用iTextSharp合并和拆分pdf,但这些文件丢失了。但它是好的。关于你创建表格的需要,我认为你必须编写常规代码,然后你必须将它们转换成字节,然后用它创建一个pdf文件。正如我记得的那样,这是一种很好的工作方式。
希望能有所帮助。

我曾经使用iTextSharp合并和拆分pdf,但这些文件丢失了。但它是好的。关于你创建表格的需要,我认为你必须编写常规代码,然后你必须将它们转换成字节,然后用它创建一个pdf文件。正如我记得的那样,这是一种很好的工作方式。
希望能有所帮助。

正如@Jon Skeet所说的,您可以使用iTextSharp,它是Java iText的C端口

首先,当前是5.1.2,将itextsharp.dll提取到某个位置,并在Visual Studio中添加对它的引用。然后使用下面的代码,这是一个完整的WinForms应用程序,可以在A4文档中创建一个非常基本的表。更多解释请参见代码中的注释

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();
        }
    }
}

正如@jonskeet所说,您可以使用iTextSharp,它是javaitext的一个C端口

首先,当前是5.1.2,将itextsharp.dll提取到某个位置,并在Visual Studio中添加对它的引用。然后使用下面的代码,这是一个完整的WinForms应用程序,可以在A4文档中创建一个非常基本的表。更多解释请参见代码中的注释

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();
        }
    }
}

我只需要能够创建一个PDF文件,其中包含一个表。。如果可能的话,桌子上有一些看不见的边。这样看起来我所有的文字都在box@Mathias:嗯,我自己还没有用过iText,但我强烈怀疑这不会太麻烦…我只需要能够创建一个PDF文件,其中包含一个表。。如果可能的话,桌子上有一些看不见的边。这样看起来我所有的文字都在box@Mathias当前位置我自己还没用过iText,但我强烈怀疑这不会太费劲。。。。。。不要忘记,如果你打算在一个封闭源代码的应用程序中使用iTextSharp,你应该为它付费。。。。不要忘记,如果你打算在一个封闭源代码的应用程序中使用它,你应该为它支付额外的费用。@Just和Other程序员不知道你在问什么。。。SharpPDF是一个C库,它实现了用于创建PDF文档的不同对象。这是直接从SharpPDF网站获得的。@JustAndOther程序员不知道你在问什么。。。SharpPDF是一个C库,它实现了用于创建PDF文档的不同对象。这是直接从SharpPDF网站获得的。