跳過到頁腳內容
使用IRONPDF

如何在 ASP.NET 中從數據庫顯示 PDF

介紹

在 ASP.NET 應用程式中管理 PDF 文件通常需要將 PDF 文件直接儲存在資料庫中,而不是檔案系統中。 這種方法提供了更好的安全性、集中式備份和簡化的部署。 然而,如果沒有合適的工具,從資料庫中檢索和顯示 PDF 文件可能會很困難。

將 PDF 檔案作為二進位資料儲存在資料庫表中,可以更好地控製文件的存取和版本控制。 當您需要向使用者顯示 PDF 文件時,必須有效率地從資料庫中檢索位元組數組並將其呈現在瀏覽器中。 IronPDF 透過其強大的 API 簡化了在 ASP.NET 應用程式中處理 PDF 文件的整個過程。

本教學課程示範如何使用 IronPDF 的強大功能,在 ASP.NET 中顯示資料庫中的 PDF 檔案。 您將學習如何建立一個完整的解決方案,用於上傳、儲存和顯示 PDF 文件,並實現最佳效能和安全性。

前提條件和設置

在實現 PDF 顯示功能之前,請確保您的 ASP.NET 專案已安裝 IronPDF。 在 Visual Studio 的解決方案資源管理器中開啟程式包管理器控制台,然後執行:

Install-Package IronPdf

您的資料庫表結構需要一個varbinary(max)欄位來將 PDF 檔案儲存為二進位資料。 為了更好地管理文檔,表格應包含文件名稱、上傳日期和文件大小等元資料欄位。 以下是用於設定環境的程式碼:

using IronPdf;
using System.Data.SqlClient;
using System.IO;
using IronPdf;
using System.Data.SqlClient;
using System.IO;
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

web.config檔案中配置連接字串以建立資料庫連線。 PDF 檢視器實作將使用此連接從資料庫中檢索上傳的文件,並無縫顯示 PDF 內容。

建立資料庫表

首先建立一個專門用於儲存PDF文件的資料庫表。 表結構應同時容納二進位資料和必要的元資料:

CREATE TABLE PdfDocuments (
    Id INT PRIMARY KEY IDENTITY(1,1),
    FileName NVARCHAR(255) NOT NULL,
    FileData VARBINARY(MAX) NOT NULL,
    ContentType NVARCHAR(100) DEFAULT 'application/pdf',
    FileSize INT,
    UploadDate DATETIME DEFAULT GETDATE()
);

該表將每個 PDF 檔案以位元組數組的形式儲存在FileData列中。 varbinary(max)資料類型可以儲存最大 2GB 的文件,足以滿足大多數 PDF 文件的需求。 FileName欄位保留原始檔案名,以便顯示和下載。

檢索 PDF 文件時,可以考慮在經常查詢的列上新增索引,以提高效能。 以下程式碼在UploadDate列上建立索引:

CREATE INDEX IX_PdfDocuments_UploadDate 
ON PdfDocuments(UploadDate DESC);

這種結構確保了上傳文件的高效儲存和檢索,同時保持了根據需要添加其他元資料欄位的靈活性。

將PDF檔案上傳到資料庫

使用 ASP.NET 的FileUpload控制項實作上傳功能。 將以下 HTML 標記新增至您的 .aspx 頁面中,例如新增至表單元素:

<div>
    <asp:FileUpload ID="FileUpload1" runat="server" />
    <asp:Button ID="btnUpload" Text="Upload PDF" 
                OnClick="btnUpload_Click" runat="server" />
    <asp:Label ID="lblMessage" runat="server" />
</div>
<div>
    <asp:FileUpload ID="FileUpload1" runat="server" />
    <asp:Button ID="btnUpload" Text="Upload PDF" 
                OnClick="btnUpload_Click" runat="server" />
    <asp:Label ID="lblMessage" runat="server" />
</div>
HTML

範例 UI 輸出

如何在 ASP.NET 中顯示資料庫中的 PDF 檔案:圖 1 - 範例 UI

上傳按鈕會觸發伺服器端事件處理程序。 以下是上傳函數的完整實現,該函數將上傳的檔案從指定的檔案路徑轉換為位元組數組並儲存。 我們將編寫處理 POST 請求的邏輯:

protected void btnUpload_Click(object sender, EventArgs e)
{
    if (FileUpload1.HasFile && FileUpload1.PostedFile.ContentType == "application/pdf")
    {
        string fileName = FileUpload1.FileName;
        byte[] fileBytes = FileUpload1.FileBytes;
        // Connection string is retrieved from web.config
        string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
        using (SqlConnection conn = new SqlConnection(constr))
        {
            string query = "INSERT INTO PdfDocuments (FileName, FileData, FileSize) " +
                           "VALUES (@FileName, @FileData, @FileSize)";
            using (SqlCommand cmd = new SqlCommand(query, conn))
            {
                cmd.Parameters.AddWithValue("@FileName", fileName);
                cmd.Parameters.AddWithValue("@FileData", fileBytes);
                cmd.Parameters.AddWithValue("@FileSize", fileBytes.Length);
                conn.Open();
                cmd.ExecuteNonQuery();
            }
        }
        lblMessage.Text = "PDF document uploaded successfully!";
        LoadPdfList(); // Refresh the list after upload
    }
    else
    {
        lblMessage.Text = "Please select a valid PDF file.";
    }
}
protected void btnUpload_Click(object sender, EventArgs e)
{
    if (FileUpload1.HasFile && FileUpload1.PostedFile.ContentType == "application/pdf")
    {
        string fileName = FileUpload1.FileName;
        byte[] fileBytes = FileUpload1.FileBytes;
        // Connection string is retrieved from web.config
        string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
        using (SqlConnection conn = new SqlConnection(constr))
        {
            string query = "INSERT INTO PdfDocuments (FileName, FileData, FileSize) " +
                           "VALUES (@FileName, @FileData, @FileSize)";
            using (SqlCommand cmd = new SqlCommand(query, conn))
            {
                cmd.Parameters.AddWithValue("@FileName", fileName);
                cmd.Parameters.AddWithValue("@FileData", fileBytes);
                cmd.Parameters.AddWithValue("@FileSize", fileBytes.Length);
                conn.Open();
                cmd.ExecuteNonQuery();
            }
        }
        lblMessage.Text = "PDF document uploaded successfully!";
        LoadPdfList(); // Refresh the list after upload
    }
    else
    {
        lblMessage.Text = "Please select a valid PDF file.";
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

這段程式碼會在上傳文件前驗證文件類型,確保資料庫中只儲存 PDF 文件。 位元組數組轉換透過FileBytes屬性自動完成。

帶有上傳檔案的使用者介面

如何在 ASP.NET 中顯示資料庫中的 PDF 檔案:圖 2 - 範例 UI,其中包含已上傳到我們資料庫的 PDF 文件

使用 IronPDF 檢索和顯示 PDF 文檔

IronPDF 擅長渲染從資料庫擷取的 PDF 文件。 該庫提供了多種在瀏覽器中顯示 PDF 內容的選項。 首先,從資料庫表中檢索二進位資料:

private void LoadPdfList()
{
    string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
    using (SqlConnection conn = new SqlConnection(constr))
    {
        string query = "SELECT Id, FileName, FileSize, UploadDate FROM PdfDocuments ORDER BY UploadDate DESC";
        using (SqlCommand cmd = new SqlCommand(query, conn))
        {
            conn.Open();
            GridView1.DataSource = cmd.ExecuteReader();
            GridView1.DataBind();
        }
    }
}

// Helper method to retrieve PDF data from the database
private PdfData GetPdfFromDatabase(int id)
{
    byte[] pdfBytes = null;
    string filename = "";
    string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
    using (SqlConnection conn = new SqlConnection(constr))
    {
        string query = "SELECT FileData, FileName FROM PdfDocuments WHERE Id = @Id";
        using (SqlCommand cmd = new SqlCommand(query, conn))
        {
            cmd.Parameters.AddWithValue("@Id", id);
            conn.Open();
            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                if (reader.Read())
                {
                    // Retrieve binary data
                    pdfBytes = (byte[])reader["FileData"];
                    filename = reader["FileName"].ToString();
                }
            }
        }
    }
    if (pdfBytes != null)
    {
        return new PdfData { Bytes = pdfBytes, FileName = filename };
    }
    return null;
}

// ----------------- GridView Command Handlers -----------------
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "ViewPdf")
    {
        int documentId = Convert.ToInt32(e.CommandArgument);
        ViewPdfDocument(documentId);
    }
    else if (e.CommandName == "Download Pdf")
    {
        int documentId = Convert.ToInt32(e.CommandArgument);
        DownloadPdfDocument(documentId);
    }
}
private void ViewPdfDocument(int id)
{
    var pdfData = GetPdfFromDatabase(id);
    if (pdfData != null)
    {
        IronPdf.PdfDocument pdf;
        using (var stream = new System.IO.MemoryStream(pdfData.Bytes))
        {
            pdf = new IronPdf.PdfDocument(stream);
        }
        // Configure response to display inline in the browser
        Response.Clear();
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", $"inline; filename={pdfData.FileName}");
        Response.BinaryWrite(pdf.BinaryData);
        Response.End();
    }
}
private void LoadPdfList()
{
    string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
    using (SqlConnection conn = new SqlConnection(constr))
    {
        string query = "SELECT Id, FileName, FileSize, UploadDate FROM PdfDocuments ORDER BY UploadDate DESC";
        using (SqlCommand cmd = new SqlCommand(query, conn))
        {
            conn.Open();
            GridView1.DataSource = cmd.ExecuteReader();
            GridView1.DataBind();
        }
    }
}

// Helper method to retrieve PDF data from the database
private PdfData GetPdfFromDatabase(int id)
{
    byte[] pdfBytes = null;
    string filename = "";
    string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
    using (SqlConnection conn = new SqlConnection(constr))
    {
        string query = "SELECT FileData, FileName FROM PdfDocuments WHERE Id = @Id";
        using (SqlCommand cmd = new SqlCommand(query, conn))
        {
            cmd.Parameters.AddWithValue("@Id", id);
            conn.Open();
            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                if (reader.Read())
                {
                    // Retrieve binary data
                    pdfBytes = (byte[])reader["FileData"];
                    filename = reader["FileName"].ToString();
                }
            }
        }
    }
    if (pdfBytes != null)
    {
        return new PdfData { Bytes = pdfBytes, FileName = filename };
    }
    return null;
}

// ----------------- GridView Command Handlers -----------------
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "ViewPdf")
    {
        int documentId = Convert.ToInt32(e.CommandArgument);
        ViewPdfDocument(documentId);
    }
    else if (e.CommandName == "Download Pdf")
    {
        int documentId = Convert.ToInt32(e.CommandArgument);
        DownloadPdfDocument(documentId);
    }
}
private void ViewPdfDocument(int id)
{
    var pdfData = GetPdfFromDatabase(id);
    if (pdfData != null)
    {
        IronPdf.PdfDocument pdf;
        using (var stream = new System.IO.MemoryStream(pdfData.Bytes))
        {
            pdf = new IronPdf.PdfDocument(stream);
        }
        // Configure response to display inline in the browser
        Response.Clear();
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", $"inline; filename={pdfData.FileName}");
        Response.BinaryWrite(pdf.BinaryData);
        Response.End();
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

SQL 命令的參數對於安全地檢索特定 PDF 檔案至關重要。 ViewPdfDocument方法隨後負責將文件串流回客戶端。

查看已上傳的PDF文件

如何在 ASP.NET 中顯示資料庫中的 PDF 檔案:圖 3 - 已上傳的 PDF 檔案顯示

IronPDF&#39;s PDF 檢視器功能不僅限於簡單的顯示。 您可以在渲染之前對 PDF 文件進行編輯:

// Add watermark before displaying
pdf.ApplyWatermark("<h2>CONFIDENTIAL</h2>", rotation: 30, opacity: 50);
// Convert specific pages to images for preview
var previewImage = pdf.RasterizeToImageFiles("preview*.png", 1, 3);
// Add watermark before displaying
pdf.ApplyWatermark("<h2>CONFIDENTIAL</h2>", rotation: 30, opacity: 50);
// Convert specific pages to images for preview
var previewImage = pdf.RasterizeToImageFiles("preview*.png", 1, 3);
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

查看帶有浮水印的 PDF 文件

如何在 ASP.NET 中顯示資料庫中的 PDF 檔案:圖 4

PDF 檢視器支援功能強大。為了更好地與網頁整合並控制內容的顯示寬度,請使用 CSS 和 JavaScript 在對話方塊或新標籤頁中開啟文檔,並將其居中顯示在螢幕上。

<script type="text/javascript">
    function openPdfInNewTab(documentId) {
        // This generates a simple HTTP GET request to a handler URL
        window.open('/PdfHandler.ashx?id=' + documentId, '_blank');
    }
</script>
<script type="text/javascript">
    function openPdfInNewTab(documentId) {
        // This generates a simple HTTP GET request to a handler URL
        window.open('/PdfHandler.ashx?id=' + documentId, '_blank');
    }
</script>
HTML

完整工作範例:ASP.NET C# 中的 PDF 檢視器

以下是一個綜合範例程式碼,它整合了所有元件,可建立一個功能齊全的系統,用於管理資料庫中的 PDF 檔案:

using IronPdf;
using System;
using System.Configuration; // Required for ConfigurationManager
using System.Data.SqlClient;
using System.IO;
using System.Web.UI.WebControls;

namespace PdfDatabaseViewer
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadPdfList();
            }
            License.LicenseKey = "Your-License-Key";
        }

        // ----------------- Upload Functionality -----------------
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile && FileUpload1.PostedFile.ContentType == "application/pdf")
            {
                string fileName = FileUpload1.FileName;
                byte[] fileBytes = FileUpload1.FileBytes;
                // Connection string is retrieved from web.config
                string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
                using (SqlConnection conn = new SqlConnection(constr))
                {
                    string query = "INSERT INTO PdfDocuments (FileName, FileData, FileSize) " +
                                   "VALUES (@FileName, @FileData, @FileSize)";
                    using (SqlCommand cmd = new SqlCommand(query, conn))
                    {
                        cmd.Parameters.AddWithValue("@FileName", fileName);
                        cmd.Parameters.AddWithValue("@FileData", fileBytes);
                        cmd.Parameters.AddWithValue("@FileSize", fileBytes.Length);
                        conn.Open();
                        cmd.ExecuteNonQuery();
                    }
                }
                lblMessage.Text = "PDF document uploaded successfully!";
                LoadPdfList(); // Refresh the list after upload
            }
            else
            {
                lblMessage.Text = "Please select a valid PDF file.";
            }
        }

        // ----------------- Data Retrieval and List Display -----------------
        private void LoadPdfList()
        {
            string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            using (SqlConnection conn = new SqlConnection(constr))
            {
                string query = "SELECT Id, FileName, FileSize, UploadDate FROM PdfDocuments ORDER BY UploadDate DESC";
                using (SqlCommand cmd = new SqlCommand(query, conn))
                {
                    conn.Open();
                    GridView1.DataSource = cmd.ExecuteReader();
                    GridView1.DataBind();
                }
            }
        }

        // Helper method to retrieve PDF data from the database
        private PdfData GetPdfFromDatabase(int id)
        {
            byte[] pdfBytes = null;
            string filename = "";
            string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            using (SqlConnection conn = new SqlConnection(constr))
            {
                string query = "SELECT FileData, FileName FROM PdfDocuments WHERE Id = @Id";
                using (SqlCommand cmd = new SqlCommand(query, conn))
                {
                    cmd.Parameters.AddWithValue("@Id", id);
                    conn.Open();
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            // Retrieve binary data
                            pdfBytes = (byte[])reader["FileData"];
                            filename = reader["FileName"].ToString();
                        }
                    }
                }
            }
            if (pdfBytes != null)
            {
                return new PdfData { Bytes = pdfBytes, FileName = filename };
            }
            return null;
        }

        // ----------------- GridView Command Handlers -----------------
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "ViewPdf")
            {
                int documentId = Convert.ToInt32(e.CommandArgument);
                ViewPdfDocument(documentId);
            }
            else if (e.CommandName == "Download Pdf")
            {
                int documentId = Convert.ToInt32(e.CommandArgument);
                DownloadPdfDocument(documentId);
            }
        }

        private void ViewPdfDocument(int id)
        {
            var pdfData = GetPdfFromDatabase(id);
            if (pdfData != null)
            {
                IronPdf.PdfDocument pdf;
                using (var stream = new System.IO.MemoryStream(pdfData.Bytes))
                {
                    pdf = new IronPdf.PdfDocument(stream);
                }
                pdf.ApplyWatermark("<h2 style='color:red'>CONFIDENTIAL</h2>", rotation: 30, opacity: 50);

                // Configure response to display inline in the browser
                Response.Clear();
                Response.ContentType = "application/pdf";
                Response.AddHeader("content-disposition", $"inline; filename={pdfData.FileName}");
                Response.BinaryWrite(pdf.BinaryData);
                Response.End();
            }
        }

        private void DownloadPdfDocument(int id)
        {
            var pdfData = GetPdfFromDatabase(id);
            if (pdfData != null)
            {
                // Configure response to force a download/save prompt
                Response.Clear();
                Response.ContentType = "application/pdf";
                Response.AddHeader("content-disposition", $"attachment; filename={pdfData.FileName}");
                Response.BinaryWrite(pdfData.Bytes);
                Response.End();
            }
        }
    }
}

// Helper class must be outside the Default class
public class PdfData
{
    public byte[] Bytes { get; set; }
    public string FileName { get; set; }
}
using IronPdf;
using System;
using System.Configuration; // Required for ConfigurationManager
using System.Data.SqlClient;
using System.IO;
using System.Web.UI.WebControls;

namespace PdfDatabaseViewer
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadPdfList();
            }
            License.LicenseKey = "Your-License-Key";
        }

        // ----------------- Upload Functionality -----------------
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile && FileUpload1.PostedFile.ContentType == "application/pdf")
            {
                string fileName = FileUpload1.FileName;
                byte[] fileBytes = FileUpload1.FileBytes;
                // Connection string is retrieved from web.config
                string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
                using (SqlConnection conn = new SqlConnection(constr))
                {
                    string query = "INSERT INTO PdfDocuments (FileName, FileData, FileSize) " +
                                   "VALUES (@FileName, @FileData, @FileSize)";
                    using (SqlCommand cmd = new SqlCommand(query, conn))
                    {
                        cmd.Parameters.AddWithValue("@FileName", fileName);
                        cmd.Parameters.AddWithValue("@FileData", fileBytes);
                        cmd.Parameters.AddWithValue("@FileSize", fileBytes.Length);
                        conn.Open();
                        cmd.ExecuteNonQuery();
                    }
                }
                lblMessage.Text = "PDF document uploaded successfully!";
                LoadPdfList(); // Refresh the list after upload
            }
            else
            {
                lblMessage.Text = "Please select a valid PDF file.";
            }
        }

        // ----------------- Data Retrieval and List Display -----------------
        private void LoadPdfList()
        {
            string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            using (SqlConnection conn = new SqlConnection(constr))
            {
                string query = "SELECT Id, FileName, FileSize, UploadDate FROM PdfDocuments ORDER BY UploadDate DESC";
                using (SqlCommand cmd = new SqlCommand(query, conn))
                {
                    conn.Open();
                    GridView1.DataSource = cmd.ExecuteReader();
                    GridView1.DataBind();
                }
            }
        }

        // Helper method to retrieve PDF data from the database
        private PdfData GetPdfFromDatabase(int id)
        {
            byte[] pdfBytes = null;
            string filename = "";
            string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            using (SqlConnection conn = new SqlConnection(constr))
            {
                string query = "SELECT FileData, FileName FROM PdfDocuments WHERE Id = @Id";
                using (SqlCommand cmd = new SqlCommand(query, conn))
                {
                    cmd.Parameters.AddWithValue("@Id", id);
                    conn.Open();
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            // Retrieve binary data
                            pdfBytes = (byte[])reader["FileData"];
                            filename = reader["FileName"].ToString();
                        }
                    }
                }
            }
            if (pdfBytes != null)
            {
                return new PdfData { Bytes = pdfBytes, FileName = filename };
            }
            return null;
        }

        // ----------------- GridView Command Handlers -----------------
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "ViewPdf")
            {
                int documentId = Convert.ToInt32(e.CommandArgument);
                ViewPdfDocument(documentId);
            }
            else if (e.CommandName == "Download Pdf")
            {
                int documentId = Convert.ToInt32(e.CommandArgument);
                DownloadPdfDocument(documentId);
            }
        }

        private void ViewPdfDocument(int id)
        {
            var pdfData = GetPdfFromDatabase(id);
            if (pdfData != null)
            {
                IronPdf.PdfDocument pdf;
                using (var stream = new System.IO.MemoryStream(pdfData.Bytes))
                {
                    pdf = new IronPdf.PdfDocument(stream);
                }
                pdf.ApplyWatermark("<h2 style='color:red'>CONFIDENTIAL</h2>", rotation: 30, opacity: 50);

                // Configure response to display inline in the browser
                Response.Clear();
                Response.ContentType = "application/pdf";
                Response.AddHeader("content-disposition", $"inline; filename={pdfData.FileName}");
                Response.BinaryWrite(pdf.BinaryData);
                Response.End();
            }
        }

        private void DownloadPdfDocument(int id)
        {
            var pdfData = GetPdfFromDatabase(id);
            if (pdfData != null)
            {
                // Configure response to force a download/save prompt
                Response.Clear();
                Response.ContentType = "application/pdf";
                Response.AddHeader("content-disposition", $"attachment; filename={pdfData.FileName}");
                Response.BinaryWrite(pdfData.Bytes);
                Response.End();
            }
        }
    }
}

// Helper class must be outside the Default class
public class PdfData
{
    public byte[] Bytes { get; set; }
    public string FileName { get; set; }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

此實作方案包含錯誤處理和驗證功能,以確保強大的 PDF 文件管理。 原始碼演示了處理二進位資料和檔案操作的最佳實踐。

結論

使用 IronPDF,實現 ASP.NET 從資料庫顯示 PDF 檔案的功能變得非常簡單。 該庫能夠處理 PDF 文件渲染的複雜性,同時提供豐富的自訂選項。 從簡單的顯示場景到複雜的文件操作,IronPDF 提供了在 ASP.NET 應用程式中進行專業 PDF 管理所需的工具。

本文介紹的技術為建立強大的文件管理系統奠定了堅實的基礎。 IronPDF 的全面 API 確保您的應用程式能夠有效率地處理各種與 PDF 相關的需求,從基本的文件上傳和儲存到進階渲染和操作功能。

準備好在您的 ASP.NET 應用程式中實現專業的 PDF 功能了嗎? 立即開始 IronPDF 的免費試用,體驗無縫 PDF 管理的強大功能。 對於生產環境部署,請了解我們靈活的授權選項,這些選項可根據您的需求進行擴展。

常見問題解答

在 ASP.NET 中從資料庫顯示 PDF 的主要重點是什麼?

主要重點是為開發人員提供有效的方法,在 ASP.NET Web 應用程式中直接從資料庫顯示 PDF,增強專案的功能和使用者體驗。

IronPDF 如何幫助在 ASP.NET 中顯示資料庫中的 PDF?

IronPDF for .NET 可提供強大的函式庫,讓開發人員從資料庫儲存中無縫渲染 PDF,確保順利整合至 ASP.NET 應用程式,從而簡化流程。

使用 IronPDF 在 ASP.NET 中顯示 PDF 有哪些優點?

使用 IronPDF 具有容易整合、高品質渲染以及支援各種 PDF 功能等優點,可大幅提升 ASP.NET 應用程式的可用性與效能。

IronPDF 能否高效處理資料庫中的大型 PDF 檔案?

是的,IronPDF 旨在高效處理大型 PDF 檔案,確保快速載入和渲染時間,這對於維持應用程式效能至關重要。

是否可以在 ASP.NET 中使用 IronPDF 自訂 PDF 顯示?

絕對的,IronPDF 提供各種客製化選項,讓開發人員可以在 ASP.NET 環境中,依據自己的特定需求量身打造 PDF 顯示。

IronPDF 可在 ASP.NET 應用程式中將哪些檔案格式轉換為 PDF?

IronPDF 支援將 HTML、圖片等各種檔案格式轉換成 PDF,對於 ASP.NET 應用程式中的動態內容生成特別有用。

IronPDF 是否支援 ASP.NET 應用程式的安全 PDF 處理?

是的,IronPDF for .NET 支援安全的 PDF 處理,包括加密和密碼保護,有助於保護 ASP.NET 應用程式中的敏感資訊。

IronPDF 是否可以與其他 Iron Software 產品整合以增強功能?

是的,IronPDF 可與 IronOCR 和 IronBarcode 等其他 Iron Software 產品整合,為 ASP.NET 應用程式中的文件管理和處理提供全面的解決方案。

Curtis Chau
技術作家

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。