IRONSOFTWAREHOME

如何在C#中使用IronPDF進行OpenAI處理PDF

Curtis Chau
Curtis Chau
Updated: 2026年6月29日

IronPDF的AI擴展啟用OpenAI驅動的PDF增強功能於C#應用程式中。 使用Microsoft Semantic Kernel增加摘要、查詢和備份功能,所需程式碼極少。

OpenAI是一個AI研究實驗室,開發先進的人工智慧技術。 它提供通過API存取的強大語言模型,使開發者能夠將AI能力整合到他們的應用程式中。

IronPdf.Extensions.AI NuGet包將OpenAI帶入PDF處理:摘要、查詢和備份。 基於Microsoft Semantic Kernel,此SDK在.NET應用程式中簡化AI服務整合。 自動從PDF文件中提取見解、回答問題並生成摘要。

關鍵使用案例包括處理大量文件、從報告中提取資訊、建立快速審核摘要以及構建智能文件管理系統。 整合支持一次性摘要和持續查詢,適用於各種應用。 欲了解更多PDF功能,請瀏覽IronPDF的全面文件或瞭解從HTML建立PDF。

快速開始:使用IronPDF和OpenAI總結PDF

開始將OpenAI整合到您的PDF處理工作流程中,使用IronPDF在C#中。 此範例演示如何使用少量程式碼快速生成PDF摘要。

  1. 1Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. 2複製並運行這段程式碼片段。

    // Install-Package IronPdf.Extensions.AI
    await IronPdf.AI.PdfAIEngine.Summarize("input.pdf", "summary.txt", azureEndpoint, azureApiKey);
    C#
  3. 3部署以在您的實時環境中測試

    今天就開始在您的專案中使用IronPDF,透過免費試用
    arrow pointer

所需的包:

在實現AI功能之前,設置Azure OpenAI。 您需要Azure訂閱和Azure OpenAI服務存取權限。 該服務為生產應用程式提供企業級安全和合規性。 詳盡的說明請參閱IronPDF安裝概述。

我如何用OpenAI總結PDF?

要使用OpenAI功能,配置您的Semantic Kernel及Azure端點和API密鑰。 匯入PDF文件,並使用Summarize方法生成摘要。

摘要功能適用於各種型別的PDF:

  • 掃描文件(結合OCR使用)
  • 含有多列的複雜佈局
  • 包含圖片和表格的文件

IronPDF提取文字內容並通過AI模型處理。 不同格式參見DOCX轉PDF或Markdown轉PDF。

請注意: 注意:您可能會遇到SKEXP0050錯誤,因為Semantic Kernel方法是實驗性的。 將此新增到您的.csproj文件以抑制它們:
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <NoWarn>$(NoWarn);SKEXP0001,SKEXP0010,SKEXP0050</NoWarn>
  </PropertyGroup>
</Project>
XML

下面是如何在C#中使用Semantic Kernel對PDF進行摘要:

using IronPdf;
using IronPdf.AI;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Microsoft.SemanticKernel.Memory;
using System;
using System.Threading.Tasks;

// Setup OpenAI
var azureEndpoint = "<<enter your azure endpoint here>>";
var apiKey = "<<enter your azure API key here>>";
var builder = Kernel.CreateBuilder()
    .AddAzureOpenAITextEmbeddingGeneration("oaiembed", azureEndpoint, apiKey)
    .AddAzureOpenAIChatCompletion("oaichat", azureEndpoint, apiKey);
var kernel = builder.Build();

// Setup Memory
var memory_builder = new MemoryBuilder()
    // optionally use new ChromaMemoryStore("http://127.0.0.1:8000") (see https://github.com/microsoft/semantic-kernel/blob/main/dotnet/notebooks/09-memory-with-chroma.ipynb)
    .WithMemoryStore(new VolatileMemoryStore())
    .WithAzureOpenAITextEmbeddingGeneration("oaiembed", azureEndpoint, apiKey);
var memory = memory_builder.Build();

// Initialize IronAI
IronDocumentAI.Initialize(kernel, memory);

License.LicenseKey = "<<enter your IronPdf license key here";

// Import PDF document
PdfDocument pdf = PdfDocument.FromFile("wikipedia.pdf");

// Summarize the document
Console.WriteLine("Please wait while I summarize the document...");
string summary = await pdf.Summarize(); // optionally pass AI instance or use AI instance directly
Console.WriteLine($"Document summary: {summary}\n\n");

程式碼初始化Semantic Kernel和記憶儲存。 記憶儲存在持續查詢中維持上下文。 選擇如下:

  • VolatileMemoryStore:用於開發和測試的記憶體儲存
  • ChromaMemoryStore:用於生產的持久矢量資料庫
  • 其他儲存:Azure認知搜索、Qdrant等

用於生產時,實現錯誤處理,並新增自定義日誌記錄來追蹤AI操作。 探索異步和多執行緒來同時處理多個文件。

摘要輸出看起來如何?

Visual Studio除錯控制台顯示流行網站技術棧的PDF摘要,包括語言和資料庫

摘要提供了簡明的文件概覽,提取了主要主題、重要事實和相關細節。 AI模型識別並優先考慮重要內容,使您快速理解冗長文件。

我如何持續查詢PDF?

單次查詢不適合所有情境。 IronPdf.Extensions.AI套件提供Query方法以進行持續查詢。 構建會話介面、研究工具或文件分析應用,其中使用者可對同一文件提出多次問題。

持續查詢保持會話上下文,允許後續問題和澄清。 理想用於:

  • 客戶支持系統參照文件
  • 法律文件分析需要條款解釋
  • 教育應用程式用於研究複雜材料
  • 研究工具提取特定資訊

為增強處理,考慮分別提取文字和圖片或實施PDF壓縮,以優化大型文件在AI處理前的狀態。

using IronPdf;
using IronPdf.AI;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Microsoft.SemanticKernel.Memory;
using System;
using System.Threading.Tasks;

// Setup OpenAI
var azureEndpoint = "<<enter your azure endpoint here>>";
var apiKey = "<<enter your azure API key here>>";
var builder = Kernel.CreateBuilder()
    .AddAzureOpenAITextEmbeddingGeneration("oaiembed", azureEndpoint, apiKey)
    .AddAzureOpenAIChatCompletion("oaichat", azureEndpoint, apiKey);
var kernel = builder.Build();

// Setup Memory
var memory_builder = new MemoryBuilder()
    // optionally use new ChromaMemoryStore("http://127.0.0.1:8000") (see https://github.com/microsoft/semantic-kernel/blob/main/dotnet/notebooks/09-memory-with-chroma.ipynb)
    .WithMemoryStore(new VolatileMemoryStore())
    .WithAzureOpenAITextEmbeddingGeneration("oaiembed", azureEndpoint, apiKey);
var memory = memory_builder.Build();

// Initialize IronAI
IronDocumentAI.Initialize(kernel, memory);

License.LicenseKey = "<<enter your IronPdf license key here";

// Import PDF document
PdfDocument pdf = PdfDocument.FromFile("wikipedia.pdf");

// Continuous query
while (true)
{
    Console.Write("User Input: ");
    var response = await pdf.Query(Console.ReadLine());
    Console.WriteLine($"\n{response}");
}

持續查詢系統使用嵌入技術理解問題語義,提供準確、有上下文的回應。 每次查詢都針對文件內容進行處理,由AI保持會話歷史,以提供日益相關的答案。

為了在處理大型文件或同時出現多個使用者時獲得最佳性能,實施快取策略,並探索IronPDF的性能優化技術。 考慮速率限制以及適當的授權金鑰管理,以進行生產部署。

處理敏感文件時,實施適當的安全措施。 在AI處理前後,IronPDF提供各種安全和加密選項以保護PDF。

常見問題

PDF 處理的 AI 擴展的目的是什麼?

IronPdf.Extensions.AI NuGet 套件使得在 C# 應用中啟用 OpenAI 驅動的 PDF 增強。它允許您使用 Microsoft Semantic Kernel 為您的 PDF 新增摘要、查詢和記憶功能,使用最少的程式碼,自動從文件中提取見解並回答問題。

AI 驅動的 PDF 處理的主要使用案例是什麼?

IronPDF 的 AI 擴展非常適合處理大量文件、從報告中提取資訊、建立快速審核摘要和建立智能的文件管理系統。整合支持單次摘要和連續查詢以用於各種應用。

如何快速使用 OpenAI 摘要 PDF?

using IronPDF 的 AI 擴展,您可以僅用一行程式碼就能摘要任何 PDF:await IronPdf.AI.PdfAIEngine.Summarize("input.pdf", "summary.txt", azureEndpoint, azureApiKey)。這種簡單的實現使得從 PDF 文件生成摘要變得容易。

我需要安裝哪些套件來進行 AI PDF 處理?

要實現 IronPDF 的 AI 功能,您需要三個套件:IronPdf(主要的 PDF 程式庫)、IronPdf.Extensions.AI(AI 擴展)和 Microsoft.SemanticKernel.Plugins.Memory(用於語義 kernel 功能)。

using OpenAI 與 PDF 之前的先決條件是什麼?

在使用 IronPDF 實現 AI 功能之前,您需要通過具有 Azure OpenAI 服務存取權限的 Azure 訂閱設置 Azure OpenAI。該服務提供企業級的安全性和生產應用的合規性,並需要 Azure 結點和 API 金鑰。

AI PDF 處理的最小工作流程是什麼?

using IronPDF 的最小工作流程由 5 個步驟組成:1)下載 C# 程式庫,2)準備 Azure 結點和 API 金鑰,3)匯入目標 PDF 文件,4)使用 Summarize 方法生成摘要,5)使用 Query 方法進行連續查詢。

AI 擴展如何與 Microsoft Semantic Kernel 整合?

IronPDF 的 AI 擴展基於 Microsoft Semantic Kernel 構建,其簡化了 .NET 應用中的 AI 服務整合。該 SDK 處理與 OpenAI 服務連接的複雜性,並提供針對 PDF 的 AI 操作的簡單 API。

How does IronPDF ensure security when handling sensitive PDF documents?

IronPDF offers various security and encryption options to protect PDFs, including permissions and password protection. These options help secure documents before and after AI processing, ensuring sensitive information is safeguarded.

What is the role of Microsoft Semantic Kernel in IronPDF's AI extension?

Microsoft Semantic Kernel is the foundation for IronPDF's AI extension, facilitating the integration of AI services in .NET applications. It powers features like summarization and querying by providing structured support for OpenAI capabilities.

How can I optimize performance when using IronPDF's AI features?

For optimal performance with IronPDF's AI features, consider caching strategies, implementing rate limiting, and using optimized deployment configurations. The documentation also suggests techniques for managing performance with large documents and concurrent users.

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

...
閱讀更多

準備開始了嗎?

Nuget Downloads 21,105,021版本:2026.9剛剛發布

立即獲取您的免費30天試用密鑰。
不需要信用卡或建立賬戶
C# 用於PDF的NuGet程式庫
使用NuGet安裝

版本: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. 在解決方案資源管理器,右鍵點選參考,管理NuGet包
  2. 選擇瀏覽並搜尋"IronPdf"
  3. 選擇套件並安裝
C# PDF DLL
下載DLL

版本: 2026.9

或者點擊此處下載Windows安裝程式。

  1. 下載並解壓IronPDF到類似~/Libs的位置,位於您的解決方案目錄中
  2. 在Visual Studio解決方案資源管理器,右鍵點選參考。選擇瀏覽,"IronPdf.dll"

授權從$999起

有問題嗎?聯絡我們的開發團隊。

Key in blue circle

立即免費取得 30 天試用金鑰。

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

OR
bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
預訂您的免費現場演示
Booking Badge

受到全球數百萬工程師的信任

Iron Software的客戶標誌
獲取您的無義務諮詢
填寫以下表格或電子郵件sales@ironsoftware.com
您的詳細資訊將始終保密。
受到全球數百萬工程師的信任
Iron Software的客戶標誌
立即獲取您的30天試用金鑰。
無需信用卡或帳戶建立
C# 用於PDF的NuGet程式庫
使用NuGet安裝

版本: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. 在解決方案資源管理器,右鍵點選參考,管理NuGet包
  2. 選擇瀏覽並搜尋"IronPdf"
  3. 選擇套件並安裝
C# PDF DLL
下載DLL

版本: 2026.9

或者點擊此處下載Windows安裝程式。

  1. 下載並解壓IronPDF到類似~/Libs的位置,位於您的解決方案目錄中
  2. 在Visual Studio解決方案資源管理器,右鍵點選參考。選擇瀏覽,"IronPdf.dll"

授權從$999起