iTextSharp.text.Document.Add C# (CSharp) Метод

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

Adds an Element to the Document.
public Add ( IElement element ) : bool
element IElement the Element to add
Результат bool
        public virtual bool Add(IElement element)
        {
            if (close) {
                throw new DocumentException(MessageLocalization.GetComposedMessage("the.document.has.been.closed.you.can.t.add.any.elements"));
            }
            if (!open && element.IsContent()) {
                throw new DocumentException(MessageLocalization.GetComposedMessage("the.document.is.not.open.yet.you.can.only.add.meta.information"));
            }
            bool success = false;
            if (element is ChapterAutoNumber) {
                chapternumber = ((ChapterAutoNumber)element).SetAutomaticNumber(chapternumber);
            }
            foreach (IDocListener listener in listeners) {
                success |= listener.Add(element);
            }
            if (element is ILargeElement) {
                ILargeElement e = (ILargeElement)element;
                if (!e.ElementComplete)
                    e.FlushContent();
            }
            return success;
        }

Usage Example

        public override byte[] CreatePdf(List<PdfContentParameter> contents, string[] images, int type)
        {
            var document = new Document();
            float docHeight = document.PageSize.Height - heightOffset;
            document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
            document.SetMargins(50, 50, 10, 40);

            var output = new MemoryStream();
            var writer = PdfWriter.GetInstance(document, output);

            writer.PageEvent = new HeaderFooterHandler(type);

            document.Open();

            document.Add(contents[0].Table);

            for (int i = 0; i < images.Length; i++)
            {
                document.NewPage();
                float subtrahend = document.PageSize.Height - heightOffset;
                iTextSharp.text.Image pool = iTextSharp.text.Image.GetInstance(images[i]);
                pool.Alignment = 3;
                pool.ScaleToFit(document.PageSize.Width - (document.RightMargin * 2), subtrahend);
                //pool.ScaleAbsolute(document.PageSize.Width - (document.RightMargin * 2), subtrahend);
                document.Add(pool);
            }

            document.Close();
            return output.ToArray();
        }
All Usage Examples Of iTextSharp.text.Document::Add