zoukankan      html  css  js  c++  java
  • C# 中使用iTextSharp组件修改PDF元数据(title,Keywords等)

    引用iTextSharp方法参见:C# 中使用iTextSharp组件创建简单PDF

     1 /// <summary>
     2 /// 修改PDF文件属性
     3 /// </summary>
     4 /// <param name="pdfName">PDF文件名(比如:D:\hello.pdf)</param>
     5 private void PdfPropMod(string pdfName)
     6 {
     7     try
     8     {
     9         PdfReader reader = new PdfReader(File.ReadAllBytes(pdfName));
    10 
    11         if (!reader.IsEncrypted())
    12         {
    13             Dictionary<string, string> info = reader.Info;
    14             info.Remove("Title");
    15             info.Add("Title", "标题");
    16             info.Remove("Author");
    17             info.Add("Author", "作者_幻想Zerow");
    18             info.Remove("Subject");
    19             info.Add("Subject", "主题-修改Pdf元数据_幻想Zerow");
    20             info.Remove("Keywords");
    21             info.Add("Keywords", "关键字");
    22 
    23             reader.Close();
    24             PdfStamper stamper = new PdfStamper(reader, new FileStream(pdfName, FileMode.Create, FileAccess.Write));
    25             stamper.MoreInfo = info;
    26             //设置是否加密
    27             //stamper.SetEncryption(PdfWriter.DO_NOT_ENCRYPT_METADATA, null, null, PdfWriter.ALLOW_PRINTING | PdfWriter.ALLOW_COPY);
    28             stamper.Close();
    29         }
    30     }
    31     catch (Exception e)
    32     {
    33         throw e;
    34     }
    35 }

    无加密:

  • 相关阅读:
    很难理解的三个设计模式
    设计模式思考(转)
    AOP
    CAP理论(摘)
    DDBS
    NoSql
    Enterprise Library 企业库
    padright padleft
    Process ProcessThread Thread
    053374
  • 原文地址:https://www.cnblogs.com/haocool/p/2962573.html
Copyright © 2011-2022 走看看