如何从 ASP.Net Web 表单创建 pdf

发布于 2024-12-06 02:55:20 字数 91 浏览 0 评论 0原文

我开发了一个 ASP.Net 应用程序,并开发了一个包含一些条目的 Web 表单。现在我想把这个表格转换成PDF文件,可以吗?

有什么好的免费图书馆吗?

I have developed a ASP.Net application and I have developed a web Form with some entries. Now i want to convert this form into PDF file, is it possible ?

Any good and free library for this ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

养猫人 2024-12-13 02:55:20

要创建 pdf 文件,您可以使用 itextsharppdf 锐利

To create pdf file you can use itextsharp or pdf sharp

可可 2024-12-13 02:55:20

您可以使用 ITextSharp 等免费库,或者对于更复杂的情况,您可以使用 TxtControl 的服务器版本从网站生成文档。

TxtControl 还提供用于创建文档的 OnDemand 服务...

You can use free libraries such as ITextSharp or for more complex scenarios you can use the server version of TxtControl to generate documents from websites.

TxtControl also offers a OnDemand service for creating documents...

梦亿 2024-12-13 02:55:20

您可能会发现 Ghostscript 库很有用 http://www.ghostscript.com/

You may find the Ghostscript library useful http://www.ghostscript.com/

浅忆 2024-12-13 02:55:20
     Document doc = new Document(PageSize.A4);
   // Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=hello.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);

    PdfWriter.GetInstance(doc, Response.OutputStream);
    string imagepath = Server.MapPath("IMG");
    doc.Open();

    doc.Add(new Paragraph());
    Image gif = Image.GetInstance(imagepath + "/asd.jpg");
    doc.Add(gif);

    PdfPTable table1 = new PdfPTable(2);

    table1.WidthPercentage = 90;

    PdfPCell cell11 = new PdfPCell();

    cell11.AddElement(new Paragraph("Receipt ID : " + 124325));

    cell11.AddElement(new Paragraph("Date : " + "25-Feb-2013"));

    cell11.AddElement(new Paragraph("Photo Status : " + "No"));

    cell11.VerticalAlignment = Element.ALIGN_LEFT;

    PdfPCell cell12 = new PdfPCell();

    cell12.AddElement(new Paragraph("Transaction ID : " + 4544));

    cell12.AddElement(new Paragraph("Expected Date Of Delivery : " + "25-Feb-2013"));

    cell12.VerticalAlignment = Element.ALIGN_RIGHT;

    table1.AddCell(cell11);

    table1.AddCell(cell12);

    PdfPTable table2 = new PdfPTable(3);



    //One row added

    PdfPCell cell21 = new PdfPCell();

    cell21.AddElement(new Paragraph("Photo Type"));

    PdfPCell cell22 = new PdfPCell();

    cell22.AddElement(new Paragraph("No. of Copies"));

    PdfPCell cell23 = new PdfPCell();

    cell23.AddElement(new Paragraph("Amount"));

    table2.AddCell(cell21);

    table2.AddCell(cell22);

    table2.AddCell(cell23);



    //New Row Added

    PdfPCell cell31 = new PdfPCell();

    cell31.AddElement(new Paragraph("type"));

    cell31.FixedHeight = 300.0f;

    PdfPCell cell32 = new PdfPCell();

    cell32.AddElement(new Paragraph(5));

    cell32.FixedHeight = 300.0f;

    PdfPCell cell33 = new PdfPCell();

    cell33.AddElement(new Paragraph("20.00 *   noOfCopy  = " + (20 * Convert.ToInt32(5)) + ".00"));

    cell33.FixedHeight = 300.0f;



    table2.AddCell(cell31);

    table2.AddCell(cell32);

    table2.AddCell(cell33);



    PdfPCell cell2A = new PdfPCell(table2);

    cell2A.Colspan = 2;

    table1.AddCell(cell2A);

    PdfPCell cell41 = new PdfPCell();

    cell41.AddElement(new Paragraph("Name : " + "fdfgdg"));

    cell41.AddElement(new Paragraph("Advance : " + "245"));

    cell11.VerticalAlignment = Element.ALIGN_LEFT;

    PdfPCell cell42 = new PdfPCell();

    cell42.AddElement(new Paragraph("Customer ID : " + 34345));

    cell42.AddElement(new Paragraph("Balance : " + 20545));

    cell42.VerticalAlignment = Element.ALIGN_RIGHT;

    table1.AddCell(cell41);

    table1.AddCell(cell42);
    doc.Add(table1);

    doc.Close();


    //pdfDoc.Open();
    //htmlparser.Parse(sr);
    //pdfDoc.Close();
    Response.Write(doc);
    Response.End();
     Document doc = new Document(PageSize.A4);
   // Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=hello.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);

    PdfWriter.GetInstance(doc, Response.OutputStream);
    string imagepath = Server.MapPath("IMG");
    doc.Open();

    doc.Add(new Paragraph());
    Image gif = Image.GetInstance(imagepath + "/asd.jpg");
    doc.Add(gif);

    PdfPTable table1 = new PdfPTable(2);

    table1.WidthPercentage = 90;

    PdfPCell cell11 = new PdfPCell();

    cell11.AddElement(new Paragraph("Receipt ID : " + 124325));

    cell11.AddElement(new Paragraph("Date : " + "25-Feb-2013"));

    cell11.AddElement(new Paragraph("Photo Status : " + "No"));

    cell11.VerticalAlignment = Element.ALIGN_LEFT;

    PdfPCell cell12 = new PdfPCell();

    cell12.AddElement(new Paragraph("Transaction ID : " + 4544));

    cell12.AddElement(new Paragraph("Expected Date Of Delivery : " + "25-Feb-2013"));

    cell12.VerticalAlignment = Element.ALIGN_RIGHT;

    table1.AddCell(cell11);

    table1.AddCell(cell12);

    PdfPTable table2 = new PdfPTable(3);



    //One row added

    PdfPCell cell21 = new PdfPCell();

    cell21.AddElement(new Paragraph("Photo Type"));

    PdfPCell cell22 = new PdfPCell();

    cell22.AddElement(new Paragraph("No. of Copies"));

    PdfPCell cell23 = new PdfPCell();

    cell23.AddElement(new Paragraph("Amount"));

    table2.AddCell(cell21);

    table2.AddCell(cell22);

    table2.AddCell(cell23);



    //New Row Added

    PdfPCell cell31 = new PdfPCell();

    cell31.AddElement(new Paragraph("type"));

    cell31.FixedHeight = 300.0f;

    PdfPCell cell32 = new PdfPCell();

    cell32.AddElement(new Paragraph(5));

    cell32.FixedHeight = 300.0f;

    PdfPCell cell33 = new PdfPCell();

    cell33.AddElement(new Paragraph("20.00 *   noOfCopy  = " + (20 * Convert.ToInt32(5)) + ".00"));

    cell33.FixedHeight = 300.0f;



    table2.AddCell(cell31);

    table2.AddCell(cell32);

    table2.AddCell(cell33);



    PdfPCell cell2A = new PdfPCell(table2);

    cell2A.Colspan = 2;

    table1.AddCell(cell2A);

    PdfPCell cell41 = new PdfPCell();

    cell41.AddElement(new Paragraph("Name : " + "fdfgdg"));

    cell41.AddElement(new Paragraph("Advance : " + "245"));

    cell11.VerticalAlignment = Element.ALIGN_LEFT;

    PdfPCell cell42 = new PdfPCell();

    cell42.AddElement(new Paragraph("Customer ID : " + 34345));

    cell42.AddElement(new Paragraph("Balance : " + 20545));

    cell42.VerticalAlignment = Element.ALIGN_RIGHT;

    table1.AddCell(cell41);

    table1.AddCell(cell42);
    doc.Add(table1);

    doc.Close();


    //pdfDoc.Open();
    //htmlparser.Parse(sr);
    //pdfDoc.Close();
    Response.Write(doc);
    Response.End();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文