How to use OpenAI for PDF
OpenAI is an artificial intelligence research laboratory, consisting of the for-profit OpenAI LP and its non-profit parent company, OpenAI Inc. It was founded with the goal of advancing digital intelligence in a way that benefits humanity as a whole. OpenAI conducts research in various areas of artificial intelligence (AI) and aims to develop AI technologies that are safe, beneficial, and accessible.
The IronPdf.Extensions.AI
NuGet package now enables OpenAI for PDF enhancement: summarization, querying, and memorization. The package utilizes Microsoft Semantic Kernel.
Summarize any PDF with AI in just one line!
IronPdf.AI.PdfAIEngine.Summarize("input.pdf", "summary.txt", azureEndpoint, azureApiKey);
Get started with IronPDF
Start using IronPDF in your project today with a free trial.
How to use OpenAI for PDF
- Download the C# library to utilize OpenAI for PDF
- Prepare the Azure Endpoint and API Key for OpenAI
- Import the target PDF document
- Use the
Summarize
method to generate a summary of the PDF - Use the
Query
method for continuous querying
Besides the IronPdf package, you will also need the following two packages:
Summarize PDF Example
To use the OpenAI feature, an Azure Endpoint, and an API Key are needed. Configure the Semantic Kernel according to the code example below. Import the PDF document and utilize the Summarize
method to generate a summary of the PDF document. You can download the sample PDF file from the OpenAI for PDF Summarization Example.
Please note
<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>
Here is an example of how you can summarize a PDF using the Semantic Kernel in C#:
: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)
Output Summary

Continuous Query Example
A single query may not be suitable for all scenarios. The IronPdf.Extensions.AI
package also offers a Query method that allows users to perform continuous queries.
: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
Frequently Asked Questions
What is OpenAI?
OpenAI is an artificial intelligence research laboratory, consisting of the for-profit OpenAI LP and its non-profit parent company, OpenAI Inc. It aims to develop AI technologies that are safe, beneficial, and accessible.
How can I enhance PDF documents using AI in C#?
To enhance PDF documents using AI in C#, you can use the IronPDF C# library. Prepare the Azure Endpoint and API Key, import the target PDF document, and utilize methods like Summarize and Query for PDF enhancement.
What is the AI Extensions package for PDF?
The IronPdf.Extensions.AI NuGet package enables OpenAI functionalities for PDF documents such as summarization, querying, and memorization using Microsoft Semantic Kernel.
How do I summarize a PDF using AI?
To summarize a PDF, import the PDF document using the IronPDF library, and utilize the Summarize method provided by the IronPdf.Extensions.AI package.
What do I need to start using AI for PDF enhancements?
You need the IronPDF package, the IronPdf.Extensions.AI package, and Microsoft.SemanticKernel.Plugins.Memory. Additionally, an Azure Endpoint and API Key for OpenAI are required.
What is the Query method used for in PDF processing?
The Query method is used for performing continuous queries on a PDF document to extract information dynamically using the IronPdf.Extensions.AI package.
How do I handle experimental errors in my project?
To suppress SKEXP errors, add the following code to your .csproj file:
What is the purpose of using Microsoft Semantic Kernel with PDF?
Microsoft Semantic Kernel is utilized to configure and run methods like Summarize and Query for PDF documents, enabling OpenAI functionalities with the help of IronPDF.