The iTextHandler-class maps several XHTML-tags to iText-objects.
Inheritance: ParserBase
        /// <summary>
        /// Returns a PDF action result. This method renders the view to a string then
        /// use that string to generate a PDF file. The generated PDF file is then
        /// returned to the browser as binary content. The view associated with this
        /// action should render an XML compatible with iTextSharp xml format.
        /// </summary>
        /// <param name="model">The model to send to the view.</param>
        /// <returns>The resulted BinaryContentResult.</returns>
        protected ActionResult ViewPdf(object model)
        {
            // Create the iTextSharp document.
            Document doc = new Document();
            // Set the document to write to memory.
            MemoryStream memStream = new MemoryStream();
            PdfWriter writer = PdfWriter.GetInstance(doc, memStream);
            writer.CloseStream = false;
            doc.Open();

            // Render the view xml to a string, then parse that string into an XML dom.
            string xmltext = this.RenderActionResultToString(this.View(model));
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.InnerXml = xmltext.Trim();

            // Parse the XML into the iTextSharp document.
            ITextHandler textHandler = new ITextHandler(doc);
            textHandler.Parse(xmldoc);

            // Close and get the resulted binary data.
            doc.Close();
            byte[] buf = new byte[memStream.Position];
            memStream.Position = 0;
            memStream.Read(buf, 0, buf.Length);

            // Send the binary data to the browser.
            return new BinaryContentResult(buf, "application/pdf");
        }
Exemple #2
0
 /// <summary>
 /// Parses a given XmlTextReader.
 /// </summary>
 /// <param name="document"></param>
 /// <param name="reader"></param>
 /// <param name="tagmap"></param>
 public virtual void Go(IDocListener document, XmlTextReader reader, String tagmap)
 {
     parser = new ITextmyHandler(document, new TagMap(tagmap));
     parser.Parse(reader);
 }
Exemple #3
0
 /// <summary>
 /// Parses a given file.
 /// </summary>
 /// <param name="document"></param>
 /// <param name="file"></param>
 /// <param name="tagmap"></param>
 public virtual void Go(IDocListener document, XmlDocument xDoc, XmlDocument xTagmap)
 {
     parser = new ITextmyHandler(document, new TagMap(xTagmap));
     parser.Parse(xDoc);
 }
Exemple #4
0
 /// <summary>
 /// Parses a given XmlTextReader.
 /// </summary>
 /// <param name="document"></param>
 /// <param name="reader"></param>
 public virtual void Go(IDocListener document, XmlTextReader reader)
 {
     parser = new ITextHandler(document);
     parser.Parse(reader);
 }
Exemple #5
0
 /// <summary>
 /// Parses a given file.
 /// </summary>
 /// <param name="document"></param>
 /// <param name="file"></param>
 public virtual void Go(IDocListener document, String file)
 {
     parser = new ITextHandler(document);
     parser.Parse(file);
 }
Exemple #6
0
 /// <summary>
 /// Parses a given file.
 /// </summary>
 /// <param name="document"></param>
 /// <param name="file"></param>
 public virtual void Go(IDocListener document, XmlDocument xDoc)
 {
     parser = new ITextHandler(document);
     parser.Parse(xDoc);
 }
        public void XmlToRtf(string xmlDoc, string strFilename)
        {
            Document document = new Document();
            MemoryStream ms = new MemoryStream();
            Phrase headerPhrase;
            Phrase footerPhrase;

            // iTextSharp
            RtfWriter2 writer = RtfWriter2.GetInstance(document, ms);

            footerPhrase = new Phrase("",new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA,8));
            RtfHeaderFooter footer = new RtfHeaderFooter(footerPhrase,true);
            footer.SetAlignment("center");
            writer.Footer = footer;

            AssemblyName an = this.GetType().Assembly.GetName();
            headerPhrase = new Phrase(
                "Use Case Maker " + an.Version.ToString(3),
                new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA,8));
            RtfHeaderFooter header = new RtfHeaderFooter(headerPhrase,false);
            header.SetAlignment("right");
            writer.Header = header;

            StringReader sr = new StringReader(xmlDoc);
            XmlTextReader reader = new XmlTextReader(sr);
            ITextHandler xmlHandler = new ITextHandler(document);

            try
            {
                xmlHandler.Parse(reader);
            }
            catch(Exception e)
            {
                ms.Close();
                throw e;
            }
            finally
            {
                reader.Close();
                sr.Close();
            }

            //Write output file
            FileStream fs = new FileStream(strFilename, FileMode.Create);
            BinaryWriter bw = new BinaryWriter(fs);
            bw.Write(ms.ToArray());
            bw.Close();
            fs.Close();
            ms.Close();
        }
Exemple #8
0
 /// <summary>
 /// Parses a given XmlTextReader.
 /// </summary>
 /// <param name="document"></param>
 /// <param name="reader"></param>
 /// <param name="tagmap"></param>
 public virtual void Go(IDocListener document, XmlTextReader reader, Hashtable tagmap)
 {
     parser = new ITextmyHandler(document, tagmap);
     parser.Parse(reader);
 }
 /// <summary>
 /// Parses a given file.
 /// </summary>
 /// <param name="document"></param>
 /// <param name="file"></param>
 public virtual void Go(IDocListener document, XmlDocument xDoc)
 {
     parser = new ITextHandler(document);
     parser.Parse(xDoc);
 }
 /// <summary>
 /// Parses a given XmlTextReader.
 /// </summary>
 /// <param name="document"></param>
 /// <param name="reader"></param>
 /// <param name="tagmap"></param>
 public virtual void Go(IDocListener document, XmlTextReader reader, Hashtable tagmap)
 {
     parser = new ITextmyHandler(document, tagmap);
     parser.Parse(reader);
 }
 /// <summary>
 /// Parses a given file.
 /// </summary>
 /// <param name="document"></param>
 /// <param name="file"></param>
 /// <param name="tagmap"></param>
 public virtual void Go(IDocListener document, String file, Hashtable tagmap)
 {
     parser = new ITextmyHandler(document, tagmap);
     parser.Parse(file);
 }
 /// <summary>
 /// Parses a given file.
 /// </summary>
 /// <param name="document"></param>
 /// <param name="file"></param>
 /// <param name="tagmap"></param>
 public virtual void Go(IDocListener document, String file, String tagmap)
 {
     parser = new ITextmyHandler(document, new TagMap(tagmap));
     parser.Parse(file);
 }
 /// <summary>
 /// Parses a given XmlTextReader.
 /// </summary>
 /// <param name="document"></param>
 /// <param name="reader"></param>
 /// <param name="tagmap"></param>
 public virtual void Go(IDocListener document, XmlTextReader reader, String tagmap)
 {
     parser = new ITextmyHandler(document, new TagMap(tagmap));
     parser.Parse(reader);
 }
 /// <summary>
 /// Parses a given file.
 /// </summary>
 /// <param name="document"></param>
 /// <param name="file"></param>
 /// <param name="tagmap"></param>
 public virtual void Go(IDocListener document, XmlDocument xDoc, XmlDocument xTagmap)
 {
     parser = new ITextmyHandler(document, new TagMap(xTagmap));
     parser.Parse(xDoc);
 }
Exemple #15
0
 /// <summary>
 /// Parses a given file.
 /// </summary>
 /// <param name="document"></param>
 /// <param name="file"></param>
 /// <param name="tagmap"></param>
 public virtual void Go(IDocListener document, String file, String tagmap)
 {
     parser = new ITextmyHandler(document, new TagMap(tagmap));
     parser.Parse(file);
 }
Exemple #16
0
 /// <summary>
 /// Parses a given file.
 /// </summary>
 /// <param name="document"></param>
 /// <param name="file"></param>
 /// <param name="tagmap"></param>
 public virtual void Go(IDocListener document, String file, Hashtable tagmap)
 {
     parser = new ITextmyHandler(document, tagmap);
     parser.Parse(file);
 }
 /// <summary>
 /// Parses a given file.
 /// </summary>
 /// <param name="document"></param>
 /// <param name="file"></param>
 public virtual void Go(IDocListener document, String file)
 {
     parser = new ITextHandler(document);
     parser.Parse(file);
 }
        public void XmlToPdf(string xmlDoc, string strFilename)
        {
            Document document = new Document();
            MemoryStream ms = new MemoryStream();

            // iTextSharp
            PdfWriter writer = PdfWriter.GetInstance(document, ms);
            MyPageEvents pageEvents = new MyPageEvents();
            writer.PageEvent = pageEvents;

            StringReader sr = new StringReader(xmlDoc);
            XmlTextReader reader = new XmlTextReader(sr);
            ITextHandler xmlHandler = new ITextHandler(document);

            try
            {
                xmlHandler.Parse(reader);
            }
            catch(Exception e)
            {
                ms.Close();
                throw e;
            }
            finally
            {
                reader.Close();
                sr.Close();
            }

            //Write output file
            FileStream fs = new FileStream(strFilename, FileMode.Create);
            BinaryWriter bw = new BinaryWriter(fs);
            bw.Write(ms.ToArray());
            bw.Close();
            fs.Close();
            ms.Close();
        }
 /// <summary>
 /// Parses a given XmlTextReader.
 /// </summary>
 /// <param name="document"></param>
 /// <param name="reader"></param>
 public virtual void Go(IDocListener document, XmlTextReader reader)
 {
     parser = new ITextHandler(document);
     parser.Parse(reader);
 }