仅供参考,这适用于 iText 2.1.7。它是 Java 代码,但可能也适用于 C#。
import java.io.File;
import java.io.FileOutputStream;
import org.junit.Test;
import com.lowagie.text.pdf.PdfDictionary;
import com.lowagie.text.pdf.PdfName;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
import com.lowagie.text.pdf.PdfString;
public class AppTest {
@Test
public void testApp() throws Exception {
PdfReader reader = new PdfReader(AppTest.class.getResourceAsStream("/msword2010.pdf"));
FileOutputStream fos = new FileOutputStream(new File("target", "modified_msword2010.pdf"));
PdfStamper stamper = new PdfStamper(reader, fos, '\0', true);
PdfDictionary infoDict = stamper.getReader().getTrailer().getAsDict(PdfName.INFO);
String producerCleaned = null;
if (infoDict != null) {
PdfString producer = (PdfString) infoDict.get(PdfName.PRODUCER);
if (producer != null) {
producerCleaned = producer.toUnicodeString();
PdfString cleanStrObj = new PdfString(producerCleaned);
infoDict.put(PdfName.PRODUCER, cleanStrObj);
}
}
stamper.close();
}
}