PDF Field format changes after Encrypting the PDF document using iTextSharp

删除回忆录丶 提交于 2019-12-12 01:58:16

问题


I am using iTextSharp to manipulate PDF documents. I have to make PDF document encrypted and I am able to do it. The only problem that I am getting now is the format of form fields - they got changed.

For example:

I have text field of 'Integer' type with format '1,234.00'. Before encrypting the format is what I have set. But after encrypting the PDF the format changes to default i.e. value becomes '1234'.

Any suggestion?

UPDATE:

I am using following code to set password on document:

    PdfReader reader = new PdfReader(document, System.Text.Encoding.UTF8.GetBytes("pass"));
    using (MemoryStream ms = new MemoryStream())
    {
        using (PdfStamper stamper = new PdfStamper(reader, ms))
        {
        }

        using (FileStream fs = new FileStream(
          tempFile, FileMode.Create, FileAccess.ReadWrite))
        {
            PdfEncryptor.Encrypt(
              new PdfReader(ms.ToArray()),
              fs,
              PdfWriter.DO_NOT_ENCRYPT_METADATA,
              null,
              "pass",
              PdfWriter.ALLOW_PRINTING
                  | PdfWriter.ALLOW_COPY
            );
        }
    }

    reader.Close();

来源:https://stackoverflow.com/questions/19274129/pdf-field-format-changes-after-encrypting-the-pdf-document-using-itextsharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!