Пример #1
0
        /// <summary>
        /// Converts a raw string into a raw string literal, possibly encrypted.
        /// </summary>
        public static string ToStringLiteral(string text, PdfStringEncoding encoding, PdfStandardSecurityHandler securityHandler)
        {
            if (String.IsNullOrEmpty(text))
            {
                return("()");
            }

            byte[] bytes;
            switch (encoding)
            {
            case PdfStringEncoding.RawEncoding:
                bytes = RawEncoding.GetBytes(text);
                break;

            case PdfStringEncoding.WinAnsiEncoding:
                bytes = WinAnsiEncoding.GetBytes(text);
                break;

            case PdfStringEncoding.PDFDocEncoding:
                bytes = DocEncoding.GetBytes(text);
                break;

            case PdfStringEncoding.Unicode:
                bytes = RawUnicodeEncoding.GetBytes(text);
                break;

            default:
                throw new NotImplementedException(encoding.ToString());
            }
            byte[] temp = FormatStringLiteral(bytes, encoding == PdfStringEncoding.Unicode, true, false, securityHandler);
            return(RawEncoding.GetString(temp, 0, temp.Length));
        }
Пример #2
0
        /// <summary>
        /// Converts a raw string into a raw hexadecimal string literal, possibly encrypted.
        /// </summary>
        public static string ToHexStringLiteral(byte[] bytes, bool unicode, PdfStandardSecurityHandler securityHandler)
        {
            if (bytes == null || bytes.Length == 0)
            {
                return("<>");
            }

            byte[] agTemp = FormatStringLiteral(bytes, unicode, true, true, securityHandler);
            return(RawEncoding.GetString(agTemp, 0, agTemp.Length));
        }