How to use OpenAI for PDF

This article was translated from English: Does it need improvement?
Translated
View the article in English
class="container-fluid">
class="row">
class="col-md-2"> Chatgpt related to How to use OpenAI for PDF

OpenAI 是一個人工智慧研究實驗室,由營利性公司 OpenAI LP 和其非營利母公司 OpenAI Inc 組成。成立的目的是為促進數位智能的發展,以造福全人類。 OpenAI 在人工智慧 (AI) 的各個領域進行研究,目標是開發安全、有益且可獲得的 AI 技術。

IronPdf.Extensions.AI NuGet 套件現在支持 PDF 增強功能:摘要、查詢和記憶。 該套件利用了 Microsoft Semantic Kernel

快速入門:使用 IronPDF 和 OpenAI 總結 PDFs

開始將 OpenAI 整合到您的 PDF 處理工作流程中,使用 IronPDF 和 C#。 這個簡單的例子展示了如何快速生成 PDF 文件的摘要。 只需幾行代碼,就能輕鬆利用 AI 增強您的 PDF 功能。

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. Copy and run this code snippet.

    // Install-Package IronPdf.Extensions.AI
    await IronPdf.AI.PdfAIEngine.Summarize("input.pdf", "summary.txt", azureEndpoint, azureApiKey);
  3. Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer
class="hsg-featured-snippet">

最小工作流程 (5 步驟)

  1. 下載 C# 庫以利用 OpenAI 運行 PDF
  2. 準備 Azure 端點和 OpenAI 的 API 密鑰
  3. 導入目標 PDF 文件
  4. 使用 Summarize 方法生成 PDF 的摘要
  5. 使用 Query 方法進行持續查詢


除了 IronPdf 套件,您還需要以下兩個套件:

總結 PDF 範例

要使用 OpenAI 功能,需要 Azure 端點和 API 密鑰。 參照下面的代碼範例配置語義內核。 導入 PDF 文件並利用 Summarize 方法生成 PDF 文件的摘要。 您可以從 OpenAI for PDF 總結範例 下載示例 PDF 文件。

請注意 注意:您可能會遇到 SKEXP0001、SKEXP0010 和 SKEXP0050 錯誤,因為語義內核方法是實驗性的。 將以下代碼添加到您的 .csproj 文件中以抑制這些錯誤:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <NoWarn>$(NoWarn);SKEXP0001,SKEXP0010,SKEXP0050</NoWarn>
  </PropertyGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <NoWarn>$(NoWarn);SKEXP0001,SKEXP0010,SKEXP0050</NoWarn>
  </PropertyGroup>
</Project>
XML

這是一個使用 C# 語義內核總結 PDF 的範例:

:path=/static-assets/pdf/content-code-examples/how-to/openai-summarize.cs
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");
Imports Microsoft.VisualBasic
Imports IronPdf
Imports IronPdf.AI
Imports Microsoft.SemanticKernel
Imports Microsoft.SemanticKernel.Connectors.OpenAI
Imports Microsoft.SemanticKernel.Memory
Imports System
Imports System.Threading.Tasks

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

' Setup Memory
Private memory_builder = (New MemoryBuilder()).WithMemoryStore(New VolatileMemoryStore()).WithAzureOpenAITextEmbeddingGeneration("oaiembed", azureEndpoint, apiKey)
Private memory = memory_builder.Build()

' Initialize IronAI
IronDocumentAI.Initialize(kernel, memory)

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

' Import PDF document
Dim pdf As PdfDocument = PdfDocument.FromFile("wikipedia.pdf")

' Summarize the document
Console.WriteLine("Please wait while I summarize the document...")
Dim summary As String = Await pdf.Summarize() ' optionally pass AI instance or use AI instance directly
Console.WriteLine($"Document summary: {summary}" & vbLf & vbLf)
$vbLabelText   $csharpLabel

輸出摘要

class="content-img-align-center">
class="center-image-wrapper"> 總結 PDF 文件

持續查詢範例

單次查詢可能不適合所有情況。 IronPdf.Extensions.AI 套件還提供一種查詢方法,允許用戶執行持續查詢。

:path=/static-assets/pdf/content-code-examples/how-to/openai-query.cs
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}");
}
Imports Microsoft.VisualBasic
Imports IronPdf
Imports IronPdf.AI
Imports Microsoft.SemanticKernel
Imports Microsoft.SemanticKernel.Connectors.OpenAI
Imports Microsoft.SemanticKernel.Memory
Imports System
Imports System.Threading.Tasks

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

' Setup Memory
Private memory_builder = (New MemoryBuilder()).WithMemoryStore(New VolatileMemoryStore()).WithAzureOpenAITextEmbeddingGeneration("oaiembed", azureEndpoint, apiKey)
Private memory = memory_builder.Build()

' Initialize IronAI
IronDocumentAI.Initialize(kernel, memory)

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

' Import PDF document
Dim pdf As PdfDocument = PdfDocument.FromFile("wikipedia.pdf")

' Continuous query
Do
	Console.Write("User Input: ")
	Dim response = Await pdf.Query(Console.ReadLine())
	Console.WriteLine($vbLf & "{response}")
Loop
$vbLabelText   $csharpLabel

常見問題解答

如何使用 OpenAI 在 C# 中增強 PDF 文件?

要在 C# 中增強 PDF 文檔,可以使用 `IronPdf.Extensions.AI` NuGet 套件,該套件借助 OpenAI 實現了摘要和查詢等功能。這需要使用 Azure 終端和 API 金鑰進行 OpenAI 整合。

在 C# 中將 OpenAI 與 PDF 處理整合需要哪些條件?

要將 OpenAI 與 C# 中的 PDF 處理集成,您需要 `IronPdf` 和 `IronPdf.Extensions.AI` 套件、Microsoft Semantic Kernel、Azure 終結點和 API 金鑰。

如何使用 OpenAI 在 C# 中對 PDF 文件進行摘要?

您可以使用 `IronPdf.Extensions.AI` 套件中的 `Summarize` 方法對 PDF 文件進行摘要。匯入您的 PDF 文檔,並提供您的 Azure 終結點和 API 金鑰來應用此方法。

我能否使用 C# 中的 AI 對 PDF 檔案執行連續查詢?

是的,您可以使用 `IronPdf.Extensions.AI` 套件中的 `Query` 方法對 PDF 執行連續查詢,從而可以從 PDF 文件中動態提取資訊。

如何抑制 C# 專案中的實驗性錯誤警告?

若要抑制諸如 SKEXP0001、SKEXP0010 和 SKEXP0050 之類的實驗性錯誤警告,請將以下程式碼新增至您的 .csproj 檔案: <NoWarn>$(NoWarn);SKEXP0001,SKEXP0010,SKEXP0050</NoWarn>

Microsoft Semantic Kenli 在 PDF 增強中扮演什麼角色?

Microsoft Semantic Kernel 用於設定和執行 PDF 文件上的 `Summarize` 和 `Query` 等方法,並透過 `IronPdf.Extensions.AI` 套件啟用 OpenAI 功能。

使用 OpenAI 進行 PDF 摘要生成有哪些好處?

使用 OpenAI 進行 PDF 摘要生成,可以針對大型文件生成簡潔的摘要,從而更輕鬆地快速提取關鍵資訊。這是透過 `IronPdf.Extensions.AI` 套件中的 `Summarize` 方法實現的。

使用 OpenAI 擴充功能時,IronPDF 是否相容於 .NET 10?

是的-IronPDF 完全相容於 .NET 10,`IronPdf.Extensions.AI` 套件無需特殊配置即可在 .NET 10 專案中運行。該程式庫支援 .NET 10 中引入的最新運行時改進和語言特性。

Curtis Chau
技術作家

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

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

準備好開始了嗎?
Nuget 下載 16,154,058 | 版本: 2025.11 剛剛發布