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);
}
开发者ID:,项目名称:,代码行数:17,代码来源:
示例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);
}
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;
}
开发者ID:,项目名称:,代码行数:29,代码来源:
示例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.");
}
}
/**
* 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;
}
开发者ID:,项目名称:,代码行数:71,代码来源:
示例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);
}
开发者ID:,项目名称:,代码行数:46,代码来源:
示例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();
}
}
开发者ID:,项目名称:,代码行数:91,代码来源:
示例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);
}
开发者ID:,项目名称:,代码行数:8,代码来源:
示例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);
}
}
/**
* 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;
}
}
}
}
/**
* 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);
}
请发表评论