Set Metadata in iTextSharp

后端 未结 3 1582
说谎
说谎 2020-12-18 03:28

I am developing an application and i use the iTextSharp library.

I am also reading the iText in action from Manning so i can get references.

In Chapter 12 it

3条回答
  •  太阳男子
    2020-12-18 03:49

     public void pdfproperties()
        {
            string inputFile = @"D:\1.pdf";
            string outputFile = @"D:\48.pdf";
            PdfReader reader = new PdfReader(inputFile);
            foreach (KeyValuePair KV in reader.Info)
            {
                reader.Info.Remove(KV.Key);
            }
            using (FileStream FS = new FileStream(outputFile, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                using (Document Doc = new Document())
                {
                    using (PdfCopy writer = new PdfCopy(Doc, FS))
                    {
                        Doc.Open();
                        Doc.AddTitle("Add Title");
                        Doc.AddSubject("Add Subject");
                        Doc.AddKeywords("Add Keywords");
                        Doc.AddCreator("Application Creator");
                        Doc.AddAuthor("Add Author");
                        for (int i = 1; i <= reader.NumberOfPages; i++)
                        {
                            writer.AddPage(writer.GetImportedPage(reader, i));
                        }
                        writer.Info.Put(new PdfName("Producer"), new PdfString("Producer Name"));
                        Doc.Close();
                    }
                }
            }
        }

提交回复
热议问题