惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
博客园 - 【当耐特】
月光博客
月光博客
Vercel News
Vercel News
D
Docker
I
InfoQ
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 叶小钗
MongoDB | Blog
MongoDB | Blog
GbyAI
GbyAI
有赞技术团队
有赞技术团队
雷峰网
雷峰网
博客园 - 聂微东
小众软件
小众软件
Y
Y Combinator Blog
腾讯CDC
L
LangChain Blog
The GitHub Blog
The GitHub Blog
宝玉的分享
宝玉的分享
Stack Overflow Blog
Stack Overflow Blog
大猫的无限游戏
大猫的无限游戏
T
The Blog of Author Tim Ferriss

Inside Nutrient

A guide to the invisible work behind documents Introducing Nutrient Documents for Salesforce: Native document generation and signing Document AI vs. traditional OCR: Choosing between OCR, AI, and hybrid pipelines PDF SDK compliance and security evaluation checklist for enterprise teams (2026) Invariant Corp replaces paper processes with Nutrient Workflow and scales without limits What is process mapping? A complete guide Nutrient vs. Conga Composer for Salesforce document generation (2026) Document routing: How to automate document distribution The CTO’s AI playbook: Why accountability architecture beats orchestration Compliance workflow automation: Why built-in compliance is table stakes Workflow diagrams: Examples, symbols, and how to build one that actually runs Digital forms: Replace paper forms with automated workflows Approval workflow software: How to automate approvals Why document-centric automation is different The CEO’s AI playbook: Why decision architecture beats model selection Nutrient SDK product updates for Q1 2026 PDF redaction verification: How to prove sensitive data is permanently removed What is a VPAT? The complete guide to accessibility conformance reports What is PDF/UA? The accessible PDF standard explained Salesforce eSignatures: Generate, sign, and track documents in one flow Online document viewer: Options, tradeoffs, and how to embed one Document viewer for web apps: React, Vue, Angular (2026) Best document viewers in 2026: A buyer’s guide How to edit a PDF in Python: Add text, images, and annotations Nutrient advances Workflow platform with agentic AI for enterprise-grade speed and consistency in document-heavy operations How to create a Salesforce quote template from opportunity data The business case for accessibility: Five ways it drives enterprise value Python PDF library comparison (2026): 7 libraries for developers Why your AI agent hallucinates PDF table data PDF.js limitations: When to upgrade to a commercial PDF SDK
Key-value pair extraction from PDF documents
Marija Trpkovic · 2024-05-31 · via Inside Nutrient

Table of contents

    Key-value pair extraction from PDF documents

    One of the key changes introduced in Muhimbi PDF Converter Services v11.0 is the inclusion of key-value pair (KVP) extraction from PDF documents. This feature takes advantage of AI, machine learning (ML), and advanced layout understanding to extract meaningful information from unstructured documents and images.

    The Muhimbi Document Converter Diagnostics Tool, installed along the service, can help you discover these new features.

    Key-Value Pair extraction with the Diagnostics Tool

    This post provides a simple example describing how to take advantage of this new feature programmatically.

    Key-value pair extraction offers numerous benefits for businesses and developers:

    Automated data extraction — Automate the tedious process of extracting data from documents, reducing manual labor and human error. Enhanced accuracy — Utilize AI PDF data extraction and ML technologies to ensure high accuracy in data extraction, even from complex and unstructured documents. Save time — Significantly speed up data processing times by automating extraction tasks that would otherwise take hours to complete manually. Versatile integration — Integrate with various applications and services, enhancing the functionality and efficiency of existing systems. Improved data handling — Ensure consistent and structured data output, making it easier to handle, analyze, and utilize extracted information.

    This tutorial shows how to create a .NET Framework console application and extract key-value pairs from a PDF document.

    1. Download and install Muhimbi PDF Converter or Muhimbi PDF Converter Services from our website.
    2. Create a new Console Application project in Visual Studio called KVPExtraction. The actual version of the .NET Framework isn’t important, as Web Services are system-agnostic, meaning they can be used by client applications written in a wide variety of programming languages.
    3. In the Solution Explorer window, right-click the project and select Add > Service Reference. Set the Address field to https://localhost:41734/Muhimbi.DocumentConverter.WebService/ and click Go. Define your desired namespace (in this case, DocumentConverterService) and click OK. This will generate the required proxy classes to be able to work with the Web Service.

    Service Reference

    1. In your Program.cs file, add the following code:

    using KVPExtraction.DocumentConverterService;

    using System;

    using System.IO;

    using System.ServiceModel;

    namespace KVPExtraction

    {

    class Program

    {

    // The URL where the Web Service is located. Amend host name if needed.

    static string SERVICE_URL = "https://localhost:41734/Muhimbi.DocumentConverter.WebService/";

    static void Main(string[] args)

    {

    DocumentConverterServiceClient client = null;

    try

    {

    // Determine the source file and read it into a byte array.

    string sourceFileName = null;

    if (args.Length == 0)

    {

    // If nothing is specified then read the first PDF file from the current folder.

    string[] sourceFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.pdf");

    if (sourceFiles.Length > 0)

    sourceFileName = sourceFiles[0];

    else

    {

    Console.WriteLine("Please specify a document to extract key-value pairs from.");

    Console.ReadKey();

    return;

    }

    }

    else

    sourceFileName = args[0];

    string expectedKeys = null;

    if (args.Length > 1)

    {

    // The second argument is the expected keys file. Read its content.

    expectedKeys = File.ReadAllText(args[1]);

    }

    else

    {

    // Uncomment the line below if you wish to use the following expected keys.

    //expectedKeys = "[{\"expectedKey\":\"grand total\",\"synonyms\":[\"total\"]},{\"expectedKey\":\"invoice number\",\"synonyms\":[\"invoice no.\"]}]";

    }

    byte[] sourceFile = File.ReadAllBytes(sourceFileName);

    // Open the service and configure the bindings.

    client = OpenService(SERVICE_URL);

    // Set the absolute minimum open options.

    OpenOptions openOptions = new OpenOptions();

    openOptions.OriginalFileName = Path.GetFileName(sourceFileName);

    openOptions.FileExtension = Path.GetExtension(sourceFileName);

    // Set the parameters for extracting key-value pairs.

    KVPSettings kvpSettings = new KVPSettings()

    {

    // Specify whether or not the internal image should be automatically rotated.

    AutoRotate = BooleanEnum.True,

    // Only include results with a confidence higher than the threshold (in %).

    ConfidenceThreshold = 50,

    // Specify virtual resolution for retrieving data. Higher values will make the process more accurate but slower.

    DPI = 300,

    // Specify the expected keys or leave empty to resolve all pairs.

    // Please note that extra information isn't included when `ExpectedKeys` is used.

    ExpectedKeys = expectedKeys,

    // Specify whether or not the confidence value for the extracted key-value pair should be included in the result.

    IncludeConfidence = BooleanEnum.True,

    // Specify whether or not the bounding box information for the key should be included.

    IncludeKeyBoundingBox = BooleanEnum.True,

    // Specify whether or not the page number the pair was found on should be included.

    IncludePageNumber = BooleanEnum.True,

    // Specify whether or not the type of the value should be included.

    IncludeType = BooleanEnum.True,

    // Specify whether or not the bounding box of the value should be included.

    IncludeValueBoundingBox = BooleanEnum.True,

    // Specify the desired output format (XML, JSON, or CSV).

    KVPFormat = KVPOutputFormat.CSV,

    // Specify the language used for OCR.

    OCRLanguage = "eng",

    // Specify the range of pages to search on.

    PageRange = null,

    // Specify whether or not extra symbols should be trimmed from values.

    TrimSymbols = BooleanEnum.False

    };

    Console.WriteLine("Extracting key-value pairs.");

    // Carry out the extraction.

    byte[] result = client.ExtractKeyValuePairs(sourceFile, openOptions, kvpSettings);

    if (result != null)

    {

    string destinationFileName = Path.GetFileNameWithoutExtension(sourceFileName) + "." + kvpSettings.KVPFormat;

    using (FileStream fs = File.Create(destinationFileName))

    {

    fs.Write(result, 0, result.Length);

    fs.Close();

    }

    Console.WriteLine("Result saved into " + destinationFileName);

    }

    else

    {

    Console.WriteLine("Nothing returned.");

    }

    Console.WriteLine("Finished.");

    }

    catch (FaultException<WebServiceFaultException> ex)

    {

    Console.WriteLine("FaultException occurred: ExceptionType: " +

    ex.Detail.ExceptionType.ToString());

    }

    catch (Exception ex)

    {

    Console.WriteLine(ex.ToString());

    }

    finally

    {

    CloseService(client);

    }

    Console.ReadKey();

    }

    /// <summary>

    /// Configure the bindings and endpoints and open the service using the specified address.

    /// </summary>

    /// <returns>An instance of the Web Service.</returns>

    public static DocumentConverterServiceClient OpenService(string address)

    {

    DocumentConverterServiceClient client = null;

    try

    {

    BasicHttpBinding binding = new BasicHttpBinding();

    // Use standard Windows Security.

    binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;

    binding.Security.Transport.ClientCredentialType =

    HttpClientCredentialType.Windows;

    // Increase the client Timeout to deal with (very) long running requests.

    binding.SendTimeout = TimeSpan.FromMinutes(120);

    binding.ReceiveTimeout = TimeSpan.FromMinutes(120);

    // Set the maximum document size to 50MB.

    binding.MaxReceivedMessageSize = 50 * 1024 * 1024;

    binding.ReaderQuotas.MaxArrayLength = 50 * 1024 * 1024;

    binding.ReaderQuotas.MaxStringContentLength = 50 * 1024 * 1024;

    // Specify an identity (any identity) to get it past .net3.5 sp1.

    EndpointIdentity epi = EndpointIdentity.CreateUpnIdentity("unknown");

    EndpointAddress epa = new EndpointAddress(new Uri(address), epi);

    client = new DocumentConverterServiceClient(binding, epa);

    client.Open();

    return client;

    }

    catch (Exception)

    {

    CloseService(client);

    throw;

    }

    }

    /// <summary>

    /// Check if the client is open and then close it.

    /// </summary>

    /// <param name="client">The client to close.</param>

    public static void CloseService(DocumentConverterServiceClient client)

    {

    if (client != null && client.State == CommunicationState.Opened)

    client.Close();

    }

    }

    }

    Sample input

    When the program above is executed on the PDF document and expected keys JSON below, it retrieves values for the expected keys and their synonyms.

    PDF document

    Here’s an example of how the PDF document looks.

    Sample input PDF

    Expected keys

    Here are the expected keys:

    [

    {

    "expectedKey": "grand total",

    "synonyms": ["total"]

    },

    {

    "expectedKey": "invoice number",

    "synonyms": ["invoice no."]

    }

    ]

    Sample output

    Note: The expectedKey property from the JSON above is used as the key property in the output.

    Sample csv output

    Conclusion

    By leveraging Muhimbi PDF Converter Services’ new key-value pair extraction feature, you can streamline data extraction processes, reduce manual labor, and ensure high accuracy and consistency in your data handling workflows. Whether you’re processing invoices, forms, or any other documents, this feature can greatly enhance your document management system’s efficiency and effectiveness.

    Explore related topics

    Try for free Ready to get started?

    Related Low-Code articles

    Explore more