我正在使用 iTextSharp 产品来更改 PDF 属性,如下所示。 我根本无法更改“PDF Producer”属性。请建议,我哪里错了。
代码行 info["制作人"] = "我的制作人";
没有正常工作。
string sourcePath = tbPath.Text;
IList<string> dirs = null;
string pdfName = string.Empty;
string OutputPath = string.Empty;
DirectoryInfo di = new DirectoryInfo(sourcePath);
DirectoryInfo dInfo = Directory.CreateDirectory(sourcePath + "\\" + "TempDir");
OutputPath = Path.Combine(sourcePath,"TempDir");
dirs = Directory.GetFiles(di.FullName, "*.pdf").ToList();
for (int i = 0; i <= dirs.Count - 1; i++)
{
try
{
PdfReader pdfReader = new PdfReader(dirs[i]);
using (FileStream fileStream = new FileStream(Path.Combine(OutputPath, Path.GetFileName(dirs[i])),
FileMode.Create,
FileAccess.Write))
{
PdfStamper pdfStamper = new PdfStamper(pdfReader, fileStream);
Dictionary<string, string> info = pdfReader.Info;
info["Title"] = "";
info["Author"] = "";
info["Producer"] = "My producer"; ////THIS IS NOT WORKING..
pdfStamper.MoreInfo = info;
pdfStamper.Close();
pdfReader.Close();
}
最佳答案
如果您有许可证 key ,您只能更改生产商行。需要从 iText Software 购买许可证 key .有关如何应用许可证 key 的说明随该 key 一起发送。
如果你想免费使用iText,你不能改变生产者的路线。查看开源版iText中每个文件的license header:
* In accordance with Section 7(b) of the GNU Affero General Public License,
* a covered work must retain the producer line in every PDF that is created
* or manipulated using iText.
供您引用:iText Group 已成功起诉一家德国公司,该公司在未购买许可证的情况下更改生产线。您可以在此处找到与此案例相关的一些文档:IANAL: What developers should know about IP and Legal (幻灯片 57-62)
顺便说一句,我通过这次演讲获得了 JavaOne Rockstar 奖:https://twitter.com/itext/status/704278659012681728
总结:如果您没有 iText 的商业许可,您就不能合法地更改 iText 中的生产者行。如果您有商业许可证,则需要应用许可证 key 。
关于c# - iTextSharp .NET PDF - 无法更改 PDF Producer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36351302/