本文整理汇总了C#中iTextSharp.text.pdf.PdfArray类的典型用法代码示例。如果您正苦于以下问题:C# PdfArray类的具体用法?C# PdfArray怎么用?C# PdfArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PdfArray类属于iTextSharp.text.pdf命名空间,在下文中一共展示了PdfArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetOCGOrder
private static void GetOCGOrder(PdfArray order, PdfLayer layer) {
if (!layer.OnPanel)
return;
if (layer.Title == null)
order.Add(layer.Ref);
List<PdfLayer> children = layer.Children;
if (children == null)
return;
PdfArray kids = new PdfArray();
if (layer.Title != null)
kids.Add(new PdfString(layer.Title, PdfObject.TEXT_UNICODE));
for (int k = 0; k < children.Count; ++k) {
GetOCGOrder(kids, children[k]);
}
if (kids.Size > 0)
order.Add(kids);
}
示例2: PdfCollectionSort
/**
* 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);
}
示例3: GetSpotObject
protected internal virtual PdfObject GetSpotObject(PdfWriter writer) {
PdfArray array = new PdfArray(PdfName.SEPARATION);
array.Add(name);
PdfFunction func = null;
if (altcs is ExtendedColor) {
int type = ((ExtendedColor)altcs).Type;
switch (type) {
case ExtendedColor.TYPE_GRAY:
array.Add(PdfName.DEVICEGRAY);
func = PdfFunction.Type2(writer, new float[]{0, 1}, null, new float[]{0}, new float[]{((GrayColor)altcs).Gray}, 1);
break;
case ExtendedColor.TYPE_CMYK:
array.Add(PdfName.DEVICECMYK);
CMYKColor cmyk = (CMYKColor)altcs;
func = PdfFunction.Type2(writer, new float[]{0, 1}, null, new float[]{0, 0, 0, 0},
new float[]{cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black}, 1);
break;
default:
throw new Exception(MessageLocalization.GetComposedMessage("only.rgb.gray.and.cmyk.are.supported.as.alternative.color.spaces"));
}
}
else {
array.Add(PdfName.DEVICERGB);
func = PdfFunction.Type2(writer, new float[]{0, 1}, null, new float[]{1, 1, 1},
new float[]{(float)altcs.R / 255, (float)altcs.G / 255, (float)altcs.B / 255}, 1);
}
array.Add(func.Reference);
return array;
}
示例4: SetSortOrder
/**
* 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.");
}
}
示例5: GetPdfObject
public virtual PdfObject GetPdfObject(PdfWriter writer) {
PdfArray array = new PdfArray(PdfName.LAB);
PdfDictionary dictionary = new PdfDictionary();
if (whitePoint == null
|| whitePoint.Length != 3
|| whitePoint[0] < 0.000001f || whitePoint[2] < 0.000001f
|| whitePoint[1] < 0.999999f || whitePoint[1] > 1.000001f)
throw new Exception(MessageLocalization.GetComposedMessage("lab.cs.white.point"));
dictionary.Put(PdfName.WHITEPOINT, new PdfArray(whitePoint));
if (blackPoint != null) {
if (blackPoint.Length != 3
|| blackPoint[0] < -0.000001f || blackPoint[1] < -0.000001f || blackPoint[2] < -0.000001f)
throw new Exception(MessageLocalization.GetComposedMessage("lab.cs.black.point"));
dictionary.Put(PdfName.BLACKPOINT, new PdfArray(blackPoint));
}
if (range != null) {
if (range.Length != 4 || range[0] > range[1] || range[2] > range[3])
throw new Exception(MessageLocalization.GetComposedMessage("lab.cs.range"));
dictionary.Put(PdfName.RANGE, new PdfArray(range));
}
array.Add(dictionary);
return array;
}
示例6: AddDirectImageSimple
/**
* Adds an image to the document but not to the page resources. It is used with
* templates and <CODE>Document.Add(Image)</CODE>.
* @param image the <CODE>Image</CODE> to add
* @param fixedRef the reference to used. It may be <CODE>null</CODE>,
* a <CODE>PdfIndirectReference</CODE> or a <CODE>PRIndirectReference</CODE>.
* @return the name of the image added
* @throws PdfException on error
* @throws DocumentException on error
*/
public PdfName AddDirectImageSimple(Image image, PdfIndirectReference fixedRef) {
PdfName name;
// if the images is already added, just retrieve the name
if (images.ContainsKey(image.MySerialId)) {
name = images[image.MySerialId];
}
// if it's a new image, add it to the document
else {
if (image.IsImgTemplate()) {
name = new PdfName("img" + images.Count);
if (image is ImgWMF){
ImgWMF wmf = (ImgWMF)image;
wmf.ReadWMF(PdfTemplate.CreateTemplate(this, 0, 0));
}
}
else {
PdfIndirectReference dref = image.DirectReference;
if (dref != null) {
PdfName rname = new PdfName("img" + images.Count);
images[image.MySerialId] = rname;
imageDictionary.Put(rname, dref);
return rname;
}
Image maskImage = image.ImageMask;
PdfIndirectReference maskRef = null;
if (maskImage != null) {
PdfName mname = images[maskImage.MySerialId];
maskRef = GetImageReference(mname);
}
PdfImage i = new PdfImage(image, "img" + images.Count, maskRef);
if (image is ImgJBIG2) {
byte[] globals = ((ImgJBIG2) image).GlobalBytes;
if (globals != null) {
PdfDictionary decodeparms = new PdfDictionary();
decodeparms.Put(PdfName.JBIG2GLOBALS, GetReferenceJBIG2Globals(globals));
i.Put(PdfName.DECODEPARMS, decodeparms);
}
}
if (image.HasICCProfile()) {
PdfICCBased icc = new PdfICCBased(image.TagICC, image.CompressionLevel);
PdfIndirectReference iccRef = Add(icc);
PdfArray iccArray = new PdfArray();
iccArray.Add(PdfName.ICCBASED);
iccArray.Add(iccRef);
PdfArray colorspace = i.GetAsArray(PdfName.COLORSPACE);
if (colorspace != null) {
if (colorspace.Size > 1 && PdfName.INDEXED.Equals(colorspace[0]))
colorspace[1] = iccArray;
else
i.Put(PdfName.COLORSPACE, iccArray);
}
else
i.Put(PdfName.COLORSPACE, iccArray);
}
Add(i, fixedRef);
name = i.Name;
}
images[image.MySerialId] = name;
}
return name;
}
示例7: FillOCProperties
protected void FillOCProperties(bool erase) {
if (vOCProperties == null)
vOCProperties = new PdfOCProperties();
if (erase) {
vOCProperties.Remove(PdfName.OCGS);
vOCProperties.Remove(PdfName.D);
}
if (vOCProperties.Get(PdfName.OCGS) == null) {
PdfArray gr = new PdfArray();
foreach (PdfLayer layer in documentOCG.Keys) {
gr.Add(layer.Ref);
}
vOCProperties.Put(PdfName.OCGS, gr);
}
if (vOCProperties.Get(PdfName.D) != null)
return;
List<IPdfOCG> docOrder = new List<IPdfOCG>(documentOCGorder);
for (ListIterator<IPdfOCG> it = new ListIterator<IPdfOCG>(docOrder); it.HasNext();) {
PdfLayer layer = (PdfLayer)it.Next();
if (layer.Parent != null)
it.Remove();
}
PdfArray order = new PdfArray();
foreach (PdfLayer layer in docOrder) {
GetOCGOrder(order, layer);
}
PdfDictionary d = new PdfDictionary();
vOCProperties.Put(PdfName.D, d);
d.Put(PdfName.ORDER, order);
PdfArray grx = new PdfArray();
foreach (PdfLayer layer in documentOCG.Keys) {
if (!layer.On)
grx.Add(layer.Ref);
}
if (grx.Size > 0)
d.Put(PdfName.OFF, grx);
if (OCGRadioGroup.Size > 0)
d.Put(PdfName.RBGROUPS, OCGRadioGroup);
if (OCGLocked.Size > 0)
d.Put(PdfName.LOCKED, OCGLocked);
AddASEvent(PdfName.VIEW, PdfName.ZOOM);
AddASEvent(PdfName.VIEW, PdfName.VIEW);
AddASEvent(PdfName.PRINT, PdfName.PRINT);
AddASEvent(PdfName.EXPORT, PdfName.EXPORT);
d.Put(PdfName.LISTMODE, PdfName.VISIBLEPAGES);
}
示例8: Close
/**
* Signals that the <CODE>Document</CODE> was closed and that no other
* <CODE>Elements</CODE> will be added.
* <P>
* The pages-tree is built and written to the outputstream.
* A Catalog is constructed, as well as an Info-object,
* the referencetable is composed and everything is written
* to the outputstream embedded in a Trailer.
*/
public override void Close() {
if (open) {
if ((currentPageNumber - 1) != pageReferences.Count)
throw new Exception("The page " + pageReferences.Count +
" was requested but the document has only " + (currentPageNumber - 1) + " pages.");
pdf.Close();
AddSharedObjectsToBody();
foreach (IPdfOCG layer in documentOCG.Keys) {
AddToBody(layer.PdfObject, layer.Ref);
}
// add the root to the body
PdfIndirectReference rootRef = root.WritePageTree();
// make the catalog-object and add it to the body
PdfDictionary catalog = GetCatalog(rootRef);
// [C9] if there is XMP data to add: add it
if (xmpMetadata != null) {
PdfStream xmp = new PdfStream(xmpMetadata);
xmp.Put(PdfName.TYPE, PdfName.METADATA);
xmp.Put(PdfName.SUBTYPE, PdfName.XML);
if (crypto != null && !crypto.IsMetadataEncrypted()) {
PdfArray ar = new PdfArray();
ar.Add(PdfName.CRYPT);
xmp.Put(PdfName.FILTER, ar);
}
catalog.Put(PdfName.METADATA, body.Add(xmp).IndirectReference);
}
// [C10] make pdfx conformant
if (IsPdfX()) {
CompleteInfoDictionary(Info);
CompleteExtraCatalog(ExtraCatalog);
}
// [C11] Output Intents
if (extraCatalog != null) {
catalog.MergeDifferent(extraCatalog);
}
WriteOutlines(catalog, false);
// add the Catalog to the body
PdfIndirectObject indirectCatalog = AddToBody(catalog, false);
// add the info-object to the body
PdfIndirectObject infoObj = AddToBody(Info, false);
// [F1] encryption
PdfIndirectReference encryption = null;
PdfObject fileID = null;
body.FlushObjStm();
if (crypto != null) {
PdfIndirectObject encryptionObject = AddToBody(crypto.GetEncryptionDictionary(), false);
encryption = encryptionObject.IndirectReference;
fileID = crypto.FileID;
}
else
fileID = PdfEncryption.CreateInfoId(PdfEncryption.CreateDocumentId());
// write the cross-reference table of the body
body.WriteCrossReferenceTable(os, indirectCatalog.IndirectReference,
infoObj.IndirectReference, encryption, fileID, prevxref);
// make the trailer
// [F2] full compression
if (fullCompression) {
WriteKeyInfo(os);
byte[] tmp = GetISOBytes("startxref\n");
os.Write(tmp, 0, tmp.Length);
tmp = GetISOBytes(body.Offset.ToString());
os.Write(tmp, 0, tmp.Length);
tmp = GetISOBytes("\n%%EOF\n");
os.Write(tmp, 0, tmp.Length);
}
else {
PdfTrailer trailer = new PdfTrailer(body.Size,
body.Offset,
indirectCatalog.IndirectReference,
infoObj.IndirectReference,
encryption,
fileID, prevxref);
trailer.ToPdf(this, os);
}
base.Close();
}
}
示例9: SetPageViewport
/**
* Sets the Viewport for the next page.
* @param viewport an array consisting of Viewport dictionaries.
* @since 5.1.0
*/
public void SetPageViewport(PdfArray vp) {
AddPageDictEntry(PdfName.VP, vp);
}
示例10: AlterContents
virtual internal protected void AlterContents() {
foreach (PageStamp ps in pagesToContent.Values) {
PdfDictionary pageN = ps.pageN;
MarkUsed(pageN);
PdfArray ar = null;
PdfObject content = PdfReader.GetPdfObject(pageN.Get(PdfName.CONTENTS), pageN);
if (content == null) {
ar = new PdfArray();
pageN.Put(PdfName.CONTENTS, ar);
}
else if (content.IsArray()) {
ar = new PdfArray((PdfArray)content);
pageN.Put(PdfName.CONTENTS, ar);
}
else if (content.IsStream()) {
ar = new PdfArray();
ar.Add(pageN.Get(PdfName.CONTENTS));
pageN.Put(PdfName.CONTENTS, ar);
}
else {
ar = new PdfArray();
pageN.Put(PdfName.CONTENTS, ar);
}
ByteBuffer out_p = new ByteBuffer();
if (ps.under != null) {
out_p.Append(PdfContents.SAVESTATE);
ApplyRotation(pageN, out_p);
out_p.Append(ps.under.InternalBuffer);
out_p.Append(PdfContents.RESTORESTATE);
}
if (ps.over != null)
out_p.Append(PdfContents.SAVESTATE);
PdfStream stream = new PdfStream(out_p.ToByteArray());
stream.FlateCompress(compressionLevel);
ar.AddFirst(AddToBody(stream).IndirectReference);
out_p.Reset();
if (ps.over != null) {
out_p.Append(' ');
out_p.Append(PdfContents.RESTORESTATE);
ByteBuffer buf = ps.over.InternalBuffer;
out_p.Append(buf.Buffer, 0, ps.replacePoint);
out_p.Append(PdfContents.SAVESTATE);
ApplyRotation(pageN, out_p);
out_p.Append(buf.Buffer, ps.replacePoint, buf.Size - ps.replacePoint);
out_p.Append(PdfContents.RESTORESTATE);
stream = new PdfStream(out_p.ToByteArray());
stream.FlateCompress(compressionLevel);
ar.Add(AddToBody(stream).IndirectReference);
}
AlterResources(ps);
}
}
示例11: AddAnnotation
internal void AddAnnotation(PdfAnnotation annot, PdfDictionary pageN)
{
ArrayList allAnnots = new ArrayList();
if (annot.IsForm()) {
fieldsAdded = true;
AcroFields afdummy = AcroFields;
PdfFormField field = (PdfFormField)annot;
if (field.Parent != null)
return;
ExpandFields(field, allAnnots);
}
else
allAnnots.Add(annot);
for (int k = 0; k < allAnnots.Count; ++k) {
annot = (PdfAnnotation)allAnnots[k];
if (annot.PlaceInPage > 0)
pageN = reader.GetPageN(annot.PlaceInPage);
if (annot.IsForm()) {
if (!annot.IsUsed()) {
Hashtable templates = annot.Templates;
if (templates != null) {
foreach (object tpl in templates.Keys) {
fieldTemplates[tpl] = null;
}
}
}
PdfFormField field = (PdfFormField)annot;
if (field.Parent == null)
AddDocumentField(field.IndirectReference);
}
if (annot.IsAnnotation()) {
PdfArray annots = (PdfArray)PdfReader.GetPdfObject(pageN.Get(PdfName.ANNOTS), pageN);
if (annots == null) {
annots = new PdfArray();
pageN.Put(PdfName.ANNOTS, annots);
MarkUsed(pageN);
}
annots.Add(annot.IndirectReference);
MarkUsed(annots);
if (!annot.IsUsed()) {
PdfRectangle rect = (PdfRectangle)annot.Get(PdfName.RECT);
if (rect != null && (rect.Left != 0 || rect.Right != 0 || rect.Top != 0 || rect.Bottom != 0)) {
int rotation = reader.GetPageRotation(pageN);
Rectangle pageSize = reader.GetPageSizeWithRotation(pageN);
switch (rotation) {
case 90:
annot.Put(PdfName.RECT, new PdfRectangle(
pageSize.Top - rect.Bottom,
rect.Left,
pageSize.Top - rect.Top,
rect.Right));
break;
case 180:
annot.Put(PdfName.RECT, new PdfRectangle(
pageSize.Right - rect.Left,
pageSize.Top - rect.Bottom,
pageSize.Right - rect.Right,
pageSize.Top - rect.Top));
break;
case 270:
annot.Put(PdfName.RECT, new PdfRectangle(
rect.Bottom,
pageSize.Right - rect.Left,
rect.Top,
pageSize.Right - rect.Right));
break;
}
}
}
}
if (!annot.IsUsed()) {
annot.SetUsed();
AddToBody(annot, annot.IndirectReference);
}
}
}
示例12: InsertPage
internal void InsertPage(int pageNumber, Rectangle mediabox)
{
Rectangle media = new Rectangle(mediabox);
int rotation = media.Rotation % 360;
PdfDictionary page = new PdfDictionary(PdfName.PAGE);
PdfDictionary resources = new PdfDictionary();
PdfArray procset = new PdfArray();
procset.Add(PdfName.PDF);
procset.Add(PdfName.TEXT);
procset.Add(PdfName.IMAGEB);
procset.Add(PdfName.IMAGEC);
procset.Add(PdfName.IMAGEI);
resources.Put(PdfName.PROCSET, procset);
page.Put(PdfName.RESOURCES, resources);
page.Put(PdfName.ROTATE, new PdfNumber(rotation));
page.Put(PdfName.MEDIABOX, new PdfRectangle(media, rotation));
PRIndirectReference pref = reader.AddPdfObject(page);
PdfDictionary parent;
PRIndirectReference parentRef;
if (pageNumber > reader.NumberOfPages) {
PdfDictionary lastPage = reader.GetPageNRelease(reader.NumberOfPages);
parentRef = (PRIndirectReference)lastPage.Get(PdfName.PARENT);
parentRef = new PRIndirectReference(reader, parentRef.Number);
parent = (PdfDictionary)PdfReader.GetPdfObject(parentRef);
PdfArray kids = (PdfArray)PdfReader.GetPdfObject(parent.Get(PdfName.KIDS), parent);
kids.Add(pref);
MarkUsed(kids);
reader.pageRefs.InsertPage(pageNumber, pref);
}
else {
if (pageNumber < 1)
pageNumber = 1;
PdfDictionary firstPage = reader.GetPageN(pageNumber);
PRIndirectReference firstPageRef = reader.GetPageOrigRef(pageNumber);
reader.ReleasePage(pageNumber);
parentRef = (PRIndirectReference)firstPage.Get(PdfName.PARENT);
parentRef = new PRIndirectReference(reader, parentRef.Number);
parent = (PdfDictionary)PdfReader.GetPdfObject(parentRef);
PdfArray kids = (PdfArray)PdfReader.GetPdfObject(parent.Get(PdfName.KIDS), parent);
ArrayList ar = kids.ArrayList;
int len = ar.Count;
int num = firstPageRef.Number;
for (int k = 0; k < len; ++k) {
PRIndirectReference cur = (PRIndirectReference)ar[k];
if (num == cur.Number) {
ar.Insert(k, pref);
break;
}
}
if (len == ar.Count)
throw new Exception("Internal inconsistence.");
MarkUsed(kids);
reader.pageRefs.InsertPage(pageNumber, pref);
CorrectAcroFieldPages(pageNumber);
}
page.Put(PdfName.PARENT, parentRef);
while (parent != null) {
MarkUsed(parent);
PdfNumber count = (PdfNumber)PdfReader.GetPdfObjectRelease(parent.Get(PdfName.COUNT));
parent.Put(PdfName.COUNT, new PdfNumber(count.IntValue + 1));
parent = (PdfDictionary)PdfReader.GetPdfObject(parent.Get(PdfName.PARENT));
}
}
示例13: IterateFields
/**
* After reading, we index all of the fields. Recursive.
* @param fieldlist An array of fields
* @param fieldDict the last field dictionary we encountered (recursively)
* @param parentPath the pathname of the field, up to this point or null
*/
virtual protected void IterateFields(PdfArray fieldlist, PRIndirectReference fieldDict, String parentPath) {
foreach (PRIndirectReference refi in fieldlist.ArrayList) {
PdfDictionary dict = (PdfDictionary) PdfReader.GetPdfObjectRelease(refi);
// if we are not a field dictionary, pass our parent's values
PRIndirectReference myFieldDict = fieldDict;
String fullPath = parentPath;
PdfString tField = (PdfString)dict.Get(PdfName.T);
bool isFieldDict = tField != null;
if (isFieldDict) {
myFieldDict = refi;
if (parentPath == null) {
fullPath = tField.ToString();
} else {
fullPath = parentPath + '.' + tField.ToString();
}
}
PdfArray kids = (PdfArray)dict.Get(PdfName.KIDS);
if (kids != null) {
PushAttrib(dict);
IterateFields(kids, myFieldDict, fullPath);
stack.RemoveAt(stack.Count - 1); // pop
}
else { // leaf node
if (myFieldDict != null) {
PdfDictionary mergedDict = (PdfDictionary)stack[stack.Count - 1];
if (isFieldDict)
mergedDict = MergeAttrib(mergedDict, dict);
mergedDict.Put(PdfName.T, new PdfString(fullPath));
FieldInformation fi = new FieldInformation(fullPath, mergedDict, myFieldDict);
fields.Add(fi);
fieldByName[fullPath] = fi;
}
}
}
}
示例14: SerArray
private void SerArray(PdfArray array, int level, ByteBuffer bb)
{
bb.Append("$A");
if (level <= 0)
return;
for (int k = 0; k < array.Size; ++k) {
SerObject(array[k], level, bb);
}
}
示例15: PdfArray
/**
* Constructs an <CODE>PdfArray</CODE>-object, containing all the <CODE>PdfObject</CODE>s in a given <CODE>PdfArray</CODE>.
*
* @param array a <CODE>PdfArray</CODE> that has to be added to the array
*/
public PdfArray(PdfArray array)
: base(ARRAY)
{
arrayList = new ArrayList(array.arrayList);
}