を使用して、既存のPDFファイルからメタデータを削除します。 は、今私は、PDFの暗号化を解除したいです。私はiTextSharpを使用して成功しましたが、追加したメタデータを削除できませんでした。 は、誰もが、私は、メタデータを削除することができますどのように私をgiudeてくださいすることができます。緊急です。は、私は、PDFを作成し、それにメタデータを追加しても、それはiTextsharpライブラリをuisng暗号化iTextsharp
ありがとうございました。
を使用して、既存のPDFファイルからメタデータを削除します。 は、今私は、PDFの暗号化を解除したいです。私はiTextSharpを使用して成功しましたが、追加したメタデータを削除できませんでした。 は、誰もが、私は、メタデータを削除することができますどのように私をgiudeてくださいすることができます。緊急です。は、私は、PDFを作成し、それにメタデータを追加しても、それはiTextsharpライブラリをuisng暗号化iTextsharp
ありがとうございました。
メタデータを削除すると、それはPdfReader
オブジェクトを直接操作するのが最も簡単です。一度それを行うと、それをディスクに書き戻すことができます。以下のコードは、iTextSharp 5.1.2.0を対象としたC#2010 WinFormsアプリケーションのフル機能です。最初にいくつかのメタデータを含むPDFを作成した後、PdfReader
を使用してPDFのメモリ内のバージョンを変更し、最後に変更をディスクに書き込みます。追加のコメントについては、コードを参照してください。
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace WindowsFormsApplication1 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
//File with meta data added
string InputFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf");
//File with meta data removed
string OutputFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Output.pdf");
//Create a file with meta data, nothing special here
using (FileStream FS = new FileStream(InputFile, FileMode.Create, FileAccess.Write, FileShare.None)) {
using (Document Doc = new Document(PageSize.LETTER)) {
using (PdfWriter writer = PdfWriter.GetInstance(Doc, FS)) {
Doc.Open();
Doc.Add(new Paragraph("Test"));
//Add a standard header
Doc.AddTitle("This is a test");
//Add a custom header
Doc.AddHeader("Test Header", "This is also a test");
Doc.Close();
}
}
}
//Read our newly created file
PdfReader R = new PdfReader(InputFile);
//Loop through each piece of meta data and remove it
foreach (KeyValuePair<string, string> KV in R.Info) {
R.Info.Remove(KV.Key);
}
//The code above modifies an in-memory representation of the PDF, we need to write these changes to disk now
using (FileStream FS = new FileStream(OutputFile, FileMode.Create, FileAccess.Write, FileShare.None)) {
using (Document Doc = new Document()) {
//Use the PdfCopy object to copy each page
using (PdfCopy writer = new PdfCopy(Doc, FS)) {
Doc.Open();
//Loop through each page
for (int i = 1; i <= R.NumberOfPages; i++) {
//Add it to the new document
writer.AddPage(writer.GetImportedPage(R, i));
}
Doc.Close();
}
}
}
this.Close();
}
}
}
こんにちは、私は追加の肉体情報を追加しました。最初にreaderを使ってメタデータを削除し、stamperのmoreinfoプロパティを設定してメタデータを追加しました。しかし、メタデータ値はまだそこにあります。 – Lipika
はStackOverflowのへようこそ。私はあなたの質問が短すぎると、詳細に欠けるので、私たちはあなたを助けることはできません怖いです。してくださいくださいstackoverflow.com/questions/how-to-ask –