2024年5月1日 星期三

[研究]ASP.NET,試用FreeSpire.PDF 8.6.0、10.2.0 產生 .pdf 檔案

[研究]ASP.NET,試用FreeSpire.PDF 8.6.0、10.2.0 產生 .pdf 檔案

2024-04-30

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019 + SQL Server Management Studio (SSMS) 19

********************************************************************************

NuGet Gallery | FreeSpire.PDF
https://www.nuget.org/packages/FreeSpire.PDF

Free .NET PDF API - Developing PDF in C#, VB.NET, ASP.NET
https://www.e-iceblue.com/Introduce/free-pdf-component.html

授權 License

Free Spire.PDF for .NET is a Community Edition of the Spire.PDF for .NET, which is a totally free PDF API for commercial and personal use. As a standalone .NET library, Free Spire.PDF for .NET enables developers to create, write, edit, convert, print, handle and read PDF files on any .NET( C#, VB.NET, ASP.NET, .NET Core) applications.

Free version is limited to 10 pages of PDF. This limitation is enforced during writing PDF. When converting PDF to Image, XPS, Word, HTML, you can only get the first 3 pages of file. We don't provide technical or any other support to the users of the free versions.

********************************************************************************




Default.aspx

<asp:Button ID="btnGeneratePDF" runat="server" Text="Generate PDF" OnClick="btnGeneratePDF_Click" />

Default.aspx.cs

using Spire.Pdf;    // PdfDocument 使用
using Spire.Pdf.Graphics;   // PdfFont 使用
using System;
using System.Drawing;   // PointF 使用

protected void btnGeneratePDF_Click(object sender, EventArgs e)
{
    // 創建 PDF 文件
    PdfDocument doc = new PdfDocument();

    // 添加頁面
    PdfPageBase page = doc.Pages.Add();

    // 繪製文字到頁面
    page.Canvas.DrawString("Hello, World!", new PdfFont(PdfFontFamily.Helvetica, 20f), PdfBrushes.Black, new PointF(100, 100));

    // 儲存 PDF
    string filePath = Server.MapPath("~/GeneratedPDFs/Example.pdf");
    doc.SaveToFile(filePath);
    doc.Close();

    // 下載 PDF
    Response.ContentType = "application/pdf";
    Response.AppendHeader("Content-Disposition", "attachment; filename=Example.pdf");
    Response.TransmitFile(filePath);
    Response.End();
}




實際測試,FreeSpire.PDF 8.6.0 此測試程式可用,

把 FreeSpire.PDF 8.6.0 升級到 FreeSpire.PDF 10.2.0 後,也可使用。

(完)

相關

[研究]ASP.NET,試用FreeSpire.PDF 8.6.0、10.2.0 產生 .pdf 檔案
https://shaurong.blogspot.com/2024/05/aspnetfreespirepdf-8601020.html

[研究][C#][ASP.NET] 使用 FreeSpire.Doc 12.2.0 取代 .docx 中的文字
https://shaurong.blogspot.com/2024/05/caspnet-freespiredoc-1220-docx.html

[研究][C#][ASP.NET] 使用 FreeSpire.Doc 12.2.0 把 .docx 轉成 .pdf
https://shaurong.blogspot.com/2024/05/caspnet-freespiredoc-1220-docx-pdf.html

[研究]FreeSpire.PDF 6.2.60 升級 7.8.9 後出錯,warning CS0618: 'PdfTextFind.Bounds' 已經過時: 'This property may be removed in the future, please use TextBounds instead.'
https://shaurong.blogspot.com/2021/08/warning-cs0618-pdftextfindbounds-this.html

[研究][C#][ASP.NET] 使用 FreeSpire.Doc 7.11.0 取代 .docx 中的文字
https://shaurong.blogspot.com/2020/06/caspnet-freespiredoc-7110-docx.html

[研究][C#][ASP.NET] 使用 Free Spire.PDF for NET v6.2.0 取代 .pdf 中的文字
https://shaurong.blogspot.com/2020/06/caspnet-free-spirepdf-for-net-v620-pdf.html

[研究][C#][ASP.NET] 使用 FreeSpire.Doc 7.11.0 把 .docx 轉成 .pdf
https://shaurong.blogspot.com/2020/06/caspnet-spiredoc-docx-pdf.html

[研究][C#][ASP.NET] 免費 Free Spire.PDF for .NET 3.2.0 試用 Url to pdf 檔案 (NuGet 安裝)
https://shaurong.blogspot.com/2018/03/aspnet-free-spirepdf-for-net-pdf.html

[研究][C#][ASP.NET] 免費 PDFsharp v1.32.3057.0 產生 pdf 試用 (NuGet 安裝)
https://shaurong.blogspot.com/2018/03/caspnet-pdfsharp-v13230570-pdf-nuget.html

沒有留言:

張貼留言