iTextSharp.text.pdf.PdfStructureElement.SetAttribute C# (CSharp) Метод

SetAttribute() публичный Метод

public SetAttribute ( PdfName name, PdfObject obj ) : void
name PdfName
obj PdfObject
Результат void
        public void SetAttribute(PdfName name, PdfObject obj)
        {
            PdfDictionary attr = GetAsDict(PdfName.A);
            if (attr == null) {
                attr = new PdfDictionary();
                Put(PdfName.A, attr);
            }
            attr.Put(name, obj);
        }

Usage Example

Пример #1
0
        private PdfStructureElement OpenMCBlockInt(IElement element)
        {
            PdfStructureElement structureElement = null;
            if (writer.IsTagged()) {
                if (element is Paragraph) {
                    if (!pdf.structElements.TryGetValue(element, out structureElement)) {
                        structureElement = new PdfStructureElement(GetParentStructureElement(), PdfName.P);
                        Paragraph p = (Paragraph) element;

                        // Setting non-inheritable attributes
                        if ((p.Font != null) && (p.Font.Color != null)) {
                            BaseColor c = p.Font.Color;
                            float[] colors = new float[] {c.R / 255f, c.G / 255f, c.B / 255f};
                            structureElement.Put(PdfName.COLOR, new PdfArray(colors));
                        }
                        float epsilon = 0.0001f;
                        if (Math.Abs(p.SpacingBefore) > epsilon)
                            structureElement.SetAttribute(PdfName.SPACEBEFORE, new PdfNumber(p.SpacingBefore));
                        if (Math.Abs(p.SpacingAfter) > epsilon)
                            structureElement.SetAttribute(PdfName.SPACEAFTER, new PdfNumber(p.SpacingAfter));
                        if (Math.Abs(p.FirstLineIndent) > epsilon)
                            structureElement.SetAttribute(PdfName.TEXTINDENT, new PdfNumber(p.FirstLineIndent));

                        // Setting inheritable attributes
                        IPdfStructureElement parent = GetParentStructureInterface();
                        PdfObject obj = parent.GetAttribute(PdfName.STARTINDENT);
                        if (obj is PdfNumber) {
                            float startIndent = ((PdfNumber) obj).FloatValue;
                            if (Math.Abs(startIndent - p.IndentationLeft) > epsilon)
                                structureElement.SetAttribute(PdfName.STARTINDENT, new PdfNumber(p.IndentationLeft));
                        } else {
                            if (Math.Abs(p.IndentationLeft) > epsilon)
                                structureElement.SetAttribute(PdfName.STARTINDENT, new PdfNumber(p.IndentationLeft));
                        }

                        obj = parent.GetAttribute(PdfName.ENDINDENT);
                        if (obj is PdfNumber) {
                            float endIndent = ((PdfNumber)obj).FloatValue;
                            if (Math.Abs(endIndent - p.IndentationRight) > epsilon)
                                structureElement.SetAttribute(PdfName.ENDINDENT, new PdfNumber(p.IndentationRight));
                        } else {
                            if (Math.Abs(p.IndentationRight) > epsilon)
                                structureElement.SetAttribute(PdfName.ENDINDENT, new PdfNumber(p.IndentationRight));
                        }

                        PdfName align = null;
                        switch (p.Alignment) {
                            case Element.ALIGN_LEFT:
                                align = PdfName.START;
                                break;
                            case Element.ALIGN_CENTER:
                                align = PdfName.CENTER;
                                break;
                            case Element.ALIGN_RIGHT:
                                align = PdfName.END;
                                break;
                            case Element.ALIGN_JUSTIFIED:
                                align = PdfName.JUSTIFY;
                                break;
                        }
                        obj = parent.GetAttribute(PdfName.TEXTALIGN);
                        if (obj
                        is PdfName) {
                            PdfName textAlign = ((PdfName)obj);
                            if (align != null && !textAlign.Equals(align))
                                structureElement.SetAttribute(PdfName.TEXTALIGN, align);
                        } else {
                            if (align != null && !PdfName.START.Equals(align))
                                structureElement.SetAttribute(PdfName.TEXTALIGN, align);
                        }

                    }
                    if (inText && autoControlTextBlocks) {
                        EndText();
                    }
                    BeginMarkedContentSequence(structureElement);
                }
            }
            return structureElement;
        }