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

Sets a new page tag.
public SetNewPage ( ) : Chunk
Результат Chunk
Пример #1
1
        /// <summary>
        /// This method deals with the starting tags.
        /// </summary>
        /// <param name="name">the name of the tag</param>
        /// <param name="attributes">the list of attributes</param>
        public void HandleStartingTags(String name, Properties attributes) {
            //System.err.Println("Start: " + name);
            if (ignore || ElementTags.IGNORE.Equals(name)) {
                ignore = true;
                return;
            }
        
            // maybe there is some meaningful data that wasn't between tags
            if (currentChunk != null) {
                ITextElementArray current;
                try {
                    current = (ITextElementArray) stack.Pop();
                }
                catch {
                    if (bf == null) {
                        current = new Paragraph("", new Font());
                    }
                    else {
                        current = new Paragraph("", new Font(this.bf));
                    }
                }
                current.Add(currentChunk);
                stack.Push(current);
                currentChunk = null;
            }

            // registerfont
            if (name.Equals("registerfont")) {
                FontFactory.Register(attributes);
            }

            // header
            if (ElementTags.HEADER.Equals(name)) {
                stack.Push(new HeaderFooter(attributes));
                return;
            }

            // footer
            if (ElementTags.FOOTER.Equals(name)) {
                stack.Push(new HeaderFooter(attributes));
                return;
            }

            // before
            if (name.Equals("before")) {
                HeaderFooter tmp = (HeaderFooter)stack.Pop();

                tmp.Before = ElementFactory.GetPhrase(attributes);
                stack.Push(tmp);
                return;
            }
        
            // after
            if (name.Equals("after")) {
                HeaderFooter tmp = (HeaderFooter)stack.Pop();

                tmp.After = ElementFactory.GetPhrase(attributes);
                stack.Push(tmp);
                return;
            }
        
            // chunks
            if (ElementTags.CHUNK.Equals(name)) {
                currentChunk = ElementFactory.GetChunk(attributes);
                if (bf != null) {
                    currentChunk.Font = new Font(this.bf);
                }
                return;
            }
        
            // symbols
            if (ElementTags.ENTITY.Equals(name)) {
                Font f = new Font();
                if (currentChunk != null) {
                    HandleEndingTags(ElementTags.CHUNK);
                    f = currentChunk.Font;
                }
                currentChunk = EntitiesToSymbol.Get(attributes[ElementTags.ID], f);
                return;
            }

            // phrases
            if (ElementTags.PHRASE.Equals(name)) {
                stack.Push(ElementFactory.GetPhrase(attributes));
                return;
            }
        
            // anchors
            if (ElementTags.ANCHOR.Equals(name)) {
                stack.Push(ElementFactory.GetAnchor(attributes));
                return;
            }
        
            // paragraphs and titles
            if (ElementTags.PARAGRAPH.Equals(name) || ElementTags.TITLE.Equals(name)) {
                stack.Push(ElementFactory.GetParagraph(attributes));
                return;
            }
        
            // lists
            if (ElementTags.LIST.Equals(name)) {
                stack.Push(ElementFactory.GetList(attributes));
                return;
            }
        
            // listitems
            if (ElementTags.LISTITEM.Equals(name)) {
                stack.Push(ElementFactory.GetListItem(attributes));
                return;
            }
        
            // cells
            if (ElementTags.CELL.Equals(name)) {
                stack.Push(ElementFactory.GetCell(attributes));
                return;
            }
        
            // tables
            if (ElementTags.TABLE.Equals(name)) {
                Table table = ElementFactory.GetTable(attributes);
                float[] widths = table.ProportionalWidths;
                for (int i = 0; i < widths.Length; i++) {
                    if (widths[i] == 0) {
                        widths[i] = 100.0f / (float)widths.Length;
                    }
                }
                try {
                    table.Widths = widths;
                }
                catch (BadElementException bee) {
                    // this shouldn't happen
                    throw new Exception("", bee);
                }
                stack.Push(table);
                return;
            }
        
            // sections
            if (ElementTags.SECTION.Equals(name)) {
                IElement previous = (IElement) stack.Pop();
                Section section;
                section = ElementFactory.GetSection((Section) previous, attributes);
                stack.Push(previous);
                stack.Push(section);
                return;
            }
        
            // chapters
            if (ElementTags.CHAPTER.Equals(name)) {
                stack.Push(ElementFactory.GetChapter(attributes));
                return;
            }
        
            // images
            if (ElementTags.IMAGE.Equals(name)) {
                try {
                    Image img = ElementFactory.GetImage(attributes);
                    try {
                        AddImage(img);
                        return;
                    }
                    catch {
                        // if there is no element on the stack, the Image is added to the document
                        try {
                            document.Add(img);
                        }
                        catch (DocumentException de) {
                            throw new Exception("", de);
                        }
                        return;
                    }
                }
                catch (Exception e) {
                    throw new Exception("", e);
                }
            }
        
            // annotations
            if (ElementTags.ANNOTATION.Equals(name)) {
                Annotation annotation = ElementFactory.GetAnnotation(attributes);
                ITextElementArray current;
                try {
                    try {
                        current = (ITextElementArray) stack.Pop();
                        try {
                            current.Add(annotation);
                        }
                        catch {
                            document.Add(annotation);
                        }
                        stack.Push(current);
                    }
                    catch {
                        document.Add(annotation);
                    }
                    return;
                }
                catch (DocumentException de) {
                    throw de;
                }
            }
        
            // newlines
            if (IsNewline(name)) {
                ITextElementArray current;
                try {
                    current = (ITextElementArray) stack.Pop();
                    current.Add(Chunk.NEWLINE);
                    stack.Push(current);
                }
                catch {
                    if (currentChunk == null) {
                        try {
                            document.Add(Chunk.NEWLINE);
                        }
                        catch (DocumentException de) {
                            throw de;
                        }
                    }
                    else {
                        currentChunk.Append("\n");
                    }
                }
                return;
            }
        
            // newpage
            if (IsNewpage(name)) {
                ITextElementArray current;
                try {
                    current = (ITextElementArray) stack.Pop();
                    Chunk newPage = new Chunk("");
                    newPage.SetNewPage();
                    if (bf != null) {
                        newPage.Font = new Font(this.bf);
                    }
                    current.Add(newPage);
                    stack.Push(current);
                }
                catch {
                    document.NewPage();
                }
                return;
            }
        
            if (ElementTags.HORIZONTALRULE.Equals(name)) {
                ITextElementArray current;
                LineSeparator hr = new LineSeparator(1.0f, 100.0f, null, Element.ALIGN_CENTER, 0);
                try {
                    current = (ITextElementArray)stack.Pop();
                    current.Add(hr);
                    stack.Push(current);
                } catch (InvalidOperationException) {
                    document.Add(hr);
                }
                return;
            }
            
            // documentroot
            if (IsDocumentRoot(name)) {
                String value;
                // pagesize and orientation specific code suggested by Samuel Gabriel
                // Updated by Ricardo Coutinho. Only use if set in html!
                Rectangle pageSize = null;
                String orientation = null;
                foreach (string key in attributes.Keys) {
                    value = attributes[key];
                    // margin specific code suggested by Reza Nasiri
                    if (Util.EqualsIgnoreCase(ElementTags.LEFT, key))
                        leftMargin = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
                    if (Util.EqualsIgnoreCase(ElementTags.RIGHT, key))
                        rightMargin = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
                    if (Util.EqualsIgnoreCase(ElementTags.TOP, key))
                        topMargin = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
                    if (Util.EqualsIgnoreCase(ElementTags.BOTTOM, key))
                        bottomMargin = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
                    if (ElementTags.PAGE_SIZE.Equals(key)) {
                        pageSize = (Rectangle)typeof(PageSize).GetField(value).GetValue(null);
                    } else if (ElementTags.ORIENTATION.Equals(key)) {
                        if ("landscape".Equals(value)) {
                            orientation = "landscape";
                        }
                    } else {
                        document.Add(new Meta(key, value));
                    }
                }
                if (pageSize != null) {
                    if ("landscape".Equals(orientation)) {
                        pageSize = pageSize.Rotate();
                    }
                    document.SetPageSize(pageSize);
                }
                document.SetMargins(leftMargin, rightMargin, topMargin,
                        bottomMargin);
                if (controlOpenClose)
                    document.Open();
            }
        }
Пример #2
0
 static Chunk()
 {
     NEXTPAGE.SetNewPage();
     NEWLINE.Role = PdfName.P;
 }
Пример #3
0
 static Chunk()
 {
     NEXTPAGE.SetNewPage();
 }
Пример #4
0
        /// <summary>
        /// This method deals with the starting tags.
        /// </summary>
        /// <param name="name">the name of the tag</param>
        /// <param name="attributes">the list of attributes</param>
        public void HandleStartingTags(String name, Properties attributes)
        {
            //System.err.Println("Start: " + name);
            if (ignore || ElementTags.IGNORE.Equals(name)) {
                ignore = true;
                return;
            }

            // maybe there is some meaningful data that wasn't between tags
            if (currentChunk != null) {
                ITextElementArray current;
                try {
                    current = (ITextElementArray) stack.Pop();
                }
                catch {
                    if (bf == null) {
                        current = new Paragraph("", new Font());
                    }
                    else {
                        current = new Paragraph("", new Font(this.bf));
                    }
                }
                current.Add(currentChunk);
                stack.Push(current);
                currentChunk = null;
            }

            // registerfont
            if (name.Equals("registerfont")) {
                FontFactory.Register(attributes);
            }

            // header
            if (ElementTags.HEADER.Equals(name)) {
                stack.Push(new HeaderFooter(attributes));
                return;
            }

            // footer
            if (ElementTags.FOOTER.Equals(name)) {
                stack.Push(new HeaderFooter(attributes));
                return;
            }

            // before
            if (name.Equals("before")) {
                HeaderFooter tmp = (HeaderFooter)stack.Pop();

                tmp.Before = new Phrase(attributes);
                stack.Push(tmp);
                return;
            }

            // after
            if (name.Equals("after")) {
                HeaderFooter tmp = (HeaderFooter)stack.Pop();

                tmp.After = new Phrase(attributes);
                stack.Push(tmp);
                return;
            }

            // chunks
            if (Chunk.IsTag(name)) {
                currentChunk = new Chunk(attributes);
                if (bf != null) {
                    currentChunk.Font = new Font(this.bf);
                }
                return;
            }

            // symbols
            if (EntitiesToSymbol.IsTag(name)) {
                Font f = new Font();
                if (currentChunk != null) {
                    HandleEndingTags(ElementTags.CHUNK);
                    f = currentChunk.Font;
                }
                currentChunk = EntitiesToSymbol.Get(attributes[ElementTags.ID], f);
                return;
            }

            // phrases
            if (Phrase.IsTag(name)) {
                stack.Push(new Phrase(attributes));
                return;
            }

            // anchors
            if (Anchor.IsTag(name)) {
                stack.Push(new Anchor(attributes));
                return;
            }

            // paragraphs and titles
            if (Paragraph.IsTag(name) || Section.IsTitle(name)) {
                stack.Push(new Paragraph(attributes));
                return;
            }

            // lists
            if (List.IsTag(name)) {
                stack.Push(new List(attributes));
                return;
            }

            // listitems
            if (ListItem.IsTag(name)) {
                stack.Push(new ListItem(attributes));
                return;
            }

            // cells
            if (Cell.IsTag(name)) {
                stack.Push(new Cell(attributes));
                return;
            }

            // tables
            if (Table.IsTag(name)) {
                Table table = new Table(attributes);
                float[] widths = table.ProportionalWidths;
                for (int i = 0; i < widths.Length; i++) {
                    if (widths[i] == 0) {
                        widths[i] = 100.0f / (float)widths.Length;
                    }
                }
                try {
                    table.Widths = widths;
                }
                catch (BadElementException bee) {
                    // this shouldn't happen
                    throw new Exception("", bee);
                }
                stack.Push(table);
                return;
            }

            // sections
            if (Section.IsTag(name)) {
                IElement previous = (IElement) stack.Pop();
                Section section;
                section = ((Section)previous).AddSection(attributes);
                stack.Push(previous);
                stack.Push(section);
                return;
            }

            // chapters
            if (Chapter.IsTag(name)) {
                String value; // changed after a suggestion by Serge S. Vasiljev
                if ((value = (String)attributes.Remove(ElementTags.NUMBER)) != null){
                    chapters = int.Parse(value);
                }
                else {
                    chapters++;
                }
                Chapter chapter = new Chapter(attributes,chapters);
                stack.Push(chapter);
                return;
            }

            // images
            if (Image.IsTag(name)) {
                try {
                    Image img = Image.GetInstance(attributes);
                    Object current;
                    try {
                        // if there is an element on the stack...
                        current = stack.Pop();
                        // ...and it's a Chapter or a Section, the Image can be added directly
                        if (current is Chapter || current is Section || current is Cell) {
                            ((ITextElementArray)current).Add(img);
                            stack.Push(current);
                            return;
                        }
                            // ...if not, the Image is wrapped in a Chunk before it's added
                        else {
                            Stack newStack = new Stack();
                            try {
                                while (! (current is Chapter || current is Section || current is Cell)) {
                                    newStack.Push(current);
                                    if (current is Anchor) {
                                        img.Annotation = new Annotation(0, 0, 0, 0, ((Anchor)current).Reference);
                                    }
                                    current = stack.Pop();
                                }
                                ((ITextElementArray)current).Add(img);
                                stack.Push(current);
                            }
                            catch {
                                document.Add(img);
                            }
                            while (!(newStack.Count == 0)) {
                                stack.Push(newStack.Pop());
                            }
                            return;
                        }
                    }
                    catch {
                        // if there is no element on the stack, the Image is added to the document
                        try {
                            document.Add(img);
                        }
                        catch (DocumentException de) {
                            throw new Exception("", de);
                        }
                        return;
                    }
                }
                catch (Exception e) {
                    throw new Exception("", e);
                }
            }

            // annotations
            if (Annotation.IsTag(name)) {
                Annotation annotation = new Annotation(attributes);
                ITextElementArray current;
                try {
                    try {
                        current = (ITextElementArray) stack.Pop();
                        try {
                            current.Add(annotation);
                        }
                        catch {
                            document.Add(annotation);
                        }
                        stack.Push(current);
                    }
                    catch {
                        document.Add(annotation);
                    }
                    return;
                }
                catch (DocumentException de) {
                    throw new Exception("", de);
                }
            }

            // newlines
            if (IsNewline(name)) {
                ITextElementArray current;
                try {
                    current = (ITextElementArray) stack.Pop();
                    current.Add(Chunk.NEWLINE);
                    stack.Push(current);
                }
                catch {
                    if (currentChunk == null) {
                        try {
                            document.Add(Chunk.NEWLINE);
                        }
                        catch (DocumentException de) {
                            throw new Exception("", de);
                        }
                    }
                    else {
                        currentChunk.Append("\n");
                    }
                }
                return;
            }

            // newpage
            if (IsNewpage(name)) {
                ITextElementArray current;
                try {
                    current = (ITextElementArray) stack.Pop();
                    Chunk newPage = new Chunk("");
                    newPage.SetNewPage();
                    if (bf != null) {
                        newPage.Font = new Font(this.bf);
                    }
                    current.Add(newPage);
                    stack.Push(current);
                }
                catch {
                    document.NewPage();
                }
                return;
            }

            // documentroot
            if (IsDocumentRoot(name)) {
                String value;
                // pagesize and orientation specific code suggested by Samuel Gabriel
                // Updated by Ricardo Coutinho. Only use if set in html!
                Rectangle pageSize = null;
                String orientation = null;
                foreach (string key in attributes.Keys) {
                    value = attributes[key];
                    // margin specific code suggested by Reza Nasiri
                    if (Util.EqualsIgnoreCase(ElementTags.LEFT, key))
                        leftMargin = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
                    if (Util.EqualsIgnoreCase(ElementTags.RIGHT, key))
                        rightMargin = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
                    if (Util.EqualsIgnoreCase(ElementTags.TOP, key))
                        topMargin = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
                    if (Util.EqualsIgnoreCase(ElementTags.BOTTOM, key))
                        bottomMargin = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
                    if (ElementTags.PAGE_SIZE.Equals(key)) {
                        pageSize = (Rectangle)typeof(PageSize).GetField(value).GetValue(null);
                    } else if (ElementTags.ORIENTATION.Equals(key)) {
                        if ("landscape".Equals(value)) {
                            orientation = "landscape";
                        }
                    } else {
                        document.Add(new Meta(key, value));
                    }
                }
                if(pageSize != null) {
                    if ("landscape".Equals(orientation)) {
                        pageSize = pageSize.Rotate();
                    }
                    document.SetPageSize(pageSize);
                }
                document.SetMargins(leftMargin, rightMargin, topMargin,
                        bottomMargin);
                if (controlOpenClose)
                    document.Open();
            }
        }
 static Chunk()
 {
     Nextpage.SetNewPage();
 }