Initial Commit

This commit is contained in:
2023-06-21 12:46:23 -04:00
commit c70248a520
1352 changed files with 336780 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
using System;
using iTextSharp.text.pdf;
namespace iTextSharp.text.pdf.collection {
public class PdfCollection : PdfDictionary {
/** A type of PDF Collection */
public const int DETAILS = 0;
/** A type of PDF Collection */
public const int TILE = 1;
/** A type of PDF Collection */
public const int HIDDEN = 2;
/**
* Constructs a PDF Collection.
* @param type the type of PDF collection.
*/
public PdfCollection(int type) : base(PdfName.COLLECTION) {
switch(type) {
case TILE:
Put(PdfName.VIEW, PdfName.T);
break;
case HIDDEN:
Put(PdfName.VIEW, PdfName.H);
break;
default:
Put(PdfName.VIEW, PdfName.D);
break;
}
}
/**
* Identifies the document that will be initially presented
* in the user interface.
* @param description the description that was used when attaching the file to the document
*/
public String InitialDocument {
set {
Put(PdfName.D, new PdfString(value, null));
}
}
/**
* Sets the Collection schema dictionary.
* @param schema an overview of the collection fields
*/
public PdfCollectionSchema Schema {
set {
Put(PdfName.SCHEMA, value);
}
get {
return (PdfCollectionSchema)Get(PdfName.SCHEMA);
}
}
/**
* Sets the Collection sort dictionary.
* @param sort a collection sort dictionary
*/
public PdfCollectionSort Sort {
set {
Put(PdfName.SORT, value);
}
}
}
}

View File

@@ -0,0 +1,127 @@
using System;
using iTextSharp.text.pdf;
namespace iTextSharp.text.pdf.collection {
/**
* @author blowagie
*
*/
public class PdfCollectionField : PdfDictionary {
/** A possible type of collection field. */
public const int TEXT = 0;
/** A possible type of collection field. */
public const int DATE = 1;
/** A possible type of collection field. */
public new const int NUMBER = 2;
/** A possible type of collection field. */
public const int FILENAME = 3;
/** A possible type of collection field. */
public const int DESC = 4;
/** A possible type of collection field. */
public const int MODDATE = 5;
/** A possible type of collection field. */
public const int CREATIONDATE = 6;
/** A possible type of collection field. */
public const int SIZE = 7;
/** The type of the PDF collection field. */
protected internal int fieldType;
/**
* Creates a PdfCollectionField.
* @param name the field name
* @param type the field type
*/
public PdfCollectionField(String name, int type) : base(PdfName.COLLECTIONFIELD) {
Put(PdfName.N, new PdfString(name, PdfObject.TEXT_UNICODE));
this.fieldType = type;
switch (type) {
default:
Put(PdfName.SUBTYPE, PdfName.S);
break;
case DATE:
Put(PdfName.SUBTYPE, PdfName.D);
break;
case NUMBER:
Put(PdfName.SUBTYPE, PdfName.N);
break;
case FILENAME:
Put(PdfName.SUBTYPE, PdfName.F);
break;
case DESC:
Put(PdfName.SUBTYPE, PdfName.DESC);
break;
case MODDATE:
Put(PdfName.SUBTYPE, PdfName.MODDATE);
break;
case CREATIONDATE:
Put(PdfName.SUBTYPE, PdfName.CREATIONDATE);
break;
case SIZE:
Put(PdfName.SUBTYPE, PdfName.SIZE);
break;
}
}
/**
* The relative order of the field name. Fields are sorted in ascending order.
* @param i a number indicating the order of the field
*/
public int Order {
set {
Put(PdfName.O, new PdfNumber(value));
}
}
/**
* Sets the initial visibility of the field.
* @param visible the default is true (visible)
*/
public bool Visible {
set {
Put(PdfName.V, new PdfBoolean(value));
}
}
/**
* Indication if the field value should be editable in the viewer.
* @param editable the default is false (not editable)
*/
public bool Editable {
set {
Put(PdfName.E, new PdfBoolean(value));
}
}
/**
* Checks if the type of the field is suitable for a Collection Item.
*/
public bool IsCollectionItem() {
switch (fieldType) {
case TEXT:
case DATE:
case NUMBER:
return true;
default:
return false;
}
}
/**
* Returns a PdfObject that can be used as the value of a Collection Item.
* @param String value the value that has to be changed into a PdfObject (PdfString, PdfDate or PdfNumber)
*/
public PdfObject GetValue(String v) {
switch (fieldType) {
case TEXT:
return new PdfString(v, PdfObject.TEXT_UNICODE);
case DATE:
return new PdfDate(PdfDate.Decode(v));
case NUMBER:
return new PdfNumber(v);
}
throw new InvalidOperationException(v + " is not an acceptable value for the field " + Get(PdfName.N).ToString());
}
}
}

View File

@@ -0,0 +1,112 @@
using System;
using iTextSharp.text.pdf;
namespace iTextSharp.text.pdf.collection {
public class PdfCollectionItem : PdfDictionary {
/** The PdfCollectionSchema with the names and types of the items. */
internal PdfCollectionSchema schema;
/**
* Constructs a Collection Item that can be added to a PdfFileSpecification.
*/
public PdfCollectionItem(PdfCollectionSchema schema) : base(PdfName.COLLECTIONITEM) {
this.schema = schema;
}
/**
* Sets the value of the collection item.
* @param value
*/
public void AddItem(String key, String value) {
PdfName fieldname = new PdfName(key);
PdfCollectionField field = (PdfCollectionField)schema.Get(fieldname);
Put(fieldname, field.GetValue(value));
}
/**
* Sets the value of the collection item.
* @param value
*/
public void AddItem(String key, PdfString value) {
PdfName fieldname = new PdfName(key);
PdfCollectionField field = (PdfCollectionField)schema.Get(fieldname);
if (field.fieldType == PdfCollectionField.TEXT) {
Put(fieldname, value);
}
}
/**
* Sets the value of the collection item.
* @param value
*/
public void AddItem(String key, PdfDate d) {
PdfName fieldname = new PdfName(key);
PdfCollectionField field = (PdfCollectionField)schema.Get(fieldname);
if (field.fieldType == PdfCollectionField.DATE) {
Put(fieldname, d);
}
}
/**
* Sets the value of the collection item.
* @param value
*/
public void AddItem(String key, PdfNumber n) {
PdfName fieldname = new PdfName(key);
PdfCollectionField field = (PdfCollectionField)schema.Get(fieldname);
if (field.fieldType == PdfCollectionField.NUMBER) {
Put(fieldname, n);
}
}
/**
* Sets the value of the collection item.
* @param value
*/
public void AddItem(String key, DateTime c) {
AddItem(key, new PdfDate(c));
}
/**
* Sets the value of the collection item.
* @param value
*/
public void AddItem(String key, int i) {
AddItem(key, new PdfNumber(i));
}
/**
* Sets the value of the collection item.
* @param value
*/
public void AddItem(String key, float f) {
AddItem(key, new PdfNumber(f));
}
/**
* Sets the value of the collection item.
* @param value
*/
public void AddItem(String key, double d) {
AddItem(key, new PdfNumber(d));
}
/**
* Adds a prefix for the Collection item.
* You can only use this method after you have set the value of the item.
* @param prefix a prefix
*/
public void SetPrefix(String key, String prefix) {
PdfName fieldname = new PdfName(key);
PdfObject o = Get(fieldname);
if (o == null)
throw new InvalidOperationException("You must set a value before adding a prefix.");
PdfDictionary dict = new PdfDictionary(PdfName.COLLECTIONSUBITEM);
dict.Put(PdfName.D, o);
dict.Put(PdfName.P, new PdfString(prefix, PdfObject.TEXT_UNICODE));
Put(fieldname, dict);
}
}
}

View File

@@ -0,0 +1,22 @@
using System;
using iTextSharp.text.pdf;
namespace iTextSharp.text.pdf.collection {
public class PdfCollectionSchema : PdfDictionary {
/**
* Creates a Collection Schema dictionary.
*/
public PdfCollectionSchema() : base(PdfName.COLLECTIONSCHEMA) {
}
/**
* Adds a Collection field to the Schema.
* @param name the name of the collection field
* @param field a Collection Field
*/
public void AddField(String name, PdfCollectionField field) {
Put(new PdfName(name), field);
}
}
}

View File

@@ -0,0 +1,63 @@
using System;
using iTextSharp.text.pdf;
namespace iTextSharp.text.pdf.collection {
public class PdfCollectionSort : PdfDictionary {
/**
* Constructs a PDF Collection Sort Dictionary.
* @param key the key of the field that will be used to sort entries
*/
public PdfCollectionSort(String key) : base(PdfName.COLLECTIONSORT) {
Put(PdfName.S, new PdfName(key));
}
/**
* Constructs a PDF Collection Sort Dictionary.
* @param keys the keys of the fields that will be used to sort entries
*/
public PdfCollectionSort(String[] keys) : base(PdfName.COLLECTIONSORT) {
PdfArray array = new PdfArray();
for (int i = 0; i < keys.Length; i++) {
array.Add(new PdfName(keys[i]));
}
Put(PdfName.S, array);
}
/**
* Defines the sort order of the field (ascending or descending).
* @param ascending true is the default, use false for descending order
*/
public void SetSortOrder(bool ascending) {
PdfObject o = (PdfObject)Get(PdfName.S);
if (o is PdfName) {
Put(PdfName.A, new PdfBoolean(ascending));
}
else {
throw new InvalidOperationException("You have to define a bool array for this collection sort dictionary.");
}
}
/**
* Defines the sort order of the field (ascending or descending).
* @param ascending an array with every element corresponding with a name of a field.
*/
public void SetSortOrder(bool[] ascending) {
PdfObject o = (PdfObject)Get(PdfName.S);
if (o is PdfArray) {
if (((PdfArray)o).Size != ascending.Length) {
throw new InvalidOperationException("The number of booleans in this array doesn't correspond with the number of fields.");
}
PdfArray array = new PdfArray();
for (int i = 0; i < ascending.Length; i++) {
array.Add(new PdfBoolean(ascending[i]));
}
Put(PdfName.A, array);
}
else {
throw new InvalidOperationException("You need a single bool for this collection sort dictionary.");
}
}
}
}

View File

@@ -0,0 +1,101 @@
using System;
using iTextSharp.text.pdf;
namespace iTextSharp.text.pdf.collection {
public class PdfTargetDictionary : PdfDictionary {
/**
* Creates dictionary referring to a target document that is the parent of the current document.
* @param nested null if this is the actual target, another target if this is only an intermediate target.
*/
public PdfTargetDictionary(PdfTargetDictionary nested) : base() {
Put(PdfName.R, PdfName.P);
if (nested != null)
AdditionalPath = nested;
}
/**
* Creates a dictionary referring to a target document.
* @param child if false, this refers to the parent document; if true, this refers to a child document, and you'll have to specify where to find the child using the other methods of this class
*/
public PdfTargetDictionary(bool child) : base() {
if (child) {
Put(PdfName.R, PdfName.C);
}
else {
Put(PdfName.R, PdfName.P);
}
}
/**
* If this dictionary refers to a child that is a document level attachment,
* you need to specify the name that was used to attach the document.
* @param name the name in the EmbeddedFiles name tree
*/
public String EmbeddedFileName {
set {
Put(PdfName.N, new PdfString(value, null));
}
}
/**
* If this dictionary refers to a child that is a file attachment added to a page,
* you need to specify the name of the page (or use setFileAttachmentPage to specify the page number).
* Once you have specified the page, you still need to specify the attachment using another method.
* @param name the named destination referring to the page with the file attachment.
*/
public String FileAttachmentPagename {
set {
Put(PdfName.P, new PdfString(value, null));
}
}
/**
* If this dictionary refers to a child that is a file attachment added to a page,
* you need to specify the page number (or use setFileAttachmentPagename to specify a named destination).
* Once you have specified the page, you still need to specify the attachment using another method.
* @param page the page number of the page with the file attachment.
*/
public int FileAttachmentPage {
set {
Put(PdfName.P, new PdfNumber(value));
}
}
/**
* If this dictionary refers to a child that is a file attachment added to a page,
* you need to specify the page with setFileAttachmentPage or setFileAttachmentPageName,
* and then specify the name of the attachment added to this page (or use setFileAttachmentIndex).
* @param name the name of the attachment
*/
public String FileAttachmentName {
set {
Put(PdfName.A, new PdfString(value, PdfObject.TEXT_UNICODE));
}
}
/**
* If this dictionary refers to a child that is a file attachment added to a page,
* you need to specify the page with setFileAttachmentPage or setFileAttachmentPageName,
* and then specify the index of the attachment added to this page (or use setFileAttachmentName).
* @param name the name of the attachment
*/
public int FileAttachmentIndex {
set {
Put(PdfName.A, new PdfNumber(value));
}
}
/**
* If this dictionary refers to an intermediate target, you can
* add the next target in the sequence.
* @param nested the next target in the sequence
*/
public PdfTargetDictionary AdditionalPath {
set {
Put(PdfName.T, value);
}
}
}
}