使用PDFsharp从PDF获取元数据

时间:2014-02-20 06:17:40

标签: c# pdfsharp

如何使用PDFsharp从PDF获取元数据。请参阅图像。 我想提取“文档限制摘要”

private static void Method1(string strPDFAddress)
        {
            PdfDocument pdfDoc = new PdfDocument(strPDFAddress);

            Console.WriteLine("--------------------------------------------------------------");
            Console.WriteLine("File: {0}", strPDFAddress);
            Console.WriteLine("Author: {0}", pdfDoc.Info.Author);
            Console.WriteLine("CreationDate: {0}", pdfDoc.Info.CreationDate);
            Console.WriteLine("Creator: {0}", pdfDoc.Info.Creator);
            Console.WriteLine("Keywords: {0}", pdfDoc.Info.Keywords);

            PdfDocumentSettings pdfDocSettings = pdfDoc.Settings;
            Console.WriteLine(pdfDocSettings.ToString());

            PdfSecuritySettings pdfSecuritySettings = pdfDoc.SecuritySettings;
            Console.WriteLine(pdfSecuritySettings.PermitExtractContent);

            //PdfSharp.Pdf.Advanced.PdfFormXObject xObj = 

            PdfDictionary.DictionaryElements pdfDictionaryElements = pdfDoc.Info.Elements;
            Console.WriteLine(pdfDictionaryElements.ToString());
        }

enter image description here

2 个答案:

答案 0 :(得分:1)

试试这个

希望它有效。

PdfReader reader = new PdfReader("HelloWorldNoMetadata.pdf");

string s = reader.Info["Author"];

答案 1 :(得分:0)

您可以使用PdfSecuritySettings类设置这些文档限制。

见此样本:
http://www.pdfsharp.net/wiki/ProtectDocument-sample.ashx

我不确定,但我希望在打开PDF文档时也会填充此结构。