Esempio n. 1
0
        public void CreateTaggedPdf16()
        {
            InitializeDocument("16");

            Paragraph p     = new Paragraph();
            Chunk     chunk = new Chunk("Hello tagged world!");

            chunk.SetBackground(new BaseColor(255, 0, 255));
            chunk.Font = FontFactory.GetFont("TimesNewRoman", 20, BaseColor.ORANGE);
            chunk.SetUnderline(BaseColor.PINK, 1.2f, 1, 1, 1, 0);
            p.Add(chunk);
            PdfDiv div = new PdfDiv();

            div.AddElement(p);
            document.Add(div);

            document.Add(new Paragraph("This paragraph appears between 2 div blocks"));

            div = new PdfDiv();
            div.AddElement(new Paragraph(text));
            document.Add(div);


            document.Close();
            int[] nums = new int[] { 48, 7 };
            CheckNums(nums);
            CompareResults("16");
        }
Esempio n. 2
0
        public void Add(IWritable htmlElement)
        {
            WritableElement writableElement = htmlElement as WritableElement;

            if (writableElement == null)
            {
                return;
            }

            foreach (IElement element in writableElement.Elements())
            {
                if (element is PdfDiv)
                {
                    PdfDiv div = element as PdfDiv;
                    foreach (IElement divChildElement in div.Content)
                    {
                        _paragraph.Add(divChildElement);
                    }
                }
                else
                {
                    _paragraph.Add(element);
                }
            }
        }
Esempio n. 3
0
        public void CreateTaggedPdf18()
        {
            InitializeDocument("18");

            PdfDiv div = new PdfDiv();

            Paragraph paragraph = new Paragraph(text);

            paragraph.Font = new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL, BaseColor.RED);

            div.BackgroundColor = BaseColor.MAGENTA;
            div.TextAlignment   = Element.ALIGN_CENTER;
            div.AddElement(paragraph);
            document.Add(div);
            document.Close();
            int[] nums = new int[] { 32 };
            CheckNums(nums);
            CompareResults("18");
        }
Esempio n. 4
0
        private void invertTextAlignForDiv(PdfDiv div)
        {
            switch (div.TextAlignment)
            {
            case Element.ALIGN_UNDEFINED:
            case Element.ALIGN_CENTER:
            case Element.ALIGN_JUSTIFIED:
            case Element.ALIGN_JUSTIFIED_ALL:
                break;

            case Element.ALIGN_RIGHT:
                div.TextAlignment = Element.ALIGN_LEFT;
                break;

            case Element.ALIGN_LEFT:
            default:
                div.TextAlignment = Element.ALIGN_RIGHT;
                break;
            }
        }
Esempio n. 5
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 {
                Paragraph p   = null;
                PdfDiv    div = (PdfDiv)GetCssAppliers().Apply(new PdfDiv(), tag, GetHtmlPipelineContext(ctx));
                foreach (IElement e in currentContent)
                {
                    if (e is Paragraph || e is PdfPTable || e is PdfDiv)
                    {
                        if (p != null)
                        {
                            if (p.Trim())
                            {
                                div.AddElement(p);
                            }
                            p = null;
                        }
                        div.AddElement(e);
                    }
                    else
                    {
                        if (p == null)
                        {
                            p = new Paragraph();
                            p.MultipliedLeading = 1.2f;
                        }
                        p.Add(e);
                    }
                }
                if (p != null && p.Trim())
                {
                    div.AddElement(p);
                }

                List <IElement> l = new List <IElement>(1);
                l.Add(div);
                return(l);
            } catch (NoCustomContextException e) {
                throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e);
            }
        }
Esempio n. 6
0
        public void CreateTaggedPdf19()
        {
            InitializeDocument("19");

            PdfDiv div = new PdfDiv();

            writer.DirectContent.OpenMCBlock(div);

            PdfArtifact artifact = new PdfArtifact();

            artifact.Type = new PdfString("Rectangle");
            writer.DirectContent.OpenMCBlock(artifact);
            writer.DirectContent.SetColorFill(BaseColor.RED);
            writer.DirectContent.Rectangle(100, 100, 400, 400);
            writer.DirectContent.Fill();
            writer.DirectContent.CloseMCBlock(artifact);

            writer.DirectContent.CloseMCBlock(div);

            document.Close();
            CompareResults("19");
        }
Esempio n. 7
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 {
                Paragraph p         = null;
                PdfDiv    div       = (PdfDiv)GetCssAppliers().Apply(new PdfDiv(), tag, GetHtmlPipelineContext(ctx));
                int       direction = GetRunDirection(tag);

                if (direction != PdfWriter.RUN_DIRECTION_NO_BIDI)
                {
                    div.RunDirection = direction;
                }

                foreach (IElement e in currentContent)
                {
                    if (e is Paragraph || e is PdfPTable || e is PdfDiv)
                    {
                        if (p != null)
                        {
                            if (p.Trim())
                            {
                                div.AddElement(p);
                            }
                            p = null;
                        }
                        div.AddElement(e);
                    }
                    else
                    {
                        if (p == null)
                        {
                            p           = new Paragraph();
                            p.Alignment = div.TextAlignment;

                            if (direction == PdfWriter.RUN_DIRECTION_RTL)
                            {
                                InvertTextAlignForParagraph(p);
                            }

                            p.MultipliedLeading = 1.2f;
                        }

                        p.Add(e);
                    }
                }

                if (p != null && p.Trim())
                {
                    div.AddElement(p);
                }

                if (direction == PdfWriter.RUN_DIRECTION_RTL)
                {
                    invertTextAlignForDiv(div);
                }

                List <IElement> l = new List <IElement>(1);
                l.Add(div);
                return(l);
            } catch (NoCustomContextException e) {
                throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e);
            }
        }
Esempio n. 8
0
        virtual public PdfDiv Apply(PdfDiv div, Tag t, IMarginMemory memory, IPageSizeContainable psc, HtmlPipelineContext context)
        {
            IDictionary <String, String> css = t.CSS;
            float fontSize = FontSizeTranslator.GetInstance().TranslateFontSize(t);

            if (fontSize == Font.UNDEFINED)
            {
                fontSize = FontSizeTranslator.DEFAULT_FONT_SIZE;
            }
            String align = null;

            if (t.Attributes.ContainsKey(HTML.Attribute.ALIGN))
            {
                align = t.Attributes[HTML.Attribute.ALIGN];
            }
            else if (css.ContainsKey(CSS.Property.TEXT_ALIGN))
            {
                align = css[CSS.Property.TEXT_ALIGN];
            }

            if (align != null)
            {
                div.TextAlignment = CSS.GetElementAlignment(align);
            }


            String widthValue;

            if (!css.TryGetValue(HTML.Attribute.WIDTH, out widthValue))
            {
                t.Attributes.TryGetValue(HTML.Attribute.WIDTH, out widthValue);
            }
            if (widthValue != null)
            {
                float pageWidth = psc.PageSize.Width;
                if (utils.IsNumericValue(widthValue) || utils.IsMetricValue(widthValue))
                {
                    div.Width = Math.Min(pageWidth, utils.ParsePxInCmMmPcToPt(widthValue));
                }
                else if (utils.IsRelativeValue(widthValue))
                {
                    if (widthValue.Contains(CSS.Value.PERCENTAGE))
                    {
                        div.PercentageWidth = utils.ParseRelativeValue(widthValue, 1f);
                    }
                    else
                    {
                        div.Width = Math.Min(pageWidth, utils.ParseRelativeValue(widthValue, fontSize));
                    }
                }
            }

            String heightValue;

            if (!css.TryGetValue(HTML.Attribute.HEIGHT, out heightValue))
            {
                t.Attributes.TryGetValue(HTML.Attribute.HEIGHT, out heightValue);
            }
            if (heightValue != null)
            {
                if (utils.IsNumericValue(heightValue) || utils.IsMetricValue(heightValue))
                {
                    div.Height = utils.ParsePxInCmMmPcToPt(heightValue);
                }
                else if (utils.IsRelativeValue(heightValue))
                {
                    if (heightValue.Contains(CSS.Value.PERCENTAGE))
                    {
                        div.PercentageHeight = utils.ParseRelativeValue(heightValue, 1f);
                    }
                    else
                    {
                        div.Height = utils.ParseRelativeValue(heightValue, fontSize);
                    }
                }
            }

            float?marginTop    = null;
            float?marginBottom = null;

            foreach (KeyValuePair <String, String> entry in css)
            {
                String key   = entry.Key;
                String value = entry.Value;
                if (Util.EqualsIgnoreCase(key, CSS.Property.LEFT))
                {
                    div.Left = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.RIGHT))
                {
                    if (div.Width == null || div.Left == null)
                    {
                        div.Right = utils.ParseValueToPt(value, fontSize);
                    }
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.TOP))
                {
                    div.Top = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.BOTTOM))
                {
                    if (div.Height == null || div.Top == null)
                    {
                        div.Bottom = utils.ParseValueToPt(value, fontSize);
                    }
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.BACKGROUND_COLOR))
                {
                    div.BackgroundColor = HtmlUtilities.DecodeColor(value);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.BACKGROUND_IMAGE))
                {
                    string url = utils.ExtractUrl(value);
                    try {
                        Image img =
                            new ImageRetrieve(context.ResourcePath, context.GetImageProvider()).RetrieveImage(url);
                        div.BackgroundImage = img;
                    }
                    catch (NoImageException e) {
                        if (LOG.IsLogging(Level.ERROR))
                        {
                            LOG.Error(string.Format(LocaleMessages.GetInstance().GetMessage("html.tag.img.failed"), url), e);
                        }
                    }
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.PADDING_LEFT))
                {
                    div.PaddingLeft = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.PADDING_RIGHT))
                {
                    div.PaddingRight = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.PADDING_TOP))
                {
                    div.PaddingTop = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.PADDING_BOTTOM))
                {
                    div.PaddingBottom = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.MARGIN_TOP))
                {
                    marginTop = utils.CalculateMarginTop(value, fontSize, memory);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.MARGIN_BOTTOM))
                {
                    marginBottom = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.FLOAT))
                {
                    if (Util.EqualsIgnoreCase(value, CSS.Value.LEFT))
                    {
                        div.Float = PdfDiv.FloatType.LEFT;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.RIGHT))
                    {
                        div.Float = PdfDiv.FloatType.RIGHT;
                    }
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.POSITION))
                {
                    if (Util.EqualsIgnoreCase(value, CSS.Value.ABSOLUTE))
                    {
                        div.Position = PdfDiv.PositionType.ABSOLUTE;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.FIXED))
                    {
                        div.Position = PdfDiv.PositionType.FIXED;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.RELATIVE))
                    {
                        div.Position = PdfDiv.PositionType.RELATIVE;
                    }
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.DISPLAY))
                {
                    if (Util.EqualsIgnoreCase(value, CSS.Value.BLOCK))
                    {
                        div.Display = PdfDiv.DisplayType.BLOCK;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.INLINE))
                    {
                        div.Display = PdfDiv.DisplayType.INLINE;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.INLINE_BLOCK))
                    {
                        div.Display = PdfDiv.DisplayType.INLINE_BLOCK;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.INLINE_TABLE))
                    {
                        div.Display = PdfDiv.DisplayType.INLINE_TABLE;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.LIST_ITEM))
                    {
                        div.Display = PdfDiv.DisplayType.LIST_ITEM;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.NONE))
                    {
                        div.Display = PdfDiv.DisplayType.NONE;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.RUN_IN))
                    {
                        div.Display = PdfDiv.DisplayType.RUN_IN;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.TABLE))
                    {
                        div.Display = PdfDiv.DisplayType.TABLE;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.TABLE_CAPTION))
                    {
                        div.Display = PdfDiv.DisplayType.TABLE_CAPTION;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.TABLE_CELL))
                    {
                        div.Display = PdfDiv.DisplayType.TABLE_CELL;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.TABLE_COLUMN_GROUP))
                    {
                        div.Display = PdfDiv.DisplayType.TABLE_COLUMN_GROUP;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.TABLE_COLUMN))
                    {
                        div.Display = PdfDiv.DisplayType.TABLE_COLUMN;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.TABLE_FOOTER_GROUP))
                    {
                        div.Display = PdfDiv.DisplayType.TABLE_FOOTER_GROUP;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.TABLE_HEADER_GROUP))
                    {
                        div.Display = PdfDiv.DisplayType.TABLE_HEADER_GROUP;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.TABLE_ROW))
                    {
                        div.Display = PdfDiv.DisplayType.TABLE_ROW;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.TABLE_ROW_GROUP))
                    {
                        div.Display = PdfDiv.DisplayType.TABLE_ROW_GROUP;
                    }
                }
                else if (Util.EqualsIgnoreCase(CSS.Property.BORDER_TOP_STYLE, key))
                {
                    if (Util.EqualsIgnoreCase(CSS.Value.DOTTED, value))
                    {
                        div.BorderStyle = PdfDiv.BorderTopStyle.DOTTED;
                    }
                    else if (Util.EqualsIgnoreCase(CSS.Value.DASHED, value))
                    {
                        div.BorderStyle = PdfDiv.BorderTopStyle.DASHED;
                    }
                    else if (Util.EqualsIgnoreCase(CSS.Value.SOLID, value))
                    {
                        div.BorderStyle = PdfDiv.BorderTopStyle.SOLID;
                    }
                    else if (Util.EqualsIgnoreCase(CSS.Value.DOUBLE, value))
                    {
                        div.BorderStyle = PdfDiv.BorderTopStyle.DOUBLE;
                    }
                    else if (Util.EqualsIgnoreCase(CSS.Value.GROOVE, value))
                    {
                        div.BorderStyle = PdfDiv.BorderTopStyle.GROOVE;
                    }
                    else if (Util.EqualsIgnoreCase(CSS.Value.RIDGE, value))
                    {
                        div.BorderStyle = PdfDiv.BorderTopStyle.RIDGE;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.INSET))
                    {
                        div.BorderStyle = PdfDiv.BorderTopStyle.INSET;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.OUTSET))
                    {
                        div.BorderStyle = PdfDiv.BorderTopStyle.OUTSET;
                    }
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.PAGE_BREAK_INSIDE))
                {
                    if (Util.EqualsIgnoreCase(value, CSS.Value.AVOID))
                    {
                        div.KeepTogether = true;
                    }
                }

                //TODO: border, background properties.
            }

            return(div);
        }
Esempio n. 9
0
        public PdfDiv apply(PdfDiv div, Tag t, IMarginMemory memory, IPageSizeContainable psc)
        {
            IDictionary <String, String> css = t.CSS;
            float fontSize = FontSizeTranslator.GetInstance().TranslateFontSize(t);

            if (fontSize == Font.UNDEFINED)
            {
                fontSize = FontSizeTranslator.DEFAULT_FONT_SIZE;
            }
            String align = null;

            if (t.Attributes.ContainsKey(HTML.Attribute.ALIGN))
            {
                align = t.Attributes[HTML.Attribute.ALIGN];
            }
            else if (css.ContainsKey(CSS.Property.TEXT_ALIGN))
            {
                align = css[CSS.Property.TEXT_ALIGN];
            }

            if (align != null)
            {
                if (Util.EqualsIgnoreCase(align, CSS.Value.CENTER))
                {
                    div.TextAlignment = Element.ALIGN_CENTER;
                }
                else if (Util.EqualsIgnoreCase(align, CSS.Value.RIGHT))
                {
                    div.TextAlignment = Element.ALIGN_RIGHT;
                }
                else if (Util.EqualsIgnoreCase(align, CSS.Value.JUSTIFY))
                {
                    div.TextAlignment = Element.ALIGN_JUSTIFIED;
                }
            }


            String widthValue;

            if (!t.CSS.TryGetValue(HTML.Attribute.WIDTH, out widthValue))
            {
                t.Attributes.TryGetValue(HTML.Attribute.WIDTH, out widthValue);
            }
            if (widthValue != null)
            {
                if (utils.IsNumericValue(widthValue) || utils.IsMetricValue(widthValue))
                {
                    div.Width = utils.ParsePxInCmMmPcToPt(widthValue);
                }
                else if (utils.IsRelativeValue(widthValue))
                {
                    if (widthValue.Contains(CSS.Value.PERCENTAGE))
                    {
                        div.PercentageWidth = utils.ParseRelativeValue(widthValue, 1f);
                    }
                    else
                    {
                        div.Width = utils.ParseRelativeValue(widthValue, fontSize);
                    }
                }
            }

            String heightValue;

            if (!t.CSS.TryGetValue(HTML.Attribute.HEIGHT, out heightValue))
            {
                t.Attributes.TryGetValue(HTML.Attribute.HEIGHT, out heightValue);
            }
            if (heightValue != null)
            {
                if (utils.IsNumericValue(heightValue) || utils.IsMetricValue(heightValue))
                {
                    div.Height = utils.ParsePxInCmMmPcToPt(heightValue);
                }
                else if (utils.IsRelativeValue(heightValue))
                {
                    if (heightValue.Contains(CSS.Value.PERCENTAGE))
                    {
                        div.PercentageHeight = utils.ParseRelativeValue(heightValue, 1f);
                    }
                    else
                    {
                        div.Height = utils.ParseRelativeValue(heightValue, fontSize);
                    }
                }
            }

            float?marginTop    = null;
            float?marginBottom = null;

            foreach (KeyValuePair <String, String> entry in css)
            {
                String key   = entry.Key;
                String value = entry.Value;
                if (Util.EqualsIgnoreCase(key, CSS.Property.LEFT))
                {
                    div.Left = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.RIGHT))
                {
                    if (div.Width == null || div.Left == null)
                    {
                        div.Right = utils.ParseValueToPt(value, fontSize);
                    }
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.TOP))
                {
                    div.Top = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.BOTTOM))
                {
                    if (div.Height == null || div.Top == null)
                    {
                        div.Bottom = utils.ParseValueToPt(value, fontSize);
                    }
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.BACKGROUND_COLOR))
                {
                    div.BackgroundColor = HtmlUtilities.DecodeColor(value);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.PADDING_LEFT))
                {
                    div.PaddingLeft = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.PADDING_RIGHT))
                {
                    div.PaddingRight = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.PADDING_TOP))
                {
                    div.PaddingTop = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.PADDING_BOTTOM))
                {
                    div.PaddingBottom = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.MARGIN_TOP))
                {
                    marginTop = utils.CalculateMarginTop(value, fontSize, memory);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.MARGIN_BOTTOM))
                {
                    marginBottom = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.FLOAT))
                {
                    if (Util.EqualsIgnoreCase(value, CSS.Value.LEFT))
                    {
                        div.Float = PdfDiv.FloatType.LEFT;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.RIGHT))
                    {
                        div.Float = PdfDiv.FloatType.RIGHT;
                    }
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.POSITION))
                {
                    if (Util.EqualsIgnoreCase(value, CSS.Value.ABSOLUTE))
                    {
                        div.Position = PdfDiv.PositionType.ABSOLUTE;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.FIXED))
                    {
                        div.Position = PdfDiv.PositionType.FIXED;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.RELATIVE))
                    {
                        div.Position = PdfDiv.PositionType.RELATIVE;
                    }
                }

                //TODO: border, background properties.
            }

            return(div);
        }
Esempio n. 10
0
        virtual public PdfDiv apply(PdfDiv div, Tag t, IMarginMemory memory, IPageSizeContainable psc)
        {
            IDictionary <String, String> css = t.CSS;
            float fontSize = FontSizeTranslator.GetInstance().TranslateFontSize(t);

            if (fontSize == Font.UNDEFINED)
            {
                fontSize = FontSizeTranslator.DEFAULT_FONT_SIZE;
            }
            String align = null;

            if (t.Attributes.ContainsKey(HTML.Attribute.ALIGN))
            {
                align = t.Attributes[HTML.Attribute.ALIGN];
            }
            else if (css.ContainsKey(CSS.Property.TEXT_ALIGN))
            {
                align = css[CSS.Property.TEXT_ALIGN];
            }

            if (align != null)
            {
                if (Util.EqualsIgnoreCase(align, CSS.Value.CENTER))
                {
                    div.TextAlignment = Element.ALIGN_CENTER;
                }
                else if (Util.EqualsIgnoreCase(align, CSS.Value.LEFT))
                {
                    div.TextAlignment = Element.ALIGN_LEFT;
                }
                else if (Util.EqualsIgnoreCase(align, CSS.Value.RIGHT))
                {
                    div.TextAlignment = Element.ALIGN_RIGHT;
                }
                else if (Util.EqualsIgnoreCase(align, CSS.Value.JUSTIFY))
                {
                    div.TextAlignment = Element.ALIGN_JUSTIFIED;
                }
            }


            String widthValue;

            if (!t.CSS.TryGetValue(HTML.Attribute.WIDTH, out widthValue))
            {
                t.Attributes.TryGetValue(HTML.Attribute.WIDTH, out widthValue);
            }
            if (widthValue != null)
            {
                float pageWidth = psc.PageSize.Width;
                if (utils.IsNumericValue(widthValue) || utils.IsMetricValue(widthValue))
                {
                    div.Width = Math.Min(pageWidth, utils.ParsePxInCmMmPcToPt(widthValue));
                }
                else if (utils.IsRelativeValue(widthValue))
                {
                    if (widthValue.Contains(CSS.Value.PERCENTAGE))
                    {
                        div.PercentageWidth = utils.ParseRelativeValue(widthValue, 1f);
                    }
                    else
                    {
                        div.Width = Math.Min(pageWidth, utils.ParseRelativeValue(widthValue, fontSize));
                    }
                }
            }

            String heightValue;

            if (!t.CSS.TryGetValue(HTML.Attribute.HEIGHT, out heightValue))
            {
                t.Attributes.TryGetValue(HTML.Attribute.HEIGHT, out heightValue);
            }
            if (heightValue != null)
            {
                if (utils.IsNumericValue(heightValue) || utils.IsMetricValue(heightValue))
                {
                    div.Height = utils.ParsePxInCmMmPcToPt(heightValue);
                }
                else if (utils.IsRelativeValue(heightValue))
                {
                    if (heightValue.Contains(CSS.Value.PERCENTAGE))
                    {
                        div.PercentageHeight = utils.ParseRelativeValue(heightValue, 1f);
                    }
                    else
                    {
                        div.Height = utils.ParseRelativeValue(heightValue, fontSize);
                    }
                }
            }

            float?marginTop    = null;
            float?marginBottom = null;

            foreach (KeyValuePair <String, String> entry in css)
            {
                String key   = entry.Key;
                String value = entry.Value;
                if (Util.EqualsIgnoreCase(key, CSS.Property.LEFT))
                {
                    div.Left = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.RIGHT))
                {
                    if (div.Width == null || div.Left == null)
                    {
                        div.Right = utils.ParseValueToPt(value, fontSize);
                    }
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.TOP))
                {
                    div.Top = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.BOTTOM))
                {
                    if (div.Height == null || div.Top == null)
                    {
                        div.Bottom = utils.ParseValueToPt(value, fontSize);
                    }
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.BACKGROUND_COLOR))
                {
                    div.BackgroundColor = HtmlUtilities.DecodeColor(value);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.PADDING_LEFT))
                {
                    div.PaddingLeft = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.PADDING_RIGHT))
                {
                    div.PaddingRight = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.PADDING_TOP))
                {
                    div.PaddingTop = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.PADDING_BOTTOM))
                {
                    div.PaddingBottom = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.MARGIN_TOP))
                {
                    marginTop = utils.CalculateMarginTop(value, fontSize, memory);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.MARGIN_BOTTOM))
                {
                    marginBottom = utils.ParseValueToPt(value, fontSize);
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.FLOAT))
                {
                    if (Util.EqualsIgnoreCase(value, CSS.Value.LEFT))
                    {
                        div.Float = PdfDiv.FloatType.LEFT;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.RIGHT))
                    {
                        div.Float = PdfDiv.FloatType.RIGHT;
                    }
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.POSITION))
                {
                    if (Util.EqualsIgnoreCase(value, CSS.Value.ABSOLUTE))
                    {
                        div.Position = PdfDiv.PositionType.ABSOLUTE;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.FIXED))
                    {
                        div.Position = PdfDiv.PositionType.FIXED;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.RELATIVE))
                    {
                        div.Position = PdfDiv.PositionType.RELATIVE;
                    }
                }
                else if (Util.EqualsIgnoreCase(key, CSS.Property.DISPLAY))
                {
                    if (Util.EqualsIgnoreCase(value, CSS.Value.BLOCK))
                    {
                        div.Display = PdfDiv.DisplayType.BLOCK;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.INLINE))
                    {
                        div.Display = PdfDiv.DisplayType.INLINE;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.INLINE_BLOCK))
                    {
                        div.Display = PdfDiv.DisplayType.INLINE_BLOCK;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.INLINE_TABLE))
                    {
                        div.Display = PdfDiv.DisplayType.INLINE_TABLE;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.LIST_ITEM))
                    {
                        div.Display = PdfDiv.DisplayType.LIST_ITEM;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.NONE))
                    {
                        div.Display = PdfDiv.DisplayType.NONE;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.RUN_IN))
                    {
                        div.Display = PdfDiv.DisplayType.RUN_IN;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.TABLE))
                    {
                        div.Display = PdfDiv.DisplayType.TABLE;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.TABLE_CAPTION))
                    {
                        div.Display = PdfDiv.DisplayType.TABLE_CAPTION;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.TABLE_CELL))
                    {
                        div.Display = PdfDiv.DisplayType.TABLE_CELL;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.TABLE_COLUMN_GROUP))
                    {
                        div.Display = PdfDiv.DisplayType.TABLE_COLUMN_GROUP;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.TABLE_COLUMN))
                    {
                        div.Display = PdfDiv.DisplayType.TABLE_COLUMN;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.TABLE_FOOTER_GROUP))
                    {
                        div.Display = PdfDiv.DisplayType.TABLE_FOOTER_GROUP;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.TABLE_HEADER_GROUP))
                    {
                        div.Display = PdfDiv.DisplayType.TABLE_HEADER_GROUP;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.TABLE_ROW))
                    {
                        div.Display = PdfDiv.DisplayType.TABLE_ROW;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.TABLE_ROW_GROUP))
                    {
                        div.Display = PdfDiv.DisplayType.TABLE_ROW_GROUP;
                    }
                }
                else if (Util.EqualsIgnoreCase(CSS.Property.BORDER_TOP_STYLE, key))
                {
                    if (Util.EqualsIgnoreCase(CSS.Value.DOTTED, value))
                    {
                        div.BorderStyle = PdfDiv.BorderTopStyle.DOTTED;
                    }
                    else if (Util.EqualsIgnoreCase(CSS.Value.DASHED, value))
                    {
                        div.BorderStyle = PdfDiv.BorderTopStyle.DASHED;
                    }
                    else if (Util.EqualsIgnoreCase(CSS.Value.SOLID, value))
                    {
                        div.BorderStyle = PdfDiv.BorderTopStyle.SOLID;
                    }
                    else if (Util.EqualsIgnoreCase(CSS.Value.DOUBLE, value))
                    {
                        div.BorderStyle = PdfDiv.BorderTopStyle.DOUBLE;
                    }
                    else if (Util.EqualsIgnoreCase(CSS.Value.GROOVE, value))
                    {
                        div.BorderStyle = PdfDiv.BorderTopStyle.GROOVE;
                    }
                    else if (Util.EqualsIgnoreCase(CSS.Value.RIDGE, value))
                    {
                        div.BorderStyle = PdfDiv.BorderTopStyle.RIDGE;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.INSET))
                    {
                        div.BorderStyle = PdfDiv.BorderTopStyle.INSET;
                    }
                    else if (Util.EqualsIgnoreCase(value, CSS.Value.OUTSET))
                    {
                        div.BorderStyle = PdfDiv.BorderTopStyle.OUTSET;
                    }
                }

                //TODO: border, background properties.
            }

            return(div);
        }
Esempio n. 11
0
        private MemoryStream CCMPDFDATA(DataSet Ds, string PdfTitle)
        {
            PdfDiv DvHeaderMain = new PdfDiv();

            PdfDiv DvHeaderHead    = new PdfDiv();
            PdfDiv DvHeaderHeadSub = new PdfDiv();
            PdfDiv DvHeaderLeft    = new PdfDiv();
            PdfDiv DvSubHeaderLeft = new PdfDiv();
            PdfDiv DvHeaderRight   = new PdfDiv();
            PdfDiv DvHeaderLogo    = new PdfDiv();
            PdfDiv DvData          = new PdfDiv();


            ///LOGO
            ///
            iTextSharp.text.Image logoimg = null;
            logoimg = iTextSharp.text.Image.GetInstance(System.Web.HttpContext.Current.Server.MapPath("~/App_Themes/NewTheme/Images/Geesemed_logo.jpg"));
            logoimg.ScaleToFit(80f, 80f);
            logoimg.Alignment = iTextSharp.text.Image.ALIGN_RIGHT;

            DvHeaderLogo.AddElement(logoimg);
            DvHeaderLogo.TextAlignment = Element.ALIGN_RIGHT;


            MemoryStream ms = new MemoryStream();

            iTextSharp.text.Rectangle rect = PageSize.A4;
            Document  CCMDoc     = new Document(rect, 25f, 25f, 25f, 40f);
            PdfWriter writer_Sub = PdfWriter.GetInstance(CCMDoc, ms);

            writer_Sub.PageEvent = new PDFDashBoardFooter();

            CCMDoc.Open();

            DvHeaderMain.AddElement(logoimg);


            // ClientMasterDAL objClient = new ClientMasterDAL(SessionManager.CONNECTIONSTRING);
            DataTable dtHead = new DataTable();
            //dtHead = objClient.GetClient_Master(SessionManager.CLIENT_ID);
            string CliName   = "";
            string CliAdd    = "";
            string CityState = "";
            string PhoneFax  = "";
            string City      = "";
            string State     = "";
            string Zip       = "";
            string Phone     = "";
            string FAX       = "";

            if (dtHead.Rows.Count != 0)
            {
                CliName = Convert.ToString(dtHead.Rows[0]["mclnt_name"]);
                CliAdd  = Convert.ToString(dtHead.Rows[0]["mdl_add1"]) + " " + Convert.ToString(dtHead.Rows[0]["mdl_add2"]);
                City    = Convert.ToString(dtHead.Rows[0]["city_name"]);
                State   = Convert.ToString(dtHead.Rows[0]["state_code"]);
                Zip     = Convert.ToString(dtHead.Rows[0]["zip_code"]);
                Phone   = Convert.ToString(dtHead.Rows[0]["mclnt_cont_phone"]);
                FAX     = Convert.ToString(dtHead.Rows[0]["mclnt_fax"]);
            }



            if (City != "")
            {
                CityState += City;
            }
            if (State != "")
            {
                CityState += (City != "" ? ", " : "") + State;
            }
            if (Zip != "")
            {
                CityState += " " + Zip;
            }
            if (Phone != "")
            {
                PhoneFax += "(T): " + Phone;
            }
            if (FAX != "")
            {
                PhoneFax += " (F): " + FAX;
            }

            //LEFT
            string PatName = string.Empty;
            string BDate   = string.Empty;
            string Gender  = string.Empty;

            if (Ds.Tables[0].Rows.Count != 0)
            {
                PatName = Ds.Tables[0].Rows[0]["mpt_pat_name"].ToString();
                BDate   = Ds.Tables[0].Rows[0]["BDate"].ToString();
                Gender  = Ds.Tables[0].Rows[0]["mpt_pat_sex"].ToString();
            }
            //  clsHospital objHosp = new clsHospital(SessionManager.CONNECTIONSTRING, SessionManager.HOSPITAL_ID);
            string hospName = "trest"; //objHosp.getHospitalName();


            //   DvHeaderLeft.Float = PdfDiv.FloatType.LEFT;


            DvHeaderLeft.AddElement(new Chunk(hospName + "\n", ITextSharpHelper.GetCommonSubTitle_Chart()));
            DvHeaderLeft.AddElement(new Chunk(CliName + "\n", ITextSharpHelper.GetCommonSubTitle_Chart()));
            DvHeaderLeft.AddElement(new Chunk(CliAdd + "\n", ITextSharpHelper.GetCommonSubTitle_Chart()));
            DvHeaderLeft.AddElement(new Chunk(CityState + "\n", ITextSharpHelper.GetCommonSubTitle_Chart()));
            DvHeaderLeft.AddElement(new Chunk(PhoneFax + "\n", ITextSharpHelper.GetCommonSubTitle_Chart()));


            DvHeaderLeft.Width      = 180f;
            DvHeaderLeft.PaddingTop = 10f;
            DvHeaderMain.AddElement(DvHeaderLeft);


            //RIGHT
            PdfPTable PtableRight = new PdfPTable(1);

            DvHeaderRight.Float = PdfDiv.FloatType.RIGHT;


            PdfPCell cell = new PdfPCell(new Phrase(new Chunk(PdfTitle, ITextSharpHelper.GetCommonSubTitle_Chart())));

            cell.Border = 0;
            cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
            PtableRight.AddCell(cell);



            DvHeaderRight.PaddingTop = 10f;
            DvHeaderRight.Width      = 290f;
            DvHeaderRight.AddElement(PtableRight);

            DvHeaderMain.AddElement(DvHeaderRight);

            ///SUB Head



            DvSubHeaderLeft.AddElement(new Chunk(new LineSeparator(0.8f, 100f, BaseColor.GRAY, Element.ALIGN_CENTER, 1)));



            DvSubHeaderLeft.AddElement(new Chunk("Patient :- " + PatName + "\n", ITextSharpHelper.GetCommonSubTitle_Chart()));
            DvSubHeaderLeft.AddElement(new Chunk("DOB :- " + BDate + "\n", ITextSharpHelper.GetCommonSubTitle_Chart()));
            DvSubHeaderLeft.AddElement(new Chunk("Gender :- " + Gender + "\n", ITextSharpHelper.GetCommonSubTitle_Chart()));
            DvSubHeaderLeft.AddElement(new Chunk("Physician :- " + Ds.Tables[1].Rows[0]["ProName"].ToString() + "\n", ITextSharpHelper.GetCommonSubTitle_Chart()));



            DvSubHeaderLeft.Width = 540f;
            //   DvSubHeaderLeft.PercentageWidth = 80f;
            DvHeaderMain.AddElement(DvSubHeaderLeft);


            CCMDoc.Add(DvHeaderMain);
            //DvData.AddElement(ExportToPdf(Ds));
            ExportToPdf(Ds, ref CCMDoc);
            //DvHeaderMain.AddElement(DvData);



            CCMDoc.Close();

            return(ms);
        }