如何使用IronPDF在C#中設定和編輯PDF中繼資料
IronPDF允許開發人員在C#應用程式中以程式化方式設定和編輯PDF中繼資料,包括標題、作者和關鍵字等標準屬性,以及自訂中繼資料欄位,以增強文件組織和可搜尋性。 無論您是在建構需要文件追蹤的企業應用程式、實施合規功能,或是組織您的PDF程式庫,IronPDF提供全面的中繼資料操作功能。 此功能可與IronPDF的HTML轉PDF功能和其他文件處理功能無縫整合。
快速入門:立即修改PDF中繼資料
使用IronPDF進行PDF中繼資料管理只需幾行程式碼。 載入您的PDF,更新如標題、作者或關鍵字等中繼資料,並保存您的變更。 本指南簡化了中繼資料的設定和編輯,確保您的文件組織良好且可搜尋。 按照這個簡單的方法提升您的PDF能力。
-
使用NuGet套件管理器安裝https://www.nuget.org/packages/IronPdf
-
複製並運行這段程式碼片段。
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"); -
部署以在您的實時環境中測試
今天就開始在您的專案中使用IronPDF,透過免費試用
最小工作流程 (5步)
- 下載IronPDF C#程式庫以進行PDF中繼資料編輯
- 載入現有的 PDF 或渲染一個新的
- 存取
MetaData屬性以設定和編輯PDF中繼資料 - 利用中繼資料字典進行有效的中繼資料處理
- 新增、編輯或移除自訂的PDF中繼資料屬性
我如何設定和編輯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")
我如何查看輸出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()
當我使用中繼資料字典時會發生什麼?
要查看文件的中繼資料,請點擊垂直的三個點,進入文件屬性。 中繼資料字典的方法在實施批量處理工作流程或標準化多個文件的中繼資料時特別有用。 對於高級文件管理場景,請考慮將其與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
我如何新增、編輯和移除自訂中繼資料?
除了一個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"
高級自訂中繼資料場景
在構建文件管理系統時,自訂中繼資料變得特別強大。 這是一個全面的例子,展示了實際使用情況:
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
我如何移除自訂中繼資料屬性?
以兩種方式從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")
介紹
PDF中繼資料作為文件管理系統的支柱,使組織、可搜尋和合規追蹤高效實施。 IronPDF的中繼資料功能不僅僅是簡單的屬性設定 - 它們提供了一個建構複雜文件工作流程的全面框架。 無論是為了可及性而實施PDF/UA合規文件,還是建立自訂追蹤系統,中繼資料管理都是至關重要的。
中繼資料管理的最佳實踐
- 一致性:為自訂中繼資料鍵建立命名約定
- 文件化:維護您的系統中使用的自訂中繼資料欄位的登記
- 驗證:設定中繼資料值前實施驗證規則
- 安全性:除非PDF已被加密,否則避免在中繼資料中儲存敏感資訊
- 合規:確保中繼資料符合您行業的監管要求
透過將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 表格建立和電子簽名。這讓它成為構建全面文件管理系統或合規功能的理想工具。

