예제 #1
0
        /**
         * Exports the bookmarks to XML. Only of use if the generation is to be include in
         * some other XML document.
         * @param list the bookmarks
         * @param out the export destination. The writer is not closed
         * @param indent the indentation level. Pretty printing significant only. Use <CODE>-1</CODE> for no indents.
         * @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 ExportToXMLNode(IList <Dictionary <String, Object> > list, TextWriter outp, int indent, bool onlyASCII)
        {
            String dep = "";

            if (indent != -1)
            {
                for (int k = 0; k < indent; ++k)
                {
                    dep += "  ";
                }
            }
            foreach (Dictionary <String, Object> map in list)
            {
                String title = null;
                outp.Write(dep);
                outp.Write("<Title ");
                IList <Dictionary <String, Object> > kids = null;
                foreach (KeyValuePair <string, object> entry in map)
                {
                    String key = entry.Key;
                    if (key.Equals("Title"))
                    {
                        title = (String)entry.Value;
                        continue;
                    }
                    else if (key.Equals("Kids"))
                    {
                        kids = (IList <Dictionary <String, Object> >)entry.Value;
                        continue;
                    }
                    else
                    {
                        outp.Write(key);
                        outp.Write("=\"");
                        String value = (String)entry.Value;
                        if (key.Equals("Named") || key.Equals("NamedN"))
                        {
                            value = EscapeBinaryString(value);
                        }
                        outp.Write(XMLUtil.EscapeXML(value, onlyASCII));
                        outp.Write("\" ");
                    }
                }
                outp.Write(">");
                if (title == null)
                {
                    title = "";
                }
                outp.Write(XMLUtil.EscapeXML(title, onlyASCII));
                if (kids != null)
                {
                    outp.Write("\n");
                    ExportToXMLNode(kids, outp, indent == -1 ? indent : indent + 1, onlyASCII);
                    outp.Write(dep);
                }
                outp.Write("</Title>\n");
            }
        }
예제 #2
0
 /**
  * Exports the bookmarks to XML.
  * @param list the bookmarks
  * @param wrt the export destination. The writer 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(IList <Dictionary <String, Object> > list, TextWriter wrt, String encoding, bool onlyASCII)
 {
     wrt.Write("<?xml version=\"1.0\" encoding=\"");
     wrt.Write(XMLUtil.EscapeXML(encoding, onlyASCII));
     wrt.Write("\"?>\n<Bookmark>\n");
     ExportToXMLNode(list, wrt, 1, onlyASCII);
     wrt.Write("</Bookmark>\n");
     wrt.Flush();
 }
예제 #3
0
        /**
         * Replaces the content of a tag.
         * @param	namespaceURI	the URI of the namespace
         * @param	localName		the tag name
         * @param	value			the new content for the tag
         * @return	true if the content was successfully replaced
         * @since	2.1.6 the return type has changed from void to boolean
         */
        public bool ReplaceNode(String namespaceURI, String localName, String value)
        {
            XmlNodeList nodes = domDocument.GetElementsByTagName(localName, namespaceURI);
            XmlNode     node;

            if (nodes.Count == 0)
            {
                return(false);
            }
            for (int i = 0; i < nodes.Count; i++)
            {
                node = nodes[i];
                SetNodeText(domDocument, node, XMLUtil.EscapeXML(value, false));
            }
            return(true);
        }
예제 #4
0
        /**
         * Returns the String representation of the XmpArray.
         * @return a String representation
         */
        public override String ToString()
        {
            StringBuilder buf = new StringBuilder("<");

            buf.Append(type);
            buf.Append('>');
            foreach (String s in this)
            {
                buf.Append("<rdf:li>");
                buf.Append(XMLUtil.EscapeXML(s, false));
                buf.Append("</rdf:li>");
            }
            buf.Append("</");
            buf.Append(type);
            buf.Append('>');
            return(buf.ToString());
        }
 /**
  * Exports the bookmarks to XML.
  * @param names the names
  * @param wrt the export destination. The writer 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(Dictionary <string, string> names, TextWriter wrt, String encoding, bool onlyASCII)
 {
     wrt.Write("<?xml version=\"1.0\" encoding=\"");
     wrt.Write(XMLUtil.EscapeXML(encoding, onlyASCII));
     wrt.Write("\"?>\n<Destination>\n");
     foreach (String key in names.Keys)
     {
         String value = names[key];
         wrt.Write("  <Name Page=\"");
         wrt.Write(XMLUtil.EscapeXML(value, onlyASCII));
         wrt.Write("\">");
         wrt.Write(XMLUtil.EscapeXML(EscapeBinaryString(key), onlyASCII));
         wrt.Write("</Name>\n");
     }
     wrt.Write("</Destination>\n");
     wrt.Flush();
 }
예제 #6
0
 public override void ParseTag(String tag, PdfObject obj, PdfDictionary page)
 {
     if (obj is PdfNumber)
     {
         PdfNumber                  mcid     = (PdfNumber)obj;
         RenderFilter               filter   = new AcroFieldsFlattenTest.MyMarkedContentRenderFilter(mcid.IntValue);
         ITextExtractionStrategy    strategy = new SimpleTextExtractionStrategy();
         FilteredTextRenderListener listener = new FilteredTextRenderListener(
             strategy, filter);
         PdfContentStreamProcessor processor = new PdfContentStreamProcessor(
             listener);
         processor.ProcessContent(PdfReader.GetPageContent(page), page
                                  .GetAsDict(PdfName.RESOURCES));
         outp.Write(XMLUtil.EscapeXML(listener.GetResultantText(), true));
     }
     else
     {
         base.ParseTag(tag, obj, page);
     }
 }
예제 #7
0
// ---------------------------------------------------------------------------

        /**
         * Creates the PDF.
         * @return the bytes of a PDF file.
         */
        public byte[] CreatePdf()
        {
            IEnumerable <Movie> movies = PojoFactory.GetMovies(1);

            using (MemoryStream ms = new MemoryStream()) {
                using (Document document = new Document()) {
                    PdfWriter writer = PdfWriter.GetInstance(document, ms);
                    document.Open();
                    document.Add(new Paragraph(
                                     "'Stanley Kubrick: A Life in Pictures'"
                                     + " is a documentary about Stanley Kubrick and his films:"
                                     ));
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("<movies>");
                    List list = new List(List.UNORDERED, 20);
                    foreach (Movie movie in movies)
                    {
                        sb.AppendLine("<movie>");
                        sb.AppendLine(String.Format(
                                          "<title>{0}</title>",
                                          XMLUtil.EscapeXML(movie.MovieTitle, true)
                                          ));
                        sb.AppendLine(String.Format("<year>{0}</year>", movie.Year));
                        sb.AppendLine(String.Format(
                                          "<duration>{0}</duration>", movie.Duration
                                          ));
                        sb.AppendLine("</movie>");
                        ListItem item = new ListItem(movie.MovieTitle);
                        list.Add(item);
                    }
                    document.Add(list);
                    sb.Append("</movies>");
                    PdfFileSpecification fs = PdfFileSpecification.FileEmbedded(
                        writer, null, "kubrick.xml", Encoding.UTF8.GetBytes(sb.ToString())
                        //txt.toByteArray()
                        );
                    writer.AddFileAttachment(fs);
                }
                return(ms.ToArray());
            }
        }
예제 #8
0
 /**
  * Searches for a tag in a page.
  *
  * @param tag
  *            the name of the tag
  * @param obj
  *            an identifier to find the marked content
  * @param page
  *            a page dictionary
  * @throws IOException
  */
 public virtual void ParseTag(String tag, PdfObject obj, PdfDictionary page)
 {
     // if the identifier is a number, we can extract the content right away
     if (obj is PdfNumber)
     {
         PdfNumber                  mcid      = (PdfNumber)obj;
         RenderFilter               filter    = new MarkedContentRenderFilter(mcid.IntValue);
         ITextExtractionStrategy    strategy  = new SimpleTextExtractionStrategy();
         FilteredTextRenderListener listener  = new FilteredTextRenderListener(strategy, new RenderFilter[] { filter });
         PdfContentStreamProcessor  processor = new PdfContentStreamProcessor(
             listener);
         processor.ProcessContent(PdfReader.GetPageContent(page), page
                                  .GetAsDict(PdfName.RESOURCES));
         outp.Write(XMLUtil.EscapeXML(listener.GetResultantText(), true));
     }
     // if the identifier is an array, we call the parseTag method
     // recursively
     else if (obj is PdfArray)
     {
         PdfArray arr = (PdfArray)obj;
         int      n   = arr.Size;
         for (int i = 0; i < n; i++)
         {
             ParseTag(tag, arr[i], page);
             if (i < n - 1)
             {
                 outp.WriteLine();
             }
         }
     }
     // if the identifier is a dictionary, we get the resources from the
     // dictionary
     else if (obj is PdfDictionary)
     {
         PdfDictionary mcr = (PdfDictionary)obj;
         ParseTag(tag, mcr.GetDirectObject(PdfName.MCID), mcr
                  .GetAsDict(PdfName.PG));
     }
 }
예제 #9
0
 /**
  * Escapes a string with the appropriated XML codes.
  * @param s the string to be escaped
  * @param onlyASCII codes above 127 will always be escaped with &amp;#nn; if <CODE>true</CODE>
  * @return the escaped string
  */
 public static String EscapeXML(String s, bool onlyASCII)
 {
     return(XMLUtil.EscapeXML(s, onlyASCII));
 }
예제 #10
0
 /**
  * @param content
  * @return
  */
 public static String Escape(String content)
 {
     return(XMLUtil.EscapeXML(content, false));
 }
예제 #11
0
 public override string this[string key] {
     set {
         base[key] = XMLUtil.EscapeXML(value, false);
     }
 }
예제 #12
0
 /**
  * Add a language.
  */
 public void AddLanguage(String language, String value)
 {
     this[language] = XMLUtil.EscapeXML(value, false);
 }
예제 #13
0
 /**
  * @param os
  * @param info
  * @throws IOException
  */
 public XmpWriter(Stream os, PdfDictionary info, int PdfXConformance) : this(os) {
     if (info != null)
     {
         DublinCoreSchema dc    = new DublinCoreSchema();
         PdfSchema        p     = new PdfSchema();
         XmpBasicSchema   basic = new XmpBasicSchema();
         PdfObject        obj;
         String           value;
         foreach (PdfName key in info.Keys)
         {
             obj = info.Get(key);
             if (obj == null)
             {
                 continue;
             }
             value = XMLUtil.EscapeXML(((PdfString)obj).ToUnicodeString(), false);
             if (PdfName.TITLE.Equals(key))
             {
                 dc.AddTitle(value);
             }
             if (PdfName.AUTHOR.Equals(key))
             {
                 dc.AddAuthor(value);
             }
             if (PdfName.SUBJECT.Equals(key))
             {
                 dc.AddSubject(value);
                 dc.AddDescription(value);
             }
             if (PdfName.KEYWORDS.Equals(key))
             {
                 p.AddKeywords(value);
             }
             if (PdfName.CREATOR.Equals(key))
             {
                 basic.AddCreatorTool(value);
             }
             if (PdfName.PRODUCER.Equals(key))
             {
                 p.AddProducer(value);
             }
             if (PdfName.CREATIONDATE.Equals(key))
             {
                 basic.AddCreateDate(PdfDate.GetW3CDate(obj.ToString()));
             }
             if (PdfName.MODDATE.Equals(key))
             {
                 basic.AddModDate(PdfDate.GetW3CDate(obj.ToString()));
             }
         }
         if (dc.Count > 0)
         {
             AddRdfDescription(dc);
         }
         if (p.Count > 0)
         {
             AddRdfDescription(p);
         }
         if (basic.Count > 0)
         {
             AddRdfDescription(basic);
         }
         if (PdfXConformance == PdfWriter.PDFA1A || PdfXConformance == PdfWriter.PDFA1B)
         {
             PdfA1Schema a1 = new PdfA1Schema();
             if (PdfXConformance == PdfWriter.PDFA1A)
             {
                 a1.AddConformance("A");
             }
             else
             {
                 a1.AddConformance("B");
             }
             AddRdfDescription(a1);
         }
     }
 }