Package org.pdfclown.objects

Examples of org.pdfclown.objects.PdfReference


            NOTE: Curiously, PDF references are the only primitive objects that require
            a file reference. That's because they deal with indirect objects, which are strongly
            coupled with the current state of the file: so, PDF references are the fundamental
            bridge between the token layer and the file layer.
          */
          return new PdfReference(
            (Reference)token,
            file
            );
        case Literal:
          return new PdfTextString(
View Full Code Here


      */
      appendXRefSubsectionIndexer(xrefBuilder, 0, xrefSize);

      StringBuilder xrefInUseBlockBuilder = new StringBuilder();
      IndirectObjects indirectObjects = file.getIndirectObjects();
      PdfReference freeReference = indirectObjects.get(0).getReference(); // Initialized to the first free entry.
      for(
        int index = 1;
        index < xrefSize;
        index++
        )
View Full Code Here

      if(!(dataObject instanceof PdfDictionary) // Data object is NOT a dictionary.
        || !PdfName.Font.equals(((PdfDictionary)dataObject).get(PdfName.Type))) // Dictionary is NOT a font object.
        continue;

      // Get the indirect reference to the ToUnicode stream associated to the font object!
      PdfReference toUnicodeReference = (PdfReference)((PdfDictionary)dataObject).get(PdfName.ToUnicode);
      if(toUnicodeReference == null) // No ToUnicode stream.
        continue;

      /*
        NOTE: You can either:
          1) modify the existing data object contained within the indirect object;
        or
          2) create a new data object to replace the existing data object contained within the indirect object.
        For the sake of completeness, in this sample we apply both these approaches.

        NOTE: Data objects may be any object inheriting from the PdfDataObject class
        (for example: PdfName, PdfInteger, PdfTextString, PdfArray, PdfStream, PdfDictionary and so on...).
        Unicode mapping streams are... (you guess!) PdfStream objects.
      */
      if(toUnicodeReference.getObjectNumber() % 2 == 0) // NOTE: Arbitrary condition to force the use of both the approaches.
      {
        /*
          Approach 1: Modifying the existing data object.
        */
        // Get the existing data object from the corresponding indirect object!
        PdfStream toUnicodeStream = (PdfStream)toUnicodeReference.getDataObject();

        // Editing the data object...
        IBuffer streamBody = toUnicodeStream.getBody();
        streamBody.setLength(0); // Erases the stream content to prepare it for new content insertion.
        streamBody.append("... modified ..."); // Adds arbitrary contents (NOTE: this would NOT be done in a real ToUnicode stream! We are just testing the editing functionality...).
      }
      else
      {
        /*
          Approach 2: Creating a new data object.
        */
        // Create a new data object!
        PdfStream toUnicodeStream = new PdfStream();
        // Associate the new data object to the existing indirect object, replacing the old one!
        toUnicodeReference.setDataObject(toUnicodeStream);

        // Editing the data object...
        IBuffer streamBody = toUnicodeStream.getBody();
        streamBody.append("... created ..."); // Adds arbitrary contents (NOTE: this would NOT be done in a real ToUnicode stream! We are just testing the editing functionality...).
      }

      toUnicodeReference.getIndirectObject().update(); // Ensures that the indirect object is updated.
    }

    // 3. Serialize the PDF file!
    serialize(file);
   
View Full Code Here

      representations of the same underlying field; they should differ only in properties
      that specify their visual appearance. In particular, field dictionaries with the same
      fully qualified field name must have the same field type (FT), value (V), and default
      value (DV).
     */
    PdfReference valueFieldReference = null;
    {
      Iterator<String> partialNamesIterator = Arrays.asList(((String)key).split("\\.")).iterator();
      Iterator<PdfDirectObject> fieldObjectsIterator = getBaseDataObject().iterator();
      while(partialNamesIterator.hasNext())
      {
        String partialName = partialNamesIterator.next();
        valueFieldReference = null;
        while(fieldObjectsIterator != null && fieldObjectsIterator.hasNext())
        {
          PdfReference fieldReference = (PdfReference)fieldObjectsIterator.next();
          PdfDictionary fieldDictionary = (PdfDictionary)fieldReference.getDataObject();
          PdfTextString fieldName = (PdfTextString)fieldDictionary.get(PdfName.T);
          if(fieldName != null && fieldName.getValue().equals(partialName))
          {
            valueFieldReference = fieldReference;
            PdfArray kidFieldObjects = (PdfArray)fieldDictionary.resolve(PdfName.Kids);
View Full Code Here

    if(field == null)
      return null;

    PdfArray fieldObjects;
    {
      PdfReference fieldParentReference = (PdfReference)field.getBaseDataObject().get(PdfName.Parent);
      if(fieldParentReference == null)
      {fieldObjects = getBaseDataObject();}
      else
      {fieldObjects = (PdfArray)((PdfDictionary)fieldParentReference.getDataObject()).resolve(PdfName.Kids);}
    }
    return (fieldObjects.remove(field.getBaseObject()) ? field : null);
  }
View Full Code Here

    List<Field> values
    )
  {
    for(PdfDirectObject fieldObject : fieldObjects)
    {
      PdfReference fieldReference = (PdfReference)fieldObject;
      PdfArray kidReferences = (PdfArray)File.resolve(
        ((PdfDictionary)fieldReference.getDataObject()).get(PdfName.Kids)
        );
      PdfDictionary kidObject;
      if(kidReferences == null)
      {kidObject = null;}
      else
View Full Code Here

            || key.equals(PdfName.MK))
          {
            if(widgetDictionary == null)
            {
              widgetDictionary = new PdfDictionary();
              PdfReference widgetReference = getFile().register(widgetDictionary);

              // Remove the field from the page annotations (as the widget annotation is decoupled from it)!
              PdfArray pageAnnotationsArray = (PdfArray)File.resolve(((PdfDictionary)File.resolve(fieldDictionary.get(PdfName.P))).get(PdfName.Annots));
              pageAnnotationsArray.remove(field.getBaseObject());
View Full Code Here

  @Override
  public Bookmark get(
    int index
    )
  {
    PdfReference bookmarkObject = (PdfReference)getBaseDataObject().get(PdfName.First);
    while(index > 0)
    {
      bookmarkObject = (PdfReference)((PdfDictionary)File.resolve(bookmarkObject)).get(PdfName.Next);
      // Did we go past the collection range?
      if(bookmarkObject == null)
View Full Code Here

      countObject.setValue(countObject.getValue()+1);
    }
    else // Non-first bookmark.
    {
      PdfReference oldLastBookmarkReference = (PdfReference)getBaseDataObject().get(PdfName.Last);
      getBaseDataObject().put(PdfName.Last,bookmark.getBaseObject()); // Added bookmark is the last in the collection...
      ((PdfDictionary)File.resolve(oldLastBookmarkReference)).put(PdfName.Next,bookmark.getBaseObject()); // ...and the next of the previously-last bookmark.
      bookmark.getBaseDataObject().put(PdfName.Prev,oldLastBookmarkReference);

      /*
 
View Full Code Here

    Gets the parent bookmark.
  */
  public Bookmark getParent(
    )
  {
    PdfReference reference = (PdfReference)getBaseDataObject().get(PdfName.Parent);
    // Is its parent a bookmark?
    /*
      NOTE: the Title entry can be used as a flag to distinguish bookmark
      (outline item) dictionaries from outline (root) dictionaries.
    */
 
View Full Code Here

TOP

Related Classes of org.pdfclown.objects.PdfReference

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.