Example #1
0
        virtual public void SetUp()
        {
            LoggerFactory.GetInstance().SetLogger(new SysoLogger(3));
            tag.Parent = new Tag("defaultRoot");
            basicPara.Add(basic);
            extraPara.Add(extra);
            cell1Row1.AddElement(basicPara);
            cell2Row1.AddElement(extraPara);
            cell3Row1.AddElement(basicPara);
            cell4Row1.AddElement(extraPara);
            cell4Row1.Rowspan = 2;
            cells1.Add(cell1Row1);
            cells1.Add(cell2Row1);
            cells1.Add(cell3Row1);
            cells1.Add(cell4Row1);
            row1 = new TableRowElement(cells1, TableRowElement.Place.BODY);

            cell1Row2.AddElement(extraPara);
            cell2Row2.AddElement(basicPara);
//		Tag t = new Tag(null, new HashMap<String, String>());
//		t.getAttributes().put("col-span", "2");
            cell2Row2.Colspan = 2;
            cell3Row2.AddElement(extraPara);
            cells2.Add(cell1Row2);
            cells2.Add(cell2Row2);
            //cells2.Add(cell3Row2);
            row2 = new TableRowElement(cells2, TableRowElement.Place.BODY);

            rows.Add(row1);
            rows.Add(row2);
        }
        public void TestAddImageToParagraph()
        {
            String message = "Could not add " + jpegImage.GetType().Name
                             + " to " + paragraph.GetType().Name;

            Assert.IsTrue(paragraph.Add(jpegImage), message);
        }
Example #3
0
        /**
         * Adds currentContent list to a paragraph element. If addNewLines is true a
         * Paragraph object is returned, else a NoNewLineParagraph object is
         * returned.
         *
         * @param currentContent IList<IElement> of the current elements to be added.
         * @param addNewLines bool to declare which paragraph element should be
         *            returned, true if new line should be added or not.
         * @param applyCSS true if CSS should be applied on the paragraph
         * @param tag the relevant tag
         * @return a List with paragraphs
         */

        public virtual IList <IElement> CurrentContentToParagraph(IList <IElement> currentContent,
                                                                  bool addNewLines, bool applyCSS, Tag tag,
                                                                  IWorkerContext ctx)
        {
            try
            {
                IList <IElement> list = new List <IElement>();
                if (currentContent.Count > 0)
                {
                    if (addNewLines)
                    {
                        Paragraph p = CreateParagraph();
                        p.MultipliedLeading = 1.2f;
                        foreach (IElement e in currentContent)
                        {
                            if (e is LineSeparator)
                            {
                                try {
                                    HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx);
                                    Chunk newLine = (Chunk)GetCssAppliers().Apply(new Chunk(Chunk.NEWLINE), tag, htmlPipelineContext);
                                    p.Add(newLine);
                                } catch (NoCustomContextException exc) {
                                    throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), exc);
                                }
                            }
                            p.Add(e);
                        }
                        if (p.Trim())
                        {
                            if (applyCSS)
                            {
                                p = (Paragraph)GetCssAppliers().Apply(p, tag, GetHtmlPipelineContext(ctx));
                            }
                            list.Add(p);
                        }
                    }
                    else
                    {
                        NoNewLineParagraph p = new NoNewLineParagraph(float.NaN);
                        p.MultipliedLeading = 1.2f;
                        foreach (IElement e in currentContent)
                        {
                            p.Add(e);
                        }
                        p = (NoNewLineParagraph)GetCssAppliers().Apply(p, tag, GetHtmlPipelineContext(ctx));
                        list.Add(p);
                    }
                }
                return(list);
            } catch (NoCustomContextException e) {
                throw new RuntimeWorkerException(
                          LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e);
            }
        }
Example #4
0
        /*
         * (non-Javadoc)
         *
         * @see com.itextpdf.tool.xml.ITagProcessor#content(com.itextpdf.tool.xml.Tag, java.util.List,
         * com.itextpdf.text.Document, java.lang.String)
         */
        public override IList <IElement> Content(IWorkerContext ctx, Tag tag, String content)
        {
            List <Chunk>       sanitizedChunks = HTMLUtils.Sanitize(content, false);
            List <IElement>    l = new List <IElement>(1);
            NoNewLineParagraph sanitizedNoNewLineParagraph = new NoNewLineParagraph();

            foreach (Chunk sanitized in sanitizedChunks)
            {
                Chunk c = GetCssAppliers().ChunkCssAplier.Apply(sanitized, tag);
                sanitizedNoNewLineParagraph.Add(c);
            }
            if (sanitizedNoNewLineParagraph.Count > 0)
            {
                try {
                    l.Add(GetCssAppliers().Apply(sanitizedNoNewLineParagraph, tag, GetHtmlPipelineContext(ctx)));
                } catch (NoCustomContextException e) {
                    throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e);
                }
            }
            return(l);
        }
Example #5
0
        public void SetUp()
        {
            cells     = new List <Element>();
            tag       = new Tag("td", new Dictionary <String, String>());
            basicPara = new NoNewLineParagraph();
            basic     = new Chunk("content");

            cell    = new HtmlCell();
            applier = new HtmlCellCssApplier();


            LoggerFactory.GetInstance().SetLogger(new SysoLogger(3));
            Tag parent = new Tag("tr");

            parent.Parent = new Tag("table");
            tag.Parent    = parent;
            basicPara.Add(basic);
            cell.AddElement(basicPara);
            cells.Add(cell);
            config = new HtmlPipelineContext(null);
        }
Example #6
0
        /* (non-Javadoc)
         * @see com.itextpdf.tool.xml.ITagProcessor#content(com.itextpdf.tool.xml.Tag, java.lang.String)
         */
        public override IList <IElement> Content(IWorkerContext ctx, Tag tag, String content)
        {
            List <Chunk>       sanitizedChunks = HTMLUtils.Sanitize(content, false);
            List <IElement>    l = new List <IElement>(1);
            NoNewLineParagraph sanitizedNoNewLineParagraph = new NoNewLineParagraph();

            try {
                HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx);
                foreach (Chunk sanitized in sanitizedChunks)
                {
                    sanitizedNoNewLineParagraph.Add(GetCssAppliers().Apply(sanitized, tag, htmlPipelineContext));
                }
                if (sanitizedNoNewLineParagraph.Count > 0)
                {
                    l.Add(GetCssAppliers().Apply(sanitizedNoNewLineParagraph, tag, htmlPipelineContext));
                }
            }
            catch (NoCustomContextException e) {
                throw new RuntimeWorkerException(e);
            }
            return(l);
        }
Example #7
0
 /**
  * Adds currentContent list to a paragraph element. If addNewLines is true a
  * Paragraph object is returned, else a NoNewLineParagraph object is
  * returned.
  *
  * @param currentContent IList<IElement> of the current elements to be added.
  * @param addNewLines bool to declare which paragraph element should be
  *            returned, true if new line should be added or not.
  * @param applyCSS true if CSS should be applied on the paragraph
  * @param tag the relevant tag
  * @return a List with paragraphs
  */
 public virtual IList <IElement> CurrentContentToParagraph(IList <IElement> currentContent,
                                                           bool addNewLines, bool applyCSS, Tag tag, IWorkerContext ctx)
 {
     try {
         IList <IElement> list = new List <IElement>();
         if (currentContent.Count > 0)
         {
             if (addNewLines)
             {
                 Paragraph p = new Paragraph();
                 foreach (IElement e in currentContent)
                 {
                     p.Add(e);
                 }
                 if (applyCSS)
                 {
                     p = new ParagraphCssApplier(GetHtmlPipelineContext(ctx)).Apply(p, tag);
                 }
                 list.Add(p);
             }
             else
             {
                 NoNewLineParagraph p = new NoNewLineParagraph();
                 foreach (IElement e in currentContent)
                 {
                     p.Add(e);
                 }
                 p = new NoNewLineParagraphCssApplier(GetHtmlPipelineContext(ctx)).Apply(p, tag);
                 list.Add(p);
             }
             // TODO enhance
         }
         return(list);
     } catch (NoCustomContextException e) {
         throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e);
     }
 }
Example #8
0
        /*
         * (non-Javadoc)
         *
         * @see
         * com.itextpdf.tool.xml.ITagProcessor#endElement(com.itextpdf.tool.xml.Tag,
         * java.util.List, com.itextpdf.text.Document)
         */
        public override IList <IElement> End(IWorkerContext ctx, Tag tag, IList <IElement> currentContent)
        {
            try {
                String name;
                tag.Attributes.TryGetValue(HTML.Attribute.NAME, out name);
                IList <IElement> elems = new List <IElement>(0);
                if (currentContent.Count > 0)
                {
                    NoNewLineParagraph p = new NoNewLineParagraph();
                    String             url;
                    tag.Attributes.TryGetValue(HTML.Attribute.HREF, out url);
                    foreach (IElement e in currentContent)
                    {
                        if (e is Chunk)
                        {
                            if (null != url)
                            {
                                if (url.StartsWith("#"))
                                {
                                    if (LOGGER.IsLogging(Level.TRACE))
                                    {
                                        LOGGER.Trace(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.A_LOCALGOTO), url));
                                    }
                                    ((Chunk)e).SetLocalGoto(url.Substring(1));
                                }
                                else
                                {
                                    // TODO check url validity?
                                    if (null != GetHtmlPipelineContext(ctx).GetLinkProvider() && !url.StartsWith("http"))
                                    {
                                        String root = GetHtmlPipelineContext(ctx).GetLinkProvider().GetLinkRoot();
                                        if (root.EndsWith("/") && url.StartsWith("/"))
                                        {
                                            root = root.Substring(0, root.Length - 1);
                                        }
                                        url = root + url;
                                    }
                                    if (LOGGER.IsLogging(Level.TRACE))
                                    {
                                        LOGGER.Trace(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.A_EXTERNAL), url));
                                    }
                                    ((Chunk)e).SetAnchor(url);
                                }
                            }
                            else if (null != name)
                            {
                                ((Chunk)e).SetLocalDestination(name);
                                if (LOGGER.IsLogging(Level.TRACE))
                                {
                                    LOGGER.Trace(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.A_SETLOCALGOTO), name));
                                }
                            }
                        }
                        p.Add(e);
                    }
                    elems.Add(GetCssAppliers().Apply(p, tag, GetHtmlPipelineContext(ctx)));
                }
                else
                // !currentContent > 0 ; An empty "a" tag has been encountered.
                // we're using an anchor space hack here. without the space, reader
                // does
                // not jump to destination
                if (null != name)
                {
                    if (LOGGER.IsLogging(Level.TRACE))
                    {
                        LOGGER.Trace(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.SPACEHACK), name));
                    }
                    elems.Add(new WriteP(name));

                    /*
                     * PdfWriter writer = configuration.GetWriter(); ColumnText c =
                     * new ColumnText(writer.GetDirectContent());
                     * c.SetSimpleColumn(new Phrase(dest), 1,
                     * writer.GetVerticalPosition(false), 1,
                     * writer.GetVerticalPosition(false), 5, Element.ALIGN_LEFT);
                     * try { c.Go(); } catch (DocumentException e) { throw new
                     * RuntimeWorkerException(e); }
                     */
                }
                return(elems);
            } catch (NoCustomContextException e) {
                throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e);
            }
        }
Example #9
0
        /**
         * Adds currentContent list to a paragraph element. If addNewLines is true a
         * Paragraph object is returned, else a NoNewLineParagraph object is
         * returned.
         *
         * @param currentContent IList<IElement> of the current elements to be added.
         * @param addNewLines bool to declare which paragraph element should be
         *            returned, true if new line should be added or not.
         * @param applyCSS true if CSS should be applied on the paragraph
         * @param tag the relevant tag
         * @return a List with paragraphs
         */

        public virtual IList <IElement> CurrentContentToParagraph(IList <IElement> currentContent,
                                                                  bool addNewLines, bool applyCSS, Tag tag,
                                                                  IWorkerContext ctx)
        {
            try {
                int direction         = GetRunDirection(tag);
                IList <IElement> list = new List <IElement>();
                if (currentContent.Count > 0)
                {
                    if (addNewLines)
                    {
                        Paragraph p = CreateParagraph();
                        p.MultipliedLeading = 1.2f;
                        foreach (IElement e in currentContent)
                        {
                            if (e is LineSeparator)
                            {
                                try {
                                    HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx);
                                    Chunk newLine = (Chunk)GetCssAppliers().Apply(new Chunk(Chunk.NEWLINE), tag, htmlPipelineContext);
                                    p.Add(newLine);
                                }
                                catch (NoCustomContextException exc) {
                                    throw new RuntimeWorkerException(
                                              LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), exc);
                                }
                            }
                            p.Add(e);
                        }
                        if (p.Trim())
                        {
                            if (applyCSS)
                            {
                                p = (Paragraph)GetCssAppliers().Apply(p, tag, GetHtmlPipelineContext(ctx));
                            }
                            if (direction.Equals(PdfWriter.RUN_DIRECTION_RTL))
                            {
                                DoRtlIndentCorrections(p);
                                InvertTextAlignForParagraph(p);
                            }
                            list.Add(p);
                        }
                    }
                    else
                    {
                        NoNewLineParagraph p = new NoNewLineParagraph(float.NaN);
                        p.MultipliedLeading = 1.2f;
                        foreach (IElement e in currentContent)
                        {
                            UpdateParagraphFontIfNeeded(p, e);
                            p.Add(e);
                        }
                        p = (NoNewLineParagraph)GetCssAppliers().Apply(p, tag, GetHtmlPipelineContext(ctx));
                        if (direction.Equals(PdfWriter.RUN_DIRECTION_RTL))
                        {
                            DoRtlIndentCorrections(p);
                            InvertTextAlignForParagraph(p);
                        }
                        list.Add(p);
                    }
                }
                return(list);
            }
            catch (NoCustomContextException e) {
                throw new RuntimeWorkerException(
                          LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e);
            }
        }