如何在 C# 中設定與編輯 PDF 中繼資料

如何使用IronPDF在C#中設定和編輯PDF中繼資料

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronPDF允許開發人員在C#應用程式中以程式化方式設定和編輯PDF中繼資料,包括標題、作者和關鍵字等標準屬性,以及自訂中繼資料欄位,以增強文件組織和可搜尋性。 無論您是在建構需要文件追蹤的企業應用程式、實施合規功能,或是組織您的PDF程式庫,IronPDF提供全面的中繼資料操作功能。 此功能可與IronPDF的HTML轉PDF功能和其他文件處理功能無縫整合。

快速入門:立即修改PDF中繼資料

使用IronPDF進行PDF中繼資料管理只需幾行程式碼。 載入您的PDF,更新如標題、作者或關鍵字等中繼資料,並保存您的變更。 本指南簡化了中繼資料的設定和編輯,確保您的文件組織良好且可搜尋。 按照這個簡單的方法提升您的PDF能力。

  1. 使用NuGet套件管理器安裝https://www.nuget.org/packages/IronPdf

    PM > Install-Package IronPdf
  2. 複製並運行這段程式碼片段。

    IronPdf.PdfDocument.FromFile("example.pdf")
        .MetaData = new IronPdf.PdfMetaData { 
            Title="MyDoc", Author="Me", Subject="Demo", Keywords="ironpdf,metadata", Creator="MyApp", Producer="IronPDF", CreationDate=DateTime.Today, ModifiedDate=DateTime.Now 
        }
        .SaveAs("updated_example.pdf");
  3. 部署以在您的實時環境中測試

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

    arrow pointer


我如何設定和編輯PDF中繼資料?

使用IronPDF時,在PDF中設定和編輯通用中繼資料欄位是很簡單的。 存取MetaData屬性以修改可用的中繼資料欄位。 此功能在處理PDF表單數位簽名或實施文件管理系統時特別有用。

:path=/static-assets/pdf/content-code-examples/how-to/metadata-set-edit.cs
using IronPdf;
using System;

ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Metadata</h1>");

// Access the MetaData class and set the pre-defined metadata properties.
pdf.MetaData.Author = "Iron Software";
pdf.MetaData.CreationDate = DateTime.Today;
pdf.MetaData.Creator = "IronPDF";
pdf.MetaData.Keywords = "ironsoftware,ironpdf,pdf";
pdf.MetaData.ModifiedDate = DateTime.Now;
pdf.MetaData.Producer = "IronPDF";
pdf.MetaData.Subject = "Metadata Tutorial";
pdf.MetaData.Title = "IronPDF Metadata Tutorial";

pdf.SaveAs("pdf-with-metadata.pdf");
Imports IronPdf
Imports System

Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Metadata</h1>")

' Access the MetaData class and set the pre-defined metadata properties.
pdf.MetaData.Author = "Iron Software"
pdf.MetaData.CreationDate = DateTime.Today
pdf.MetaData.Creator = "IronPDF"
pdf.MetaData.Keywords = "ironsoftware,ironpdf,pdf"
pdf.MetaData.ModifiedDate = DateTime.Now
pdf.MetaData.Producer = "IronPDF"
pdf.MetaData.Subject = "Metadata Tutorial"
pdf.MetaData.Title = "IronPDF Metadata Tutorial"

pdf.SaveAs("pdf-with-metadata.pdf")
$vbLabelText   $csharpLabel

我如何查看輸出PDF中的中繼資料?

要查看文件的中繼資料,請點擊垂直的三個點,進入文件屬性。 此中繼資料在文件組織中至關重要,尤其是在實施PDF/A合規文件以進行長期存檔時。

我如何設定和檢索中繼資料字典?

GetMetaDataDictionary方法檢索現有的中繼資料字典並存取儲存在文件中的中繼資料資訊。 SetMetaDataDictionary方法提供了一種重寫中繼資料字典的有效方式。 如果在通用中繼資料欄位中不存在某個鍵,該鍵將成為自訂中繼資料屬性。 此方法在合併多個PDF和整合來自不同來源的中繼資料時特別有用。

:path=/static-assets/pdf/content-code-examples/how-to/metadata-set-and-get-metadata-dictionary.cs
using IronPdf;
using System.Collections.Generic;

ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Metadata</h1>");

Dictionary<string, string> newMetadata = new Dictionary<string, string>();
newMetadata.Add("Title", "How to article");
newMetadata.Add("Author", "IronPDF");

// Set metadata dictionary
pdf.MetaData.SetMetaDataDictionary(newMetadata);

// Retreive metadata dictionary
Dictionary<string, string> metadataProperties = pdf.MetaData.GetMetaDataDictionary();
Imports IronPdf
Imports System.Collections.Generic

Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Metadata</h1>")

Dim newMetadata As New Dictionary(Of String, String)()
newMetadata.Add("Title", "How to article")
newMetadata.Add("Author", "IronPDF")

' Set metadata dictionary
pdf.MetaData.SetMetaDataDictionary(newMetadata)

' Retrieve metadata dictionary
Dim metadataProperties As Dictionary(Of String, String) = pdf.MetaData.GetMetaDataDictionary()
$vbLabelText   $csharpLabel

當我使用中繼資料字典時會發生什麼?

要查看文件的中繼資料,請點擊垂直的三個點,進入文件屬性。 中繼資料字典的方法在實施批量處理工作流程或標準化多個文件的中繼資料時特別有用。 對於高級文件管理場景,請考慮將其與PDF壓縮技術結合使用,以優化文件儲存。

在不同環境中處理中繼資料

在開發企業應用程式時,中繼資料在文件分類和檢索中扮演著關鍵角色。 這是一個實施全面中繼資料管理系統的例子:

using IronPdf;
using System;
using System.Collections.Generic;

public class PDFMetadataManager
{
    public static void ProcessBatchMetadata(List<string> pdfPaths)
    {
        foreach (string path in pdfPaths)
        {
            var pdf = PdfDocument.FromFile(path);

            // Standardize metadata across all documents
            pdf.MetaData.Producer = "Company Document System v2.0";
            pdf.MetaData.Creator = "IronPDF";

            // Add processing timestamp
            pdf.MetaData.ModifiedDate = DateTime.Now;

            // Add document classification
            var metadata = pdf.MetaData.GetMetaDataDictionary();
            metadata["DocumentType"] = "Internal Report";
            metadata["Department"] = "Finance";
            metadata["SecurityLevel"] = "Confidential";

            pdf.MetaData.SetMetaDataDictionary(metadata);
            pdf.SaveAs(path.Replace(".pdf", "_processed.pdf"));
        }
    }
}
using IronPdf;
using System;
using System.Collections.Generic;

public class PDFMetadataManager
{
    public static void ProcessBatchMetadata(List<string> pdfPaths)
    {
        foreach (string path in pdfPaths)
        {
            var pdf = PdfDocument.FromFile(path);

            // Standardize metadata across all documents
            pdf.MetaData.Producer = "Company Document System v2.0";
            pdf.MetaData.Creator = "IronPDF";

            // Add processing timestamp
            pdf.MetaData.ModifiedDate = DateTime.Now;

            // Add document classification
            var metadata = pdf.MetaData.GetMetaDataDictionary();
            metadata["DocumentType"] = "Internal Report";
            metadata["Department"] = "Finance";
            metadata["SecurityLevel"] = "Confidential";

            pdf.MetaData.SetMetaDataDictionary(metadata);
            pdf.SaveAs(path.Replace(".pdf", "_processed.pdf"));
        }
    }
}
Imports IronPdf
Imports System
Imports System.Collections.Generic

Public Class PDFMetadataManager
    Public Shared Sub ProcessBatchMetadata(pdfPaths As List(Of String))
        For Each path As String In pdfPaths
            Dim pdf = PdfDocument.FromFile(path)

            ' Standardize metadata across all documents
            pdf.MetaData.Producer = "Company Document System v2.0"
            pdf.MetaData.Creator = "IronPDF"

            ' Add processing timestamp
            pdf.MetaData.ModifiedDate = DateTime.Now

            ' Add document classification
            Dim metadata = pdf.MetaData.GetMetaDataDictionary()
            metadata("DocumentType") = "Internal Report"
            metadata("Department") = "Finance"
            metadata("SecurityLevel") = "Confidential"

            pdf.MetaData.SetMetaDataDictionary(metadata)
            pdf.SaveAs(path.Replace(".pdf", "_processed.pdf"))
        Next
    End Sub
End Class
$vbLabelText   $csharpLabel
Icon Quote related to 在不同環境中處理中繼資料

我最喜歡的程式庫是IronPDF。它允許快速高效地操作PDF文件。它還有許多有價值的功能,例如導出到PDF/A格式和數位簽署PDF文件。

Milan Jovanovic related to 在不同環境中處理中繼資料

Milan Jovanovic

Microsoft MVP

查看案例研究
Icon Quote related to 在不同環境中處理中繼資料

IronOCR意味著我們每年可以從手動處理中節省$40,000,同時提高生產力,釋放資源以進行高影響的任務。我會強烈推薦它。

Brent Matzelle related to 在不同環境中處理中繼資料

Brent Matzelle

首席技術官,OPYN

查看案例研究
Icon Quote related to 在不同環境中處理中繼資料

IronSuite在我們的運營中扮演著至關重要的角色。這些工具增加了包括建立平面圖和改善庫存管理在內的業務效率。

David Jones related to 在不同環境中處理中繼資料

David Jones

首席軟體工程師,Agorus Build

查看案例研究

我如何新增、編輯和移除自訂中繼資料?

除了一個PDF文件的標準中繼資料外,您還可以包含自訂中繼資料屬性。 這些自訂屬性通常不會在PDF查看器軟體中顯示,因為它們通常僅顯示通用中繼資料,且可能不會檢索所有現有的中繼資料屬性。 自訂中繼資料在實施PDF安全功能或建立專門的文件工作流程時尤為有價值。

我如何新增和編輯自訂中繼資料屬性?

要新增自訂中繼資料,請存取Add方法。 編輯自訂中繼資料需要將鍵值傳遞給CustomProperties屬性並重新賦值。 這一功能在需要追蹤表單提交中繼資料的PDF表單編輯場景中整合得很好。

:path=/static-assets/pdf/content-code-examples/how-to/metadata-custom-properties.cs
using IronPdf;
using IronPdf.MetaData;

ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Metadata</h1>");

PdfCustomMetadataProperties customProperties = pdf.MetaData.CustomProperties;

// Add custom property
customProperties.Add("foo", "bar"); // Key: foo, Value: bar

// Edit custom property
customProperties["foo"] = "baz";
Imports IronPdf
Imports IronPdf.MetaData

Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Metadata</h1>")

Dim customProperties As PdfCustomMetadataProperties = pdf.MetaData.CustomProperties

' Add custom property
customProperties.Add("foo", "bar") ' Key: foo, Value: bar

' Edit custom property
customProperties("foo") = "baz"
$vbLabelText   $csharpLabel

高級自訂中繼資料場景

在構建文件管理系統時,自訂中繼資料變得特別強大。 這是一個全面的例子,展示了實際使用情況:

using IronPdf;
using System;
using System.Linq;

public class DocumentTrackingSystem
{
    public static void AddTrackingMetadata(PdfDocument pdf, string userId, string projectId)
    {
        var customProps = pdf.MetaData.CustomProperties;

        // Add tracking information
        customProps.Add("ProcessedBy", userId);
        customProps.Add("ProcessedDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
        customProps.Add("ProjectID", projectId);
        customProps.Add("DocumentVersion", "1.0");
        customProps.Add("ReviewStatus", "Pending");

        // Add workflow metadata
        customProps.Add("WorkflowStep", "Initial Review");
        customProps.Add("NextReviewer", "John.Doe@company.com");
        customProps.Add("DueDate", DateTime.Now.AddDays(7).ToString("yyyy-MM-dd"));

        // Add compliance metadata
        customProps.Add("ComplianceChecked", "false");
        customProps.Add("RetentionPeriod", "7 years");
        customProps.Add("Classification", "Internal Use Only");
    }

    public static void UpdateReviewStatus(PdfDocument pdf, string status, string reviewer)
    {
        var customProps = pdf.MetaData.CustomProperties;

        // Update existing properties
        customProps["ReviewStatus"] = status;
        customProps["LastReviewedBy"] = reviewer;
        customProps["LastReviewDate"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

        // Increment version if approved
        if (status == "Approved" && customProps.ContainsKey("DocumentVersion"))
        {
            var currentVersion = customProps["DocumentVersion"];
            var versionParts = currentVersion.Split('.');
            var minorVersion = int.Parse(versionParts[1]) + 1;
            customProps["DocumentVersion"] = $"{versionParts[0]}.{minorVersion}";
        }
    }
}
using IronPdf;
using System;
using System.Linq;

public class DocumentTrackingSystem
{
    public static void AddTrackingMetadata(PdfDocument pdf, string userId, string projectId)
    {
        var customProps = pdf.MetaData.CustomProperties;

        // Add tracking information
        customProps.Add("ProcessedBy", userId);
        customProps.Add("ProcessedDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
        customProps.Add("ProjectID", projectId);
        customProps.Add("DocumentVersion", "1.0");
        customProps.Add("ReviewStatus", "Pending");

        // Add workflow metadata
        customProps.Add("WorkflowStep", "Initial Review");
        customProps.Add("NextReviewer", "John.Doe@company.com");
        customProps.Add("DueDate", DateTime.Now.AddDays(7).ToString("yyyy-MM-dd"));

        // Add compliance metadata
        customProps.Add("ComplianceChecked", "false");
        customProps.Add("RetentionPeriod", "7 years");
        customProps.Add("Classification", "Internal Use Only");
    }

    public static void UpdateReviewStatus(PdfDocument pdf, string status, string reviewer)
    {
        var customProps = pdf.MetaData.CustomProperties;

        // Update existing properties
        customProps["ReviewStatus"] = status;
        customProps["LastReviewedBy"] = reviewer;
        customProps["LastReviewDate"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

        // Increment version if approved
        if (status == "Approved" && customProps.ContainsKey("DocumentVersion"))
        {
            var currentVersion = customProps["DocumentVersion"];
            var versionParts = currentVersion.Split('.');
            var minorVersion = int.Parse(versionParts[1]) + 1;
            customProps["DocumentVersion"] = $"{versionParts[0]}.{minorVersion}";
        }
    }
}
Imports IronPdf
Imports System
Imports System.Linq

Public Class DocumentTrackingSystem
    Public Shared Sub AddTrackingMetadata(pdf As PdfDocument, userId As String, projectId As String)
        Dim customProps = pdf.MetaData.CustomProperties

        ' Add tracking information
        customProps.Add("ProcessedBy", userId)
        customProps.Add("ProcessedDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
        customProps.Add("ProjectID", projectId)
        customProps.Add("DocumentVersion", "1.0")
        customProps.Add("ReviewStatus", "Pending")

        ' Add workflow metadata
        customProps.Add("WorkflowStep", "Initial Review")
        customProps.Add("NextReviewer", "John.Doe@company.com")
        customProps.Add("DueDate", DateTime.Now.AddDays(7).ToString("yyyy-MM-dd"))

        ' Add compliance metadata
        customProps.Add("ComplianceChecked", "false")
        customProps.Add("RetentionPeriod", "7 years")
        customProps.Add("Classification", "Internal Use Only")
    End Sub

    Public Shared Sub UpdateReviewStatus(pdf As PdfDocument, status As String, reviewer As String)
        Dim customProps = pdf.MetaData.CustomProperties

        ' Update existing properties
        customProps("ReviewStatus") = status
        customProps("LastReviewedBy") = reviewer
        customProps("LastReviewDate") = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")

        ' Increment version if approved
        If status = "Approved" AndAlso customProps.ContainsKey("DocumentVersion") Then
            Dim currentVersion = customProps("DocumentVersion")
            Dim versionParts = currentVersion.Split("."c)
            Dim minorVersion = Integer.Parse(versionParts(1)) + 1
            customProps("DocumentVersion") = $"{versionParts(0)}.{minorVersion}"
        End If
    End Sub
End Class
$vbLabelText   $csharpLabel

我如何移除自訂中繼資料屬性?

以兩種方式從PDF文件中移除自訂中繼資料。 使用CustomProperties屬性。 這在對PDF進行清理以供公眾發佈或準備文件以供存檔時特別有用。

:path=/static-assets/pdf/content-code-examples/how-to/metadata-remove-custom-properties.cs
using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Metadata</h1>");

// Add custom property to be deleted
pdf.MetaData.CustomProperties.Add("willBeDeleted", "value");

// Remove custom property _ two ways
pdf.MetaData.RemoveMetaDataKey("willBeDeleted");
pdf.MetaData.CustomProperties.Remove("willBeDeleted");
Imports IronPdf

Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Metadata</h1>")

' Add custom property to be deleted
pdf.MetaData.CustomProperties.Add("willBeDeleted", "value")

' Remove custom property _ two ways
pdf.MetaData.RemoveMetaDataKey("willBeDeleted")
pdf.MetaData.CustomProperties.Remove("willBeDeleted")
$vbLabelText   $csharpLabel

介紹

PDF中繼資料作為文件管理系統的支柱,使組織、可搜尋和合規追蹤高效實施。 IronPDF的中繼資料功能不僅僅是簡單的屬性設定 - 它們提供了一個建構複雜文件工作流程的全面框架。 無論是為了可及性而實施PDF/UA合規文件,還是建立自訂追蹤系統,中繼資料管理都是至關重要的。

中繼資料管理的最佳實踐

  1. 一致性:為自訂中繼資料鍵建立命名約定
  2. 文件化:維護您的系統中使用的自訂中繼資料欄位的登記
  3. 驗證:設定中繼資料值前實施驗證規則
  4. 安全性:除非PDF已被加密,否則避免在中繼資料中儲存敏感資訊
  5. 合規:確保中繼資料符合您行業的監管要求

透過將IronPDF的中繼資料能力與數位簽名PDF加密等功能結合使用,您可以構建符合企業要求的強大文件管理解決方案。

準備好看看您還能做什麼嗎? 查看我們的教程頁面:簽署和保護PDF

常見問題

我如何在 C# 中設定 PDF 中繼資料屬性如標題和作者?

using IronPDF,您可以輕鬆地存取 PDF 文件的 MetaData 屬性來設定 PDF 中繼資料。只需指派一個包含如標題、作者、主題、關鍵字、創作者和日期的 PdfMetaData 物件。IronPDF 使程式化地更新這些標準中繼資料欄位變得簡單明瞭。

我可以為 PDF 新增超越標準屬性的自定中繼資料欄位嗎?

可以,IronPDF 支援透過中繼資料字典新增自定中繼資料欄位。使用 SetMetaDataDictionary 方法,您可以新增任何鍵值對於標準欄位以外的內容。如果鍵不符合通用中繼資料欄位,IronPDF 會自動將其視為自定中繼資料。

我如何從 PDF 文件中檢索現有的中繼資料?

IronPDF 提供 GetMetaDataDictionary 方法來檢索 PDF 文件中的所有現有中繼資料。此方法會返回一個字典,包含標準與自定中繼資料欄位,讓您能存取和處理儲存於文件中的中繼資料資訊。

有哪些標準中繼資料欄位可供編輯?

IronPDF 支援所有標準的 PDF 中繼資料欄位,包括標題、作者、主題、關鍵字、創作者、製作人、建立日期及修改日期。這些欄位可以透過 PdfMetaData 物件進行設置,是文件組織和可搜尋性的重要元素。

我如何在 PDF 中設置中繼資料後進行查看?

using IronPDF 設置中繼資料後,您可以在任何 PDF 閱讀器中見它。大多數的 PDF 檢視器中,只需點擊三個垂直點或前往檔案選單並選擇文件屬性即可查看所有中繼資料欄位,包括那些程式化設置的欄位。

中繼資料的操作可以與其他 PDF 操作結合在一起嗎?

完全可以!IronPDF 允許您將中繼資料編輯與其他功能相結合,例如 HTML 轉 PDF、PDF 表格建立和電子簽名。這讓它成為構建全面文件管理系統或合規功能的理想工具。

Curtis Chau
技術作家

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

除了開發,Curtis對物聯網(IoT)有濃厚的興趣,探索創新的方法來整合硬體和軟體。在空閒時間,他喜歡玩遊戲和建立Discord機器人,結合他對技術的熱愛與創造力。

準備開始了嗎?
Nuget 下載 19,936,792 | 版本: 2026.7 剛剛發布
Still Scrolling Icon

還在捲動嗎?

想快速獲得證明嗎? PM > Install-Package IronPdf
執行範例 看您的HTML變成PDF。