/// <summary> /// Creates a Section, adds it to this Section and returns it. /// </summary> /// <param name="title">the title of the new section</param> /// <returns>the newly added Section</returns> public virtual Section AddSection(Paragraph title) { return AddSection(0, title, numberDepth + 1); }
/** * @since iText 2.0.8 * @see com.lowagie.text.LargeElement#flushContent() */ public void FlushContent() { NotAddedYet = false; title = null; for (int k = 0; k < Count; ++k) { IElement element = (IElement)this[k]; if (element is Section) { Section s = (Section)element; if (!s.ElementComplete && Count == 1) { s.FlushContent(); return; } else { s.AddedCompletely = true; } } this.RemoveAt(k); --k; } }
/** * Called when a Section is written. * <P> * <CODE>position</CODE> will hold the height at which the * section will be written to. * * @param writer the <CODE>PdfWriter</CODE> for this document * @param document the document * @param paragraphPosition the position the chapter will be written to * @param title the title of the Chapter */ public virtual void OnSection(PdfWriter writer,Document document,float paragraphPosition,int depth,Paragraph title) { }
/** * Create a new section for this chapter and add it. * * @param title the Section title (as a <CODE>Paragraph</CODE>) * @return Returns the new section. */ public override Section AddSection(Paragraph title) { if (AddedCompletely) { throw new InvalidOperationException("This LargeElement has already been added to the Document."); } return AddSection(title, 2); }
/* (non-Javadoc) * @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupEnd() */ public override bool HandleCloseGroup() { this.OnCloseGroup(); // event handler if (this.rtfParser.IsImport()) { if (this.buffer.Length>0) { WriteBuffer(); } WriteText("}"); } if (this.rtfParser.IsConvert()) { if (this.buffer.Length > 0 && this.iTextParagraph == null) { this.iTextParagraph = new Paragraph(); } if (this.buffer.Length > 0 ) { Chunk chunk = new Chunk(); chunk.Append(this.buffer.ToString()); this.iTextParagraph.Add(chunk); } if (this.iTextParagraph != null) { AddParagraphToDocument(); } } return true; }
private void AddParagraphToDocument() { if (this.iTextParagraph != null) { try { this.rtfParser.GetDocument().Add(this.iTextParagraph); } catch { } this.iTextParagraph = null; } }
/** * Constructs a RtfParagraph belonging to a RtfDocument based on a Paragraph. * * @param doc The RtfDocument this RtfParagraph belongs to * @param paragraph The Paragraph that this RtfParagraph is based on */ public RtfParagraph(RtfDocument doc, Paragraph paragraph) : base(doc) { ST.RtfFont baseFont = null; if (paragraph.Font is ST.RtfParagraphStyle) { this.paragraphStyle = this.document.GetDocumentHeader().GetRtfParagraphStyle(((ST.RtfParagraphStyle) paragraph.Font).GetStyleName()); baseFont = this.paragraphStyle; } else { baseFont = new ST.RtfFont(this.document, paragraph.Font); this.paragraphStyle = new ST.RtfParagraphStyle(this.document, this.document.GetDocumentHeader().GetRtfParagraphStyle("Normal")); this.paragraphStyle.SetAlignment(paragraph.Alignment); this.paragraphStyle.SetFirstLineIndent((int) (paragraph.FirstLineIndent * RtfElement.TWIPS_FACTOR)); this.paragraphStyle.SetIndentLeft((int) (paragraph.IndentationLeft * RtfElement.TWIPS_FACTOR)); this.paragraphStyle.SetIndentRight((int) (paragraph.IndentationRight * RtfElement.TWIPS_FACTOR)); this.paragraphStyle.SetSpacingBefore((int) (paragraph.SpacingBefore * RtfElement.TWIPS_FACTOR)); this.paragraphStyle.SetSpacingAfter((int) (paragraph.SpacingAfter * RtfElement.TWIPS_FACTOR)); if (paragraph.HasLeading()) { this.paragraphStyle.SetLineLeading((int) (paragraph.Leading * RtfElement.TWIPS_FACTOR)); } this.paragraphStyle.SetKeepTogether(paragraph.KeepTogether); } for (int i = 0; i < paragraph.Count; i++) { IElement chunk = (IElement) paragraph[i]; if (chunk is Chunk) { ((Chunk) chunk).Font = baseFont.Difference(((Chunk) chunk).Font); } else if (chunk is RtfImage) { ((RtfImage) chunks[i]).SetAlignment(this.paragraphStyle.GetAlignment()); } try { IRtfBasicElement[] rtfElements = doc.GetMapper().MapElement(chunk); for(int j = 0; j < rtfElements.Length; j++) { chunks.Add(rtfElements[j]); } } catch (DocumentException) { } } }
/** * Gets the main appearance layer. * <p> * Consult <A HREF="http://partners.adobe.com/asn/developer/pdfs/tn/PPKAppearances.pdf">PPKAppearances.pdf</A> * for further details. * @return the main appearance layer * @throws DocumentException on error * @throws IOException on error */ public PdfTemplate GetAppearance() { if (IsInvisible()) { PdfTemplate t = new PdfTemplate(writer); t.BoundingBox = new Rectangle(0, 0); writer.AddDirectTemplateSimple(t, null); return t; } if (app[0] == null) { PdfTemplate t = app[0] = new PdfTemplate(writer); t.BoundingBox = new Rectangle(100, 100); writer.AddDirectTemplateSimple(t, new PdfName("n0")); t.SetLiteral("% DSBlank\n"); } if (app[1] == null && !acro6Layers) { PdfTemplate t = app[1] = new PdfTemplate(writer); t.BoundingBox = new Rectangle(100, 100); writer.AddDirectTemplateSimple(t, new PdfName("n1")); t.SetLiteral(questionMark); } if (app[2] == null) { String text; if (layer2Text == null) { StringBuilder buf = new StringBuilder(); buf.Append("Digitally signed by ").Append(PdfPKCS7.GetSubjectFields((X509Certificate)certChain[0]).GetField("CN")).Append('\n'); buf.Append("Date: ").Append(signDate.ToString("yyyy.MM.dd HH:mm:ss zzz")); if (reason != null) buf.Append('\n').Append("Reason: ").Append(reason); if (location != null) buf.Append('\n').Append("Location: ").Append(location); text = buf.ToString(); } else text = layer2Text; PdfTemplate t = app[2] = new PdfTemplate(writer); t.BoundingBox = rect; writer.AddDirectTemplateSimple(t, new PdfName("n2")); if (image != null) { if (imageScale == 0) { t.AddImage(image, rect.Width, 0, 0, rect.Height, 0, 0); } else { float usableScale = imageScale; if (imageScale < 0) usableScale = Math.Min(rect.Width / image.Width, rect.Height / image.Height); float w = image.Width * usableScale; float h = image.Height * usableScale; float x = (rect.Width - w) / 2; float y = (rect.Height - h) / 2; t.AddImage(image, w, 0, 0, h, x, y); } } Font font; if (layer2Font == null) font = new Font(); else font = new Font(layer2Font); float size = font.Size; Rectangle dataRect = null; Rectangle signatureRect = null; if (Render == SignatureRender.NameAndDescription || (Render == SignatureRender.GraphicAndDescription && this.SignatureGraphic != null)) { // origin is the bottom-left signatureRect = new Rectangle( MARGIN, MARGIN, rect.Width / 2 - MARGIN, rect.Height - MARGIN); dataRect = new Rectangle( rect.Width / 2 + MARGIN / 2, MARGIN, rect.Width - MARGIN / 2, rect.Height - MARGIN); if (rect.Height > rect.Width) { signatureRect = new Rectangle( MARGIN, rect.Height / 2, rect.Width - MARGIN, rect.Height); dataRect = new Rectangle( MARGIN, MARGIN, rect.Width - MARGIN, rect.Height / 2 - MARGIN); } } else { dataRect = new Rectangle( MARGIN, MARGIN, rect.Width - MARGIN, rect.Height * (1 - TOP_SECTION) - MARGIN); } if (Render == SignatureRender.NameAndDescription) { string signedBy = Legacy.Text.Pdf.PdfPKCS7.GetSubjectFields(this.certChain[0]).GetField("CN"); Rectangle sr2 = new Rectangle(signatureRect.Width - MARGIN, signatureRect.Height - MARGIN ); float signedSize = FitText(font, signedBy, sr2, -1, runDirection); ColumnText ct2 = new ColumnText(t); ct2.RunDirection = runDirection; ct2.SetSimpleColumn(new Phrase(signedBy, font), signatureRect.Left, signatureRect.Bottom, signatureRect.Right, signatureRect.Top, signedSize, Element.ALIGN_LEFT); ct2.Go(); } else if (Render == SignatureRender.GraphicAndDescription) { ColumnText ct2 = new ColumnText(t); ct2.RunDirection = runDirection; ct2.SetSimpleColumn(signatureRect.Left, signatureRect.Bottom, signatureRect.Right, signatureRect.Top, 0, Element.ALIGN_RIGHT); Image im = Image.GetInstance(SignatureGraphic); im.ScaleToFit(signatureRect.Width, signatureRect.Height); Paragraph p = new Paragraph(); // must calculate the point to draw from to make image appear in middle of column float x = 0; // experimentation found this magic number to counteract Adobe's signature graphic, which // offsets the y co-ordinate by 15 units float y = -im.ScaledHeight + 15; x = x + (signatureRect.Width - im.ScaledWidth) / 2; y = y - (signatureRect.Height - im.ScaledHeight) / 2; p.Add(new Chunk(im, x + (signatureRect.Width - im.ScaledWidth) / 2, y, false)); ct2.AddElement(p); ct2.Go(); } if (size <= 0) { Rectangle sr = new Rectangle(dataRect.Width, dataRect.Height); size = FitText(font, text, sr, 12, runDirection); } ColumnText ct = new ColumnText(t); ct.RunDirection = runDirection; ct.SetSimpleColumn(new Phrase(text, font), dataRect.Left, dataRect.Bottom, dataRect.Right, dataRect.Top, size, Element.ALIGN_LEFT); ct.Go(); } if (app[3] == null && !acro6Layers) { PdfTemplate t = app[3] = new PdfTemplate(writer); t.BoundingBox = new Rectangle(100, 100); writer.AddDirectTemplateSimple(t, new PdfName("n3")); t.SetLiteral("% DSBlank\n"); } if (app[4] == null && !acro6Layers) { PdfTemplate t = app[4] = new PdfTemplate(writer); t.BoundingBox = new Rectangle(0, rect.Height * (1 - TOP_SECTION), rect.Right, rect.Top); writer.AddDirectTemplateSimple(t, new PdfName("n4")); Font font; if (layer2Font == null) font = new Font(); else font = new Font(layer2Font); float size = font.Size; String text = "Signature Not Verified"; if (layer4Text != null) text = layer4Text; Rectangle sr = new Rectangle(rect.Width - 2 * MARGIN, rect.Height * TOP_SECTION - 2 * MARGIN); size = FitText(font, text, sr, 15, runDirection); ColumnText ct = new ColumnText(t); ct.RunDirection = runDirection; ct.SetSimpleColumn(new Phrase(text, font), MARGIN, 0, rect.Width - MARGIN, rect.Height - MARGIN, size, Element.ALIGN_LEFT); ct.Go(); } int rotation = writer.reader.GetPageRotation(page); Rectangle rotated = new Rectangle(rect); int n = rotation; while (n > 0) { rotated = rotated.Rotate(); n -= 90; } if (frm == null) { frm = new PdfTemplate(writer); frm.BoundingBox = rotated; writer.AddDirectTemplateSimple(frm, new PdfName("FRM")); float scale = Math.Min(rect.Width, rect.Height) * 0.9f; float x = (rect.Width - scale) / 2; float y = (rect.Height - scale) / 2; scale /= 100; if (rotation == 90) frm.ConcatCTM(0, 1, -1, 0, rect.Height, 0); else if (rotation == 180) frm.ConcatCTM(-1, 0, 0, -1, rect.Width, rect.Height); else if (rotation == 270) frm.ConcatCTM(0, -1, 1, 0, 0, rect.Width); frm.AddTemplate(app[0], 0, 0); if (!acro6Layers) frm.AddTemplate(app[1], scale, 0, 0, scale, x, y); frm.AddTemplate(app[2], 0, 0); if (!acro6Layers) { frm.AddTemplate(app[3], scale, 0, 0, scale, x, y); frm.AddTemplate(app[4], 0, 0); } } PdfTemplate napp = new PdfTemplate(writer); napp.BoundingBox = rotated; writer.AddDirectTemplateSimple(napp, null); napp.AddTemplate(frm, 0, 0); return napp; }
/** * Constructs a <CODE>PdfOutline</CODE>. * <P> * This is the constructor for an <CODE>outline entry</CODE>. The open mode is * <CODE>true</CODE>. * * @param parent the parent of this outline item * @param destination the destination for this outline item * @param title the title of this outline item */ public PdfOutline(PdfOutline parent, PdfDestination destination, Paragraph title) : this(parent, destination, title, true) { }
/** * Constructs a <CODE>PdfOutline</CODE>. * <P> * This is the constructor for an <CODE>outline entry</CODE>. * * @param parent the parent of this outline item * @param destination the destination for this outline item * @param title the title of this outline item * @param open <CODE>true</CODE> if the children are visible */ public PdfOutline(PdfOutline parent, PdfDestination destination, Paragraph title, bool open) : base() { StringBuilder buf = new StringBuilder(); foreach (Chunk chunk in title.Chunks) { buf.Append(chunk.Content); } this.destination = destination; InitOutline(parent, buf.ToString(), open); }
/** * Constructs a <CODE>PdfOutline</CODE>. * <P> * This is the constructor for an <CODE>outline entry</CODE>. The open mode is * <CODE>true</CODE>. * * @param parent the parent of this outline item * @param action the <CODE>PdfAction</CODE> for this outline item * @param title the title of this outline item */ public PdfOutline(PdfOutline parent, PdfAction action, Paragraph title) : this(parent, action, title, true) { }
/// <summary> /// Constructs a new Chapter. /// </summary> /// <param name="title">the Chapter title (as a Paragraph)</param> /// <param name="number">the Chapter number</param> /// <overoads> /// Has three overloads. /// </overoads> public Chapter(Paragraph title, int number) : base(title, 1) { numbers = new ArrayList(); numbers.Add(number); triggerNewPage = true; }
/** * Create a new object. * * @param para the Chapter title (as a <CODE>Paragraph</CODE>) */ public ChapterAutoNumber(Paragraph para) : base(para, 0) { }
/** * Called when a Section is written. * <P> * <CODE>position</CODE> will hold the height at which the section will be * written to. * * @param writer * the <CODE>PdfWriter</CODE> for this document * @param document * the document * @param paragraphPosition * the position the section will be written to * @param depth * the number depth of the Section * @param title * the title of the section */ public virtual void OnSection(PdfWriter writer, Document document, float paragraphPosition, int depth, Paragraph title) { foreach (IPdfPageEvent eventa in events) { eventa.OnSection(writer, document, paragraphPosition, depth, title); } }
// constructors /// <summary> /// Constructs a new Section. /// </summary> /// <overloads> /// Has 2 overloads. /// </overloads> protected internal Section() { title = new Paragraph(); numberDepth = 1; }
/** * Called when a Chapter is written. * <P> * <CODE>position</CODE> will hold the height at which the chapter will be * written to. * * @param writer * the <CODE>PdfWriter</CODE> for this document * @param document * the document * @param paragraphPosition * the position the chapter will be written to * @param title * the title of the Chapter */ public virtual void OnChapter(PdfWriter writer, Document document, float paragraphPosition, Paragraph title) { foreach (IPdfPageEvent eventa in events) { eventa.OnChapter(writer, document, paragraphPosition, title); } }
/// <summary> /// Constructs a new Section. /// </summary> /// <param name="title">a Paragraph</param> /// <param name="numberDepth">the numberDepth</param> protected internal Section(Paragraph title, int numberDepth) { this.numberDepth = numberDepth; this.title = title; }
/* (non-Javadoc) * @see com.lowagie.text.rtf.parser.properties.RtfPropertyListener#beforeChange(java.lang.String) */ public void BeforePropertyChange(String propertyName) { // do we have any text to do anything with? // if not, then just return without action. if (this.buffer.Length == 0) return; if (propertyName.StartsWith(RtfProperty.CHARACTER)) { // this is a character change, // add a new chunck to the current paragraph using current character settings. Chunk chunk = new Chunk(); chunk.Append(this.buffer.ToString()); this.buffer = new StringBuilder(255); Hashtable charProperties = this.rtfParser.GetState().properties.GetProperties(RtfProperty.CHARACTER); String defFont = (String)charProperties[RtfProperty.CHARACTER_FONT]; if (defFont == null) defFont = "0"; RtfDestinationFontTable fontTable = (RtfDestinationFontTable)this.rtfParser.GetDestination("fonttbl"); Font currFont = fontTable.GetFont(defFont); int fs = Font.NORMAL; if (charProperties.ContainsKey(RtfProperty.CHARACTER_BOLD)) fs |= Font.BOLD; if (charProperties.ContainsKey(RtfProperty.CHARACTER_ITALIC)) fs |= Font.ITALIC; if (charProperties.ContainsKey(RtfProperty.CHARACTER_UNDERLINE)) fs |= Font.UNDERLINE; Font useFont = FontFactory.GetFont(currFont.Familyname, 12, fs, new Color(0,0,0)); chunk.Font = useFont; if (iTextParagraph == null) this.iTextParagraph = new Paragraph(); this.iTextParagraph.Add(chunk); } else { if (propertyName.StartsWith(RtfProperty.PARAGRAPH)) { // this is a paragraph change. what do we do? } else { if (propertyName.StartsWith(RtfProperty.SECTION)) { } else { if (propertyName.StartsWith(RtfProperty.DOCUMENT)) { } } } } }
/** * Constructs a Paragraph that will be used as title for a Section or Chapter. * @param title the title of the section * @param numbers a list of sectionnumbers * @param numberDepth how many numbers have to be shown * @param numberStyle the numbering style * @return a Paragraph object * @since iText 2.0.8 */ public static Paragraph ConstructTitle(Paragraph title, ArrayList numbers, int numberDepth, int numberStyle) { if (title == null) { return null; } int depth = Math.Min(numbers.Count, numberDepth); if (depth < 1) { return title; } StringBuilder buf = new StringBuilder(" "); for (int i = 0; i < depth; i++) { buf.Insert(0, "."); buf.Insert(0, (int)numbers[i]); } if (numberStyle == NUMBERSTYLE_DOTTED_WITHOUT_FINAL_DOT) { buf.Remove(buf.Length - 2, 1); } Paragraph result = new Paragraph(title); result.Insert(0, new Chunk(buf.ToString(), title.Font)); return result; }
/* (non-Javadoc) * @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupStart() */ public override bool HandleOpenGroup() { this.OnOpenGroup(); // event handler if (this.rtfParser.IsImport()) { } if (this.rtfParser.IsConvert()) { if (this.iTextParagraph == null) this.iTextParagraph = new Paragraph(); } return true; }
// methods that return a Section /// <summary> /// Creates a Section, adds it to this Section and returns it. /// </summary> /// <param name="indentation">the indentation of the new section</param> /// <param name="title">the title of the new section</param> /// <param name="numberDepth">the numberDepth of the section</param> /// <returns>the newly added Section</returns> public virtual Section AddSection(float indentation, Paragraph title, int numberDepth) { if (AddedCompletely) { throw new InvalidOperationException("This LargeElement has already been added to the Document."); } Section section = new Section(title, numberDepth); section.Indentation = indentation; Add(section); return section; }
/** * Creates a PdfPCell based on this Cell object. * @return a PdfPCell * @throws BadElementException */ public PdfPCell CreatePdfPCell() { if (rowspan > 1) throw new BadElementException("PdfPCells can't have a rowspan > 1"); if (IsTable()) return new PdfPCell(((Table)arrayList[0]).CreatePdfPTable()); PdfPCell cell = new PdfPCell(); cell.VerticalAlignment = verticalAlignment; cell.HorizontalAlignment = horizontalAlignment; cell.Colspan = colspan; cell.UseBorderPadding = useBorderPadding; cell.UseDescender = useDescender; cell.SetLeading(Leading, 0); cell.CloneNonPositionParameters(this); cell.NoWrap = noWrap; foreach (IElement i in Elements) { if (i.Type == Element.PHRASE || i.Type == Element.PARAGRAPH) { Paragraph p = new Paragraph((Phrase)i); p.Alignment = horizontalAlignment; cell.AddElement(p); } else cell.AddElement(i); } return cell; }
/// <summary> /// Creates a Section, adds it to this Section and returns it. /// </summary> /// <param name="indentation">the indentation of the new section</param> /// <param name="title">the title of the new section</param> /// <returns>the newly added Section</returns> public virtual Section AddSection(float indentation, Paragraph title) { return AddSection(indentation, title, numberDepth + 1); }
/** * Called when a Chapter is written. * <P> * <CODE>position</CODE> will hold the height at which the * chapter will be written to. * * @param writer the <CODE>PdfWriter</CODE> for this document * @param document the document * @param paragraphPosition the position the chapter will be written to * @param title the title of the Chapter */ public virtual void OnChapter(PdfWriter writer,Document document,float paragraphPosition,Paragraph title) { }
// [M4] Adding a PdfPTable /** Adds a <CODE>PdfPTable</CODE> to the document. * @param ptable the <CODE>PdfPTable</CODE> to be added to the document. * @throws DocumentException on error */ internal void AddPTable(PdfPTable ptable) { ColumnText ct = new ColumnText(writer.DirectContent); // if the table prefers to be on a single page, and it wouldn't //fit on the current page, start a new page. if (ptable.KeepTogether && !FitsPage(ptable, 0f) && currentHeight > 0) { NewPage(); } // add dummy paragraph if we aren't at the top of a page, so that // spacingBefore will be taken into account by ColumnText if (currentHeight > 0) { Paragraph p = new Paragraph(); p.Leading = 0; ct.AddElement(p); } ct.AddElement(ptable); bool he = ptable.HeadersInEvent; ptable.HeadersInEvent = true; int loop = 0; while (true) { ct.SetSimpleColumn(IndentLeft, IndentBottom, IndentRight, IndentTop - currentHeight); int status = ct.Go(); if ((status & ColumnText.NO_MORE_TEXT) != 0) { text.MoveText(0, ct.YLine - IndentTop + currentHeight); currentHeight = IndentTop - ct.YLine; break; } if (IndentTop - currentHeight == ct.YLine) ++loop; else loop = 0; if (loop == 3) { Add(new Paragraph("ERROR: Infinite table loop")); break; } NewPage(); } ptable.HeadersInEvent = he; }