Ejemplo n.º 1
0
 /**
  * Creates an XmpWriter.
  * @param os
  * @param utfEncoding
  * @param extraSpace
  * @throws IOException
  */
 public XmpWriter(Stream os, string utfEncoding, int extraSpace)
 {
     this.extraSpace = extraSpace;
     writer          = new StreamWriter(os, SimpleXMLParser.GetEncodingEncoding(utfEncoding));
     writer.Write("<?xpacket begin='\uFEFF' id='W5M0MpCehiHzreSzNTczkc9d' ?>\n");
     writer.Write("<x:xmpmeta xmlns:x='adobe:ns:meta/'>\n");
     writer.Write("<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n");
     about = "";
 }
Ejemplo n.º 2
0
        /**
         * Exports the bookmarks to XML. The DTD for this XML is:
         * <p>
         * <pre>
         * &lt;?xml version='1.0' encoding='UTF-8'?&gt;
         * &lt;!ELEMENT Title (#PCDATA|Title)*&gt;
         * &lt;!ATTLIST Title
         *    Action CDATA #IMPLIED
         *    Open CDATA #IMPLIED
         *    Page CDATA #IMPLIED
         *    URI CDATA #IMPLIED
         *    File CDATA #IMPLIED
         *    Named CDATA #IMPLIED
         *    NamedN CDATA #IMPLIED
         *    NewWindow CDATA #IMPLIED
         *    Style CDATA #IMPLIED
         *    Color CDATA #IMPLIED
         * &gt;
         * &lt;!ELEMENT Bookmark (Title)*&gt;
         * </pre>
         * @param list the bookmarks
         * @param out the export destination. The stream is not closed
         * @param encoding the encoding according to IANA conventions
         * @param onlyASCII codes above 127 will always be escaped with &amp;#nn; if <CODE>true</CODE>,
         * whatever the encoding
         * @throws IOException on error
         */
        public static void ExportToXML(ArrayList list, Stream outp, String encoding, bool onlyASCII)
        {
            StreamWriter wrt = new StreamWriter(outp, SimpleXMLParser.GetEncodingEncoding(encoding));

            ExportToXML(list, wrt, encoding, onlyASCII);
        }
Ejemplo n.º 3
0
        public static string ConvertToString(byte[] bytes, string encoding)
        {
            if (bytes == null)
            {
                return(PdfObject.NOTHING);
            }
            if (encoding == null || encoding.Length == 0)
            {
                char[] c = new char[bytes.Length];
                for (int k = 0; k < bytes.Length; ++k)
                {
                    c[k] = (char)(bytes[k] & 0xff);
                }
                return(new String(c));
            }
            IExtraEncoding extra = null;

            lock (extraEncodings) {
                extra = (IExtraEncoding)extraEncodings[encoding.ToLower()];
            }
            if (extra != null)
            {
                String text = extra.ByteToChar(bytes, encoding);
                if (text != null)
                {
                    return(text);
                }
            }
            char[] ch = null;
            if (encoding.Equals(BaseFont.WINANSI))
            {
                ch = winansiByteToChar;
            }
            else if (encoding.Equals(PdfObject.TEXT_PDFDOCENCODING))
            {
                ch = pdfEncodingByteToChar;
            }
            if (ch != null)
            {
                int    len = bytes.Length;
                char[] c   = new char[len];
                for (int k = 0; k < len; ++k)
                {
                    c[k] = ch[bytes[k] & 0xff];
                }
                return(new String(c));
            }
            String nameU  = encoding.ToUpper();
            bool   marker = false;
            bool   big    = false;
            int    offset = 0;

            if (bytes.Length >= 2)
            {
                if (bytes[0] == (byte)254 && bytes[1] == (byte)255)
                {
                    marker = true;
                    big    = true;
                    offset = 2;
                }
                else if (bytes[0] == (byte)255 && bytes[1] == (byte)254)
                {
                    marker = true;
                    big    = false;
                    offset = 2;
                }
            }
            Encoding enc = null;

            if (nameU.Equals("UNICODEBIGUNMARKED") || nameU.Equals("UNICODEBIG"))
            {
                enc = new UnicodeEncoding(marker ? big : true, false);
            }
            if (nameU.Equals("UNICODELITTLEUNMARKED") || nameU.Equals("UNICODELITTLE"))
            {
                enc = new UnicodeEncoding(marker ? big : false, false);
            }
            if (enc != null)
            {
                return(enc.GetString(bytes, offset, bytes.Length - offset));
            }
            return(SimpleXMLParser.GetEncodingEncoding(encoding).GetString(bytes));
        }
Ejemplo n.º 4
0
        /**
         * Converts a <CODE>string</CODE> to a </CODE>byte</CODE> array according
         * to the font's encoding.
         * @param text the <CODE>string</CODE> to be converted
         * @return an array of <CODE>byte</CODE> representing the conversion according to the font's encoding
         */
        public static byte[] ConvertToBytes(string text, string encoding)
        {
            if (text == null)
            {
                return(new byte[0]);
            }
            if (encoding == null || encoding.Length == 0)
            {
                int    len = text.Length;
                byte[] b   = new byte[len];
                for (int k = 0; k < len; ++k)
                {
                    b[k] = (byte)text[k];
                }
                return(b);
            }
            IExtraEncoding extra = null;

            lock (extraEncodings) {
                extra = (IExtraEncoding)extraEncodings[encoding.ToLower()];
            }
            if (extra != null)
            {
                byte[] b = extra.CharToByte(text, encoding);
                if (b != null)
                {
                    return(b);
                }
            }
            IntHashtable hash = null;

            if (encoding.Equals(BaseFont.CP1252))
            {
                hash = winansi;
            }
            else if (encoding.Equals(PdfObject.TEXT_PDFDOCENCODING))
            {
                hash = pdfEncoding;
            }
            if (hash != null)
            {
                char[] cc  = text.ToCharArray();
                int    len = cc.Length;
                int    ptr = 0;
                byte[] b   = new byte[len];
                int    c   = 0;
                for (int k = 0; k < len; ++k)
                {
                    char char1 = cc[k];
                    if (char1 < 128 || (char1 >= 160 && char1 <= 255))
                    {
                        c = char1;
                    }
                    else
                    {
                        c = hash[char1];
                    }
                    if (c != 0)
                    {
                        b[ptr++] = (byte)c;
                    }
                }
                if (ptr == len)
                {
                    return(b);
                }
                byte[] b2 = new byte[ptr];
                Array.Copy(b, 0, b2, 0, ptr);
                return(b2);
            }
            Encoding encw = SimpleXMLParser.GetEncodingEncoding(encoding);

            byte[] preamble = encw.GetPreamble();
            if (preamble.Length == 0)
            {
                return(encw.GetBytes(text));
            }
            byte[] encoded = encw.GetBytes(text);
            byte[] total   = new byte[encoded.Length + preamble.Length];
            Array.Copy(preamble, 0, total, 0, preamble.Length);
            Array.Copy(encoded, 0, total, preamble.Length, encoded.Length);
            return(total);
        }