Initial Commit
This commit is contained in:
111
iTechSharp/iTextSharp/text/rtf/field/RtfAnchor.cs
Normal file
111
iTechSharp/iTextSharp/text/rtf/field/RtfAnchor.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf.text;
|
||||
using iTextSharp.text.rtf.document;
|
||||
/*
|
||||
* $Id: RtfAnchor.cs,v 1.7 2008/05/16 19:30:54 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2004 by Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.field {
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfAnchor : RtfField {
|
||||
|
||||
/**
|
||||
* Constant for a hyperlink
|
||||
*/
|
||||
private static byte[] HYPERLINK = DocWriter.GetISOBytes("HYPERLINK");
|
||||
|
||||
/**
|
||||
* The url of this RtfAnchor
|
||||
*/
|
||||
private String url = "";
|
||||
/**
|
||||
* The RtfPhrase to display for the url
|
||||
*/
|
||||
private new RtfPhrase content = null;
|
||||
|
||||
/**
|
||||
* Constructs a RtfAnchor based on a RtfField
|
||||
*
|
||||
* @param doc The RtfDocument this RtfAnchor belongs to
|
||||
* @param anchor The Anchor this RtfAnchor is based on
|
||||
*/
|
||||
public RtfAnchor(RtfDocument doc, Anchor anchor) : base(doc) {
|
||||
this.url = anchor.Reference;
|
||||
this.content = new RtfPhrase(doc, anchor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the field instructions for this RtfAnchor. Sets the field
|
||||
* type to HYPERLINK and then writes the url.
|
||||
*
|
||||
* @return The field instructions for this RtfAnchor
|
||||
* @throws IOException
|
||||
*/
|
||||
protected override void WriteFieldInstContent(Stream result) {
|
||||
result.Write(HYPERLINK, 0, HYPERLINK.Length);
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
this.document.FilterSpecialChar(result, url, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the field result for this RtfAnchor. Writes the content
|
||||
* of the RtfPhrase.
|
||||
*/
|
||||
protected override void WriteFieldResultContent(Stream outp) {
|
||||
content.WriteContent(outp);
|
||||
}
|
||||
}
|
||||
}
|
427
iTechSharp/iTextSharp/text/rtf/field/RtfField.cs
Normal file
427
iTechSharp/iTextSharp/text/rtf/field/RtfField.cs
Normal file
@@ -0,0 +1,427 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using ST = iTextSharp.text.rtf.style;
|
||||
using iTextSharp.text.rtf.document;
|
||||
/*
|
||||
* $Id: RtfField.cs,v 1.7 2008/05/16 19:30:54 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2004 by Mark Hall
|
||||
* Uses code Copyright 2002
|
||||
* <a href="http://www.smb-tec.com">SMB</a>
|
||||
* <a href="mailto:Dirk.Weigenand@smb-tec.com">Dirk.Weigenand@smb-tec.com</a>
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.field {
|
||||
|
||||
/**
|
||||
* The RtfField class is an abstract base class for all rtf field functionality.
|
||||
* Subclasses only need to implement the two abstract methods writeFieldInstContent
|
||||
* and writeFieldResultContent. All other field functionality is handled by the
|
||||
* RtfField class.
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author <a href="mailto:Dirk.Weigenand@smb-tec.com">Dirk Weigenand</a>
|
||||
*/
|
||||
public abstract class RtfField : Chunk, iTextSharp.text.rtf.IRtfBasicElement {
|
||||
|
||||
/**
|
||||
* Constant for the beginning of a rtf group
|
||||
*/
|
||||
public static byte[] OPEN_GROUP = {(byte)'{'};
|
||||
/**
|
||||
* Constant for the end of an rtf group
|
||||
*/
|
||||
public static byte[] CLOSE_GROUP = {(byte)'}'};
|
||||
/**
|
||||
* Constant for a delimiter in rtf
|
||||
*/
|
||||
public static byte[] DELIMITER = {(byte)' '};
|
||||
/**
|
||||
* Constant for a comma delimiter in rtf
|
||||
*/
|
||||
public static byte[] COMMA_DELIMITER = {(byte)';'};
|
||||
/**
|
||||
* The factor to use for translating from iText to rtf measurments
|
||||
*/
|
||||
public const double TWIPS_FACTOR = 20;
|
||||
|
||||
/**
|
||||
* Constant for a rtf field
|
||||
*/
|
||||
private static byte[] FIELD = DocWriter.GetISOBytes("\\field");
|
||||
/**
|
||||
* Constant for a dirty field
|
||||
*/
|
||||
private static byte[] FIELD_DIRTY = DocWriter.GetISOBytes("\\flddirty");
|
||||
/**
|
||||
* Constant for a private field
|
||||
*/
|
||||
private static byte[] FIELD_PRIVATE = DocWriter.GetISOBytes("\\fldpriv");
|
||||
/**
|
||||
* Constant for a locked field
|
||||
*/
|
||||
private static byte[] FIELD_LOCKED = DocWriter.GetISOBytes("\\fldlock");
|
||||
/**
|
||||
* Constant for a edited field
|
||||
*/
|
||||
private static byte[] FIELD_EDIT = DocWriter.GetISOBytes("\\fldedit");
|
||||
/**
|
||||
* Constant for an alt field
|
||||
*/
|
||||
private static byte[] FIELD_ALT = DocWriter.GetISOBytes("\\fldalt");
|
||||
/**
|
||||
* Constant for the field instructions
|
||||
*/
|
||||
private static byte[] FIELD_INSTRUCTIONS = DocWriter.GetISOBytes("\\*\\fldinst");
|
||||
/**
|
||||
* Constant for the field result
|
||||
*/
|
||||
private static byte[] FIELD_RESULT = DocWriter.GetISOBytes("\\fldrslt");
|
||||
|
||||
/**
|
||||
* Is the field dirty
|
||||
*/
|
||||
private bool fieldDirty = false;
|
||||
/**
|
||||
* Is the field edited
|
||||
*/
|
||||
private bool fieldEdit = false;
|
||||
/**
|
||||
* Is the field locked
|
||||
*/
|
||||
private bool fieldLocked = false;
|
||||
/**
|
||||
* Is the field private
|
||||
*/
|
||||
private bool fieldPrivate = false;
|
||||
/**
|
||||
* Is it an alt field
|
||||
*/
|
||||
private bool fieldAlt = false;
|
||||
/**
|
||||
* Whether this RtfField is in a table
|
||||
*/
|
||||
private bool inTable = false;
|
||||
/**
|
||||
* Whether this RtfElement is in a header
|
||||
*/
|
||||
private bool inHeader = false;
|
||||
/**
|
||||
* The RtfDocument this RtfField belongs to
|
||||
*/
|
||||
protected RtfDocument document = null;
|
||||
/**
|
||||
* The RtfFont of this RtfField
|
||||
*/
|
||||
private new ST.RtfFont font = null;
|
||||
|
||||
/**
|
||||
* Constructs a RtfField for a RtfDocument. This is not very usefull,
|
||||
* since the RtfField by itself does not do anything. Use one of the
|
||||
* subclasses instead.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfField belongs to.
|
||||
*/
|
||||
protected RtfField(RtfDocument doc) : this(doc, new Font()) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfField for a RtfDocument. This is not very usefull,
|
||||
* since the RtfField by itself does not do anything. Use one of the
|
||||
* subclasses instead.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfField belongs to.
|
||||
* @param font The Font this RtfField should use
|
||||
*/
|
||||
protected RtfField(RtfDocument doc, Font font) : base("", font) {
|
||||
this.document = doc;
|
||||
this.font = new ST.RtfFont(this.document, font);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the RtfDocument this RtfElement belongs to
|
||||
*
|
||||
* @param doc The RtfDocument to use
|
||||
*/
|
||||
public void SetRtfDocument(RtfDocument doc) {
|
||||
this.document = doc;
|
||||
this.font.SetRtfDocument(this.document);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the field beginning. Also writes field properties.
|
||||
*
|
||||
* @return A byte array with the field beginning.
|
||||
* @throws IOException
|
||||
*/
|
||||
private void WriteFieldBegin(Stream result) {
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
result.Write(FIELD, 0, FIELD.Length);
|
||||
if (fieldDirty) result.Write(FIELD_DIRTY, 0, FIELD_DIRTY.Length);
|
||||
if (fieldEdit) result.Write(FIELD_EDIT, 0, FIELD_EDIT.Length);
|
||||
if (fieldLocked) result.Write(FIELD_LOCKED, 0, FIELD_LOCKED.Length);
|
||||
if (fieldPrivate) result.Write(FIELD_PRIVATE, 0, FIELD_PRIVATE.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the beginning of the field instruction area.
|
||||
*
|
||||
* @return The beginning of the field instruction area
|
||||
* @throws IOException
|
||||
*/
|
||||
private void WriteFieldInstBegin(Stream result) {
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
result.Write(FIELD_INSTRUCTIONS, 0, FIELD_INSTRUCTIONS.Length);
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the field instruction area. Override this
|
||||
* method in your subclasses.
|
||||
*/
|
||||
protected abstract void WriteFieldInstContent(Stream oupt);
|
||||
|
||||
/**
|
||||
* Writes the end of the field instruction area.
|
||||
*/
|
||||
private void WriteFieldInstEnd(Stream result) {
|
||||
if (fieldAlt) {
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
result.Write(FIELD_ALT, 0, FIELD_ALT.Length);
|
||||
}
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the beginning of the field result area
|
||||
*/
|
||||
private void WriteFieldResultBegin(Stream result) {
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
result.Write(FIELD_RESULT, 0, FIELD_RESULT.Length);
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the pre-calculated field result. Override this
|
||||
* method in your subclasses.
|
||||
*/
|
||||
protected abstract void WriteFieldResultContent(Stream oupt);
|
||||
|
||||
/**
|
||||
* Writes the end of the field result area
|
||||
*/
|
||||
private void WriteFieldResultEnd(Stream result) {
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the end of the field
|
||||
*/
|
||||
private void WriteFieldEnd(Stream result) {
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Writes the field to the <code>OutputStream</code>.
|
||||
*/
|
||||
public virtual void WriteContent(Stream result) {
|
||||
font.WriteBegin(result);
|
||||
WriteFieldBegin(result);
|
||||
WriteFieldInstBegin(result);
|
||||
WriteFieldInstContent(result);
|
||||
WriteFieldInstEnd(result);
|
||||
WriteFieldResultBegin(result);
|
||||
WriteFieldResultContent(result);
|
||||
WriteFieldResultEnd(result);
|
||||
WriteFieldEnd(result);
|
||||
font.WriteEnd(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this field is an alt field
|
||||
*
|
||||
* @return Returns whether this field is an alt field
|
||||
*/
|
||||
public bool IsFieldAlt() {
|
||||
return fieldAlt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this field is an alt field
|
||||
*
|
||||
* @param fieldAlt The value to use
|
||||
*/
|
||||
public void SetFieldAlt(bool fieldAlt) {
|
||||
this.fieldAlt = fieldAlt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this field is dirty
|
||||
*
|
||||
* @return Returns whether this field is dirty
|
||||
*/
|
||||
public bool IsFieldDirty() {
|
||||
return fieldDirty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this field is dirty
|
||||
*
|
||||
* @param fieldDirty The value to use
|
||||
*/
|
||||
public void SetFieldDirty(bool fieldDirty) {
|
||||
this.fieldDirty = fieldDirty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this field is edited
|
||||
*
|
||||
* @return Returns whether this field is edited
|
||||
*/
|
||||
public bool IsFieldEdit() {
|
||||
return fieldEdit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this field is edited.
|
||||
*
|
||||
* @param fieldEdit The value to use
|
||||
*/
|
||||
public void SetFieldEdit(bool fieldEdit) {
|
||||
this.fieldEdit = fieldEdit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this field is locked
|
||||
*
|
||||
* @return Returns the fieldLocked.
|
||||
*/
|
||||
public bool IsFieldLocked() {
|
||||
return fieldLocked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this field is locked
|
||||
* @param fieldLocked The value to use
|
||||
*/
|
||||
public void SetFieldLocked(bool fieldLocked) {
|
||||
this.fieldLocked = fieldLocked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this field is private
|
||||
*
|
||||
* @return Returns the fieldPrivate.
|
||||
*/
|
||||
public bool IsFieldPrivate() {
|
||||
return fieldPrivate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this field is private
|
||||
*
|
||||
* @param fieldPrivate The value to use
|
||||
*/
|
||||
public void SetFieldPrivate(bool fieldPrivate) {
|
||||
this.fieldPrivate = fieldPrivate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this RtfField is in a table
|
||||
*
|
||||
* @param inTable <code>True</code> if this RtfField is in a table, <code>false</code> otherwise
|
||||
*/
|
||||
public void SetInTable(bool inTable) {
|
||||
this.inTable = inTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether this <code>RtfField</code> is in a table.
|
||||
*
|
||||
* @return <code>True</code> if this <code>RtfField</code> is in a table, <code>false</code> otherwise
|
||||
*/
|
||||
public bool IsInTable() {
|
||||
return this.inTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this RtfField is in a header
|
||||
*
|
||||
* @param inHeader <code>True</code> if this RtfField is in a header, <code>false</code> otherwise
|
||||
*/
|
||||
public void SetInHeader(bool inHeader) {
|
||||
this.inHeader = inHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether this <code>RtfField</code> is in a header.
|
||||
*
|
||||
* @return <code>True</code> if this <code>RtfField</code> is in a header, <code>false</code> otherwise
|
||||
*/
|
||||
public bool IsInHeader() {
|
||||
return this.inHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* An RtfField is never empty.
|
||||
*/
|
||||
public override bool IsEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public override Font Font {
|
||||
set {
|
||||
base.Font = value;
|
||||
font = new ST.RtfFont(document, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
75
iTechSharp/iTextSharp/text/rtf/field/RtfPageNumber.cs
Normal file
75
iTechSharp/iTextSharp/text/rtf/field/RtfPageNumber.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf.document;
|
||||
/*
|
||||
* Created on Aug 10, 2004
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||
*/
|
||||
namespace iTextSharp.text.rtf.field {
|
||||
|
||||
/**
|
||||
* The RtfPageNumber provides the page number field in rtf documents.
|
||||
*
|
||||
* @version $Revision: 1.4 $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author <a href="mailto:Steffen.Stundzig@smb-tec.com">Steffen.Stundzig@smb-tec.com</a>
|
||||
*/
|
||||
public class RtfPageNumber : RtfField {
|
||||
|
||||
/**
|
||||
* Constant for the page number
|
||||
*/
|
||||
private static byte[] PAGE_NUMBER = DocWriter.GetISOBytes("PAGE");
|
||||
|
||||
/**
|
||||
* Constructs a RtfPageNumber. This can be added anywhere to add a page number field.
|
||||
*/
|
||||
public RtfPageNumber() : base(null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfPageNumber with a specified Font. This can be added anywhere to
|
||||
* add a page number field.
|
||||
* @param font
|
||||
*/
|
||||
public RtfPageNumber(Font font) : base(null, font) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfPageNumber object.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfPageNumber belongs to
|
||||
*/
|
||||
public RtfPageNumber(RtfDocument doc) : base(doc) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfPageNumber object with a specific font.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfPageNumber belongs to
|
||||
* @param font The Font to use
|
||||
*/
|
||||
public RtfPageNumber(RtfDocument doc, Font font) : base(doc, font) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the field instruction content
|
||||
*
|
||||
* @
|
||||
*/
|
||||
protected override void WriteFieldInstContent(Stream oupt) {
|
||||
oupt.Write(PAGE_NUMBER, 0, PAGE_NUMBER.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the field result content
|
||||
*
|
||||
* @
|
||||
*/
|
||||
protected override void WriteFieldResultContent(Stream oupt) {
|
||||
}
|
||||
}
|
||||
}
|
146
iTechSharp/iTextSharp/text/rtf/field/RtfTOCEntry.cs
Normal file
146
iTechSharp/iTextSharp/text/rtf/field/RtfTOCEntry.cs
Normal file
@@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
/*
|
||||
* $Id: RtfTOCEntry.cs,v 1.6 2008/05/23 17:24:26 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2004 by Mark Hall
|
||||
* Uses code Copyright 2002
|
||||
* <a href="mailto:Steffen.Stundzig@smb-tec.com">Steffen.Stundzig@smb-tec.com</a>
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.field {
|
||||
|
||||
/**
|
||||
* The RtfTOCEntry is used together with the RtfTableOfContents to generate a table of
|
||||
* contents. Add the RtfTOCEntry in those locations in the document where table of
|
||||
* contents entries should link to
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author <a href="mailto:Steffen.Stundzig@smb-tec.com">Steffen.Stundzig@smb-tec.com</a>
|
||||
*/
|
||||
public class RtfTOCEntry : RtfField {
|
||||
|
||||
/**
|
||||
* Constant for the beginning of hidden text
|
||||
*/
|
||||
private static byte[] TEXT_HIDDEN_ON = DocWriter.GetISOBytes("\\v");
|
||||
/**
|
||||
* Constant for the end of hidden text
|
||||
*/
|
||||
private static byte[] TEXT_HIDDEN_OFF = DocWriter.GetISOBytes("\\v0");
|
||||
/**
|
||||
* Constant for a TOC entry with page numbers
|
||||
*/
|
||||
private static byte[] TOC_ENTRY_PAGE_NUMBER = DocWriter.GetISOBytes("\\tc");
|
||||
/**
|
||||
* Constant for a TOC entry without page numbers
|
||||
*/
|
||||
private static byte[] TOC_ENTRY_NO_PAGE_NUMBER = DocWriter.GetISOBytes("\\tcn");
|
||||
|
||||
/**
|
||||
* The entry text of this RtfTOCEntry
|
||||
*/
|
||||
private String entry = "";
|
||||
/**
|
||||
* Whether to show page numbers in the table of contents
|
||||
*/
|
||||
private bool showPageNumber = true;
|
||||
|
||||
/**
|
||||
* Constructs a RtfTOCEntry with a certain entry text.
|
||||
*
|
||||
* @param entry The entry text to display
|
||||
* @param font The Font to use
|
||||
*/
|
||||
public RtfTOCEntry(String entry) : base(null, new Font()) {
|
||||
if (entry != null) {
|
||||
this.entry = entry;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the RtfTOCEntry
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
result.Write(TEXT_HIDDEN_ON, 0, TEXT_HIDDEN_ON.Length);
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
if (this.showPageNumber) {
|
||||
result.Write(TOC_ENTRY_PAGE_NUMBER, 0, TOC_ENTRY_PAGE_NUMBER.Length);
|
||||
} else {
|
||||
result.Write(TOC_ENTRY_NO_PAGE_NUMBER, 0, TOC_ENTRY_NO_PAGE_NUMBER.Length);
|
||||
}
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
this.document.FilterSpecialChar(result, this.entry, true, false);
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
result.Write(TEXT_HIDDEN_OFF, 0, TEXT_HIDDEN_OFF.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to display a page number in the table of contents, or not
|
||||
*
|
||||
* @param showPageNumber Whether to display a page number or not
|
||||
*/
|
||||
public void SetShowPageNumber(bool showPageNumber) {
|
||||
this.showPageNumber = showPageNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* unused
|
||||
*/
|
||||
protected override void WriteFieldInstContent(Stream outp) {
|
||||
}
|
||||
|
||||
/*
|
||||
* unused
|
||||
* @see com.lowagie.text.rtf.field.RtfField#writeFieldResultContent(java.io.OutputStream)
|
||||
*/
|
||||
protected override void WriteFieldResultContent(Stream outp) {
|
||||
}
|
||||
}
|
||||
}
|
105
iTechSharp/iTextSharp/text/rtf/field/RtfTableOfContents.cs
Normal file
105
iTechSharp/iTextSharp/text/rtf/field/RtfTableOfContents.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
/*
|
||||
* $Id: RtfTableOfContents.cs,v 1.7 2008/05/23 17:24:26 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2004 by Mark Hall
|
||||
* Uses code Copyright 2002
|
||||
* <a href="mailto:Steffen.Stundzig@smb-tec.com">Steffen.Stundzig@smb-tec.com</a>
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.field {
|
||||
|
||||
/**
|
||||
* The RtfTableOfContents together with multiple RtfTOCEntry objects generates a table
|
||||
* of contents. The table of contents will display no entries in the viewing program
|
||||
* and the user will have to update it first. A text to inform the user of this is
|
||||
* displayed instead.
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author <a href="mailto:Steffen.Stundzig@smb-tec.com">Steffen.Stundzig@smb-tec.com</a>
|
||||
*/
|
||||
public class RtfTableOfContents : RtfField {
|
||||
|
||||
/**
|
||||
* field inst content
|
||||
*/
|
||||
private const String FIELD_INST = "TOC \\\\f \\\\h \\\\u \\\\o \"1-5\" ";
|
||||
/**
|
||||
* The default text to display
|
||||
*/
|
||||
private String defaultText = "Table of Contents - Click to update";
|
||||
|
||||
/**
|
||||
* Constructs a RtfTableOfContents. The default text is the text that is displayed
|
||||
* before the user updates the table of contents
|
||||
*
|
||||
* @param defaultText The default text to display
|
||||
* @param font The Font to use
|
||||
*/
|
||||
public RtfTableOfContents(String defaultText) : base(null, new Font()) {
|
||||
this.defaultText = defaultText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the field instruction content
|
||||
*/
|
||||
protected override void WriteFieldInstContent(Stream outp) {
|
||||
byte[] t = DocWriter.GetISOBytes(FIELD_INST);
|
||||
outp.Write(t, 0, t.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the field result content
|
||||
*/
|
||||
protected override void WriteFieldResultContent(Stream outp) {
|
||||
document.FilterSpecialChar(outp, defaultText, true, true);
|
||||
}
|
||||
}
|
||||
}
|
118
iTechSharp/iTextSharp/text/rtf/field/RtfTotalPageNumber.cs
Normal file
118
iTechSharp/iTextSharp/text/rtf/field/RtfTotalPageNumber.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf.document;
|
||||
/*
|
||||
* $Id: RtfTotalPageNumber.cs,v 1.5 2008/05/23 17:24:26 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2005 Jose Hurtado <a href="mailto:jose.hurtado@gft.com">jose.hurtado@gft.com</a>
|
||||
* Parts Copyright 2005 Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.field {
|
||||
|
||||
/**
|
||||
* The RtfTotalPageNumber provides the total number of pages field in rtf documents.
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Jose Hurtado (jose.hurtado@gft.com)
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfTotalPageNumber : RtfField {
|
||||
|
||||
/**
|
||||
* Constant for arabic total page numbers.
|
||||
*/
|
||||
private static byte[] ARABIC_TOTAL_PAGES = DocWriter.GetISOBytes("NUMPAGES \\\\* Arabic");
|
||||
|
||||
/**
|
||||
* Constructs a RtfTotalPageNumber. This can be added anywhere to add a total number of pages field.
|
||||
*/
|
||||
public RtfTotalPageNumber() : base(null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfTotalPageNumber with a specified Font. This can be added anywhere
|
||||
* to add a total number of pages field.
|
||||
* @param font
|
||||
*/
|
||||
public RtfTotalPageNumber(Font font) : base(null, font) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfTotalPageNumber object.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfTotalPageNumber belongs to
|
||||
*/
|
||||
public RtfTotalPageNumber(RtfDocument doc) : base(doc) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfTotalPageNumber object with a specific font.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfTotalPageNumber belongs to
|
||||
* @param font The Font to use
|
||||
*/
|
||||
public RtfTotalPageNumber(RtfDocument doc, Font font) : base(doc, font) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the field NUMPAGES instruction with Arabic format: "NUMPAGES \\\\* Arabic".
|
||||
*/
|
||||
protected override void WriteFieldInstContent(Stream outp) {
|
||||
outp.Write(ARABIC_TOTAL_PAGES, 0, ARABIC_TOTAL_PAGES.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the field result content "1"
|
||||
*/
|
||||
protected override void WriteFieldResultContent(Stream outp) {
|
||||
byte[] t = new byte[]{(byte)'1'};
|
||||
outp.Write(t, 0, t.Length);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user