0

I have an existing PDF generated by Telerik Reporting which contains the Application and Producer metadata stating the version of the library. I want these two elements stripped. In the app we use a licensed version of ITextSharp 5.

The Creator (Application) line is properly removed, but the Producer one does not change. During debugging I can see that the code below changes both elements, but when inspecting the resulted PDF the Producer remains.

I have changed the license key to test that it is working and I receive an error leading me to believe that the license is valid.

Throughout Stack Overflow I read that it is only possible to change the Producer line with a valid license. Maybe it refers to PDFs created by ITextSharp and not existing ones?

My code below:

internal static class PdfMetadataStripService 
{
    internal static byte[] StripMetadata(byte[] pdfBytes)
    {
        LoadLicenseKey();

        PdfReader reader = new PdfReader(pdfBytes);
        using (MemoryStream ms = new MemoryStream())
        {
            using (PdfStamper stamper = new PdfStamper(reader, ms))
            {
                Dictionary<string, string> info = reader.Info;
                info["Creator"] = string.Empty;
                info["Producer"] = string.Empty;
                stamper.MoreInfo = info;

                using (var xmpMs = new MemoryStream())
                {
                    var xmp = new XmpWriter(xmpMs, info);
                    stamper.XmpMetadata = xmpMs.ToArray();
                    xmp.Close();
                }
            }

            return ms.ToArray();
        }
    }

    private static void LoadLicenseKey()
    {
        var path = string.Format("{0}itextkey.xml", HostingEnvironment.ApplicationPhysicalPath);
        LicenseKey.LoadLicenseFile(path);
    }
}

"iTextSharp" version="5.5.10"

"itextsharp.licensekey" version="1.0.4"

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • I removed your remark about the support team referring to Stack Overflow once the support contract is expired because that's simply not true. Our [support page](http://itextpdf.com/support) mentions Stack Overflow in case you want to search questions and answers posted and answered by the community, but in no way are we using Stack Overflow as a means to provide support to paying customers (because that would go against the terms of use of Stack Overflow). Paying customers have access to our own support system (JIRA) as long as they pay for support. – Bruno Lowagie Feb 08 '17 at 15:11
  • Hi Bruno, I might have misunderstood the information on your support page, sorry about that. Regarding the actual question, can you please just confirm that functionality to edit the Producer line for existing PDFs is enabled in the commercial version? – Dragos-Andrei Feb 08 '17 at 15:28
  • I don't think we change producers lines in existing PDFs. That would be cheating, wouldn't it? – Bruno Lowagie Feb 08 '17 at 16:05
  • Does this answer your question? [Changing PDF Producer property with iText](https://stackoverflow.com/questions/16963322/changing-pdf-producer-property-with-itext) – snieguu Jan 21 '20 at 13:26

0 Answers0