예제 #1
0
 /**
 * Use this method to lock an optional content group.
 * The state of a locked group cannot be changed through the user interface
 * of a viewer application. Producers can use this entry to prevent the visibility
 * of content that depends on these groups from being changed by users.
 * @param layer the layer that needs to be added to the array of locked OCGs
 * @since   2.1.2
 */
 public void LockLayer(PdfLayer layer)
 {
     OCGLocked.Add(layer.Ref);
 }
예제 #2
0
 private static void GetOCGOrder(PdfArray order, PdfLayer layer)
 {
     if (!layer.OnPanel)
         return;
     if (layer.Title == null)
         order.Add(layer.Ref);
     ArrayList 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, (PdfLayer)children[k]);
     }
     if (kids.Size > 0)
         order.Add(kids);
 }
예제 #3
0
 /**
 * Recursive method to reconstruct the documentOCGorder variable in the writer.
 * @param    parent  a parent PdfLayer (can be null)
 * @param    arr     an array possibly containing children for the parent PdfLayer
 * @param    ocgmap  a Hashtable with indirect reference Strings as keys and PdfLayer objects as values.
 * @since    2.1.2
 */
 private void AddOrder(PdfLayer parent, PdfArray arr, Hashtable ocgmap)
 {
     PdfObject obj;
     PdfLayer layer;
     for (int i = 0; i < arr.Size; i++) {
         obj = arr[i];
         if (obj.IsIndirect()) {
             layer = (PdfLayer)ocgmap[obj.ToString()];
             layer.OnPanel = true;
             RegisterLayer(layer);
             if (parent != null) {
                 parent.AddChild(layer);
             }
             if (arr.Size > i + 1 && arr[i + 1].IsArray()) {
                 i++;
                 AddOrder(layer, (PdfArray)arr[i], ocgmap);
             }
         }
         else if (obj.IsArray()) {
             PdfArray sub = (PdfArray)obj;
             if (sub.IsEmpty()) return;
             obj = sub[0];
             if (obj.IsString()) {
                 layer = new PdfLayer(obj.ToString());
                 layer.OnPanel = true;
                 RegisterLayer(layer);
                 if (parent != null) {
                     parent.AddChild(layer);
                 }
                 PdfArray array = new PdfArray();
                 for (ListIterator j = sub.GetListIterator(); j.HasNext(); ) {
                     array.Add((PdfObject)j.Next());
                 }
                 AddOrder(layer, array, ocgmap);
             }
             else {
                 AddOrder(parent, (PdfArray)obj, ocgmap);
             }
         }
     }
 }
예제 #4
0
 /**
 * Reads the OCProperties dictionary from the catalog of the existing document
 * and fills the documentOCG, documentOCGorder and OCGRadioGroup variables in PdfWriter.
 * Note that the original OCProperties of the existing document can contain more information.
 * @since    2.1.2
 */
 protected void ReadOCProperties()
 {
     if (documentOCG.Count != 0) {
         return;
     }
     PdfDictionary dict = reader.Catalog.GetAsDict(PdfName.OCPROPERTIES);
     if (dict == null) {
         return;
     }
     PdfArray ocgs = dict.GetAsArray(PdfName.OCGS);
     PdfIndirectReference refi;
     PdfLayer layer;
     Hashtable ocgmap = new Hashtable();
     for (ListIterator i = ocgs.GetListIterator(); i.HasNext();) {
         refi = (PdfIndirectReference)i.Next();
         layer = new PdfLayer(null);
         layer.Ref = refi;
         layer.OnPanel = false;
         layer.Merge((PdfDictionary)PdfReader.GetPdfObject(refi));
         ocgmap[refi.ToString()] = layer;
     }
     PdfDictionary d = dict.GetAsDict(PdfName.D);
     PdfArray off = d.GetAsArray(PdfName.OFF);
     if (off != null) {
         for (ListIterator i = off.GetListIterator(); i.HasNext(); ) {
             refi = (PdfIndirectReference)i.Next();
             layer = (PdfLayer)ocgmap[refi.ToString()];
             layer.On = false;
         }
     }
     PdfArray order = d.GetAsArray(PdfName.ORDER);
     if (order != null) {
         AddOrder(null, order, ocgmap);
     }
     foreach (object o in ocgmap.Values)
         documentOCG[o] = null;
     OCGRadioGroup = d.GetAsArray(PdfName.RBGROUPS);
     OCGLocked = d.GetAsArray(PdfName.LOCKED);
     if (OCGLocked == null)
         OCGLocked = new PdfArray();
 }
예제 #5
0
 /**
 * Adds a new member to the layer.
 * @param layer the new member to the layer
 */
 public void AddMember(PdfLayer layer)
 {
     if (!layers.ContainsKey(layer)) {
         members.Add(layer.Ref);
         layers[layer] = null;
     }
 }
예제 #6
0
 /**
 * Adds a child layer. Nested layers can only have one parent.
 * @param child the child layer
 */
 public void AddChild(PdfLayer child)
 {
     if (child.parent != null)
         throw new ArgumentException("The layer '" + ((PdfString)child.Get(PdfName.NAME)).ToUnicodeString() + "' already has a parent.");
     child.parent = this;
     if (children == null)
         children = new ArrayList();
     children.Add(child);
 }
예제 #7
0
 /**
 * Creates a title layer. A title layer is not really a layer but a collection of layers
 * under the same title heading.
 * @param title the title text
 * @param writer the <CODE>PdfWriter</CODE>
 * @return the title layer
 */
 public static PdfLayer CreateTitle(String title, PdfWriter writer)
 {
     if (title == null)
         throw new ArgumentNullException("Title cannot be null.");
     PdfLayer layer = new PdfLayer(title);
     writer.RegisterLayer(layer);
     return layer;
 }