Package org.pdfclown.objects

Examples of org.pdfclown.objects.PdfArray


  public EmbeddedFile put(
    String key,
    EmbeddedFile value
    )
  {
    PdfArray itemPairs = getBaseDataObject();
    for(
      int index = 0,
        length = itemPairs.size();
      index < length;
      index += 2
      )
    {
      // Already existing entry?
      if(((PdfTextString)itemPairs.get(index)).getValue().equals(key))
      {
        EmbeddedFile oldEmbeddedFile = new EmbeddedFile(itemPairs.get(index+1));

        itemPairs.set(index+1,value.getBaseObject());

        return oldEmbeddedFile;
      }
    }

    // New entry.
    itemPairs.add(new PdfTextString(key));
    itemPairs.add(value.getBaseObject());

    return null;
  }
View Full Code Here


  @Override
  public EmbeddedFile remove(
    Object key
    )
  {
    PdfArray itemPairs = getBaseDataObject();
    for(
      int index = 0,
        length = itemPairs.size();
      index < length;
      index += 2
      )
    {
      if(((PdfTextString)itemPairs.get(index)).getValue().equals(key))
      {
        itemPairs.remove(index); // Key removed.

        return new EmbeddedFile(itemPairs.remove(index)); // Value removed.
      }
    }

    return null;
  }
View Full Code Here

  @Override
  public Collection<EmbeddedFile> values(
    )
  {
    List<EmbeddedFile> values = new ArrayList<EmbeddedFile>();
    PdfArray itemPairs = getBaseDataObject();
    for(
      int index = 1,
        length = itemPairs.size();
      index < length;
      index += 2
      )
    {
      values.add(
        new EmbeddedFile(itemPairs.get(index))
        );
    }

    return values;
  }
View Full Code Here

    // Are contents just a single stream object?
    if(baseDataObject instanceof PdfStream) // Single stream.
    {stream = (PdfStream)baseDataObject;}
    else // Array of streams.
    {
      PdfArray streams = (PdfArray)baseDataObject;
      // No stream available?
      if(streams.size() == 0) // No stream.
      {
        // Add first stream!
        stream = new PdfStream();
        streams.add( // Inserts the new stream into the content stream.
          getFile().register(stream) // Inserts the new stream into the file.
          );
      }
      else // Streams exist.
      {
        // Eliminating exceeding streams...
        /*
          NOTE: Applications that consume or produce PDF files are not required to preserve
          the existing structure of the Contents array [PDF:1.6:3.6.2].
        */
        while(streams.size() > 1)
        {
          getFile().unregister( // Removes the exceeding stream from the file.
            (PdfReference)streams.remove(1) // Removes the exceeding stream from the content stream.
            );
        }

        PdfReference streamReference = (PdfReference)streams.get(0);
        File.update(streamReference); // Updates the existing stream into the file.
        stream = (PdfStream)streamReference.getDataObject();
      }
    }

View Full Code Here

      lower-indexed item to the ancestor of this page object at that level.
    */
    PdfReference ancestorKidReference = (PdfReference)getBaseObject();
    PdfReference parentReference = (PdfReference)getBaseDataObject().get(PdfName.Parent);
    PdfDictionary parent = (PdfDictionary)File.resolve(parentReference);
    PdfArray kids = (PdfArray)File.resolve(parent.get(PdfName.Kids));
    int index = 0;
    for(
      int i = 0;
      true;
      i++
      )
    {
      PdfReference kidReference = (PdfReference)kids.get(i);
      // Is the current-level counting complete?
      // NOTE: It's complete when it reaches the ancestor at the current level.
      if(kidReference.equals(ancestorKidReference)) // Ancestor node.
      {
        // Does the current level correspond to the page-tree root node?
View Full Code Here

    /*
      NOTE: This specialized stamper is optimized for content insertion without modifying
      existing content representations, leveraging the peculiar feature of page structures
      to express their content streams as arrays of data streams.
    */
    PdfArray streams;
    {
      PdfDirectObject contentsObject = page.getBaseDataObject().get(PdfName.Contents);
      PdfDataObject contentsDataObject = File.resolve(contentsObject);
      // Single data stream?
      if(contentsDataObject instanceof PdfStream)
      {
        /*
          NOTE: Content stream MUST be expressed as an array of data streams in order to host
          background- and foreground-stamped contents.
        */
        streams = new PdfArray();
        streams.add(contentsObject);
        page.getBaseDataObject().put(PdfName.Contents,streams);

        page.update(); // Fundamental to override original page contents collection.
      }
      else
      {
        streams = (PdfArray)contentsDataObject;

        if(!File.update(contentsObject))
        {page.update();} // Fundamental to override original page contents collection.
      }
    }

    // Background.
    // Serialize the content!
    background.flush();
    // Insert the serialized content into the page's content stream!
    streams.add(
      0,
      (PdfReference)background.getScanner().getContents().getBaseObject()
      );

    // Foreground.
    // Serialize the content!
    foreground.flush();
    // Append the serialized content into the page's content stream!
    streams.add(
      (PdfReference)foreground.getScanner().getContents().getBaseObject()
      );
  }
View Full Code Here

          PdfName.Count
        },
        new PdfDirectObject[]
        {
          PdfName.Pages,
          new PdfArray(),
          new PdfInteger(0)
        }
        )
      );
  }
View Full Code Here

      does NOT adopt recursion to deepen its search, opting for an iterative strategy
      instead.
    */
    int pageOffset = 0;
    PdfDictionary parent = getBaseDataObject();
    PdfArray kids = (PdfArray)File.resolve(parent.get(PdfName.Kids));
    for(
      int i = 0;
      i < kids.size();
      i++
      )
    {
      PdfReference kidReference = (PdfReference)kids.get(i);
      PdfDictionary kid = (PdfDictionary)File.resolve(kidReference);
      // Is current kid a page object?
      if(kid.get(PdfName.Type).equals(PdfName.Page)) // Page object.
      {
        // Did we reach the searched position?
View Full Code Here

    // Get the parent tree node!
    PdfDirectObject parent = pageData.get(PdfName.Parent);
    PdfDictionary parentData = (PdfDictionary)File.resolve(parent);
    // Get the parent's page collection!
    PdfDirectObject kids = parentData.get(PdfName.Kids);
    PdfArray kidsData = (PdfArray)File.resolve(kids);
    // Remove the page!
    kidsData.remove(pageObj.getBaseObject());
    boolean updateParent = !File.update(kids); // Try to update the page collection.
    // Unbind the page from its parent!
    pageData.put(PdfName.Parent,null);
    pageObj.update();
    // Decrementing the pages counters...
View Full Code Here

    )
  {
    PdfDirectObject parent;
    PdfDictionary parentData;
    PdfDirectObject kids;
    PdfArray kidsData;
    int offset;
    // Append operation?
    if(index == -1) // Append operation.
    {
      // Get the parent tree node!
      parent = getBaseObject();
      parentData = getBaseDataObject();
      // Get the parent's page collection!
      kids = parentData.get(PdfName.Kids);
      kidsData = (PdfArray)File.resolve(kids);
      offset = 0; // Not used.
    }
    else // Insert operation.
    {
      // Get the page currently at the specified position!
      Page pivotPage = get(index);
      // Get the parent tree node!
      parent = pivotPage.getBaseDataObject().get(PdfName.Parent);
      parentData = (PdfDictionary)File.resolve(parent);
      // Get the parent's page collection!
      kids = parentData.get(PdfName.Kids);
      kidsData = (PdfArray)File.resolve(kids);
      // Get the insertion's relative position within the parent's page collection!
      offset = kidsData.indexOf(pivotPage.getBaseObject());
    }

    // Adding the pages...
    for(Page page : pages)
    {
      // Append?
      if(index == -1) // Append.
      {
        // Append the page to the collection!
        kidsData.add(page.getBaseObject());
      }
      else // Insert.
      {
        // Insert the page into the collection!
        kidsData.add(
          offset++,
          page.getBaseObject()
          );
      }
      // Bind the page to the collection!
View Full Code Here

TOP

Related Classes of org.pdfclown.objects.PdfArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.