Package org.pdfclown.objects

Examples of org.pdfclown.objects.PdfDictionary


  {
    Document document = field.getDocument();
    for(Widget widget : field.getWidgets())
    {
      {
        PdfDictionary widgetDataObject = widget.getBaseDataObject();
        widgetDataObject.put(
          PdfName.DA,
          new PdfString("/ZaDb 0 Tf 0 0 0 rg")
          );
        widgetDataObject.put(
          PdfName.MK,
          new PdfDictionary(
            new PdfName[]
            {
              PdfName.BG,
              PdfName.BC,
              PdfName.CA
            },
            new PdfDirectObject[]
            {
              new PdfArray(new PdfDirectObject[]{new PdfReal(0.9412),new PdfReal(0.9412),new PdfReal(0.9412)}),
              new PdfArray(new PdfDirectObject[]{new PdfInteger(0),new PdfInteger(0),new PdfInteger(0)}),
              new PdfString("4")
            }
            )
          );
        widgetDataObject.put(
          PdfName.BS,
          new PdfDictionary(
            new PdfName[]
            {
              PdfName.W,
              PdfName.S
            },
            new PdfDirectObject[]
            {
              new PdfReal(0.8),
              PdfName.S
            }
            )
          );
        widgetDataObject.put(
          PdfName.H,
          PdfName.P
          );
      }
View Full Code Here


  {
    Document document = field.getDocument();
    for(Widget widget : field.getWidgets())
    {
      {
        PdfDictionary widgetDataObject = widget.getBaseDataObject();
        widgetDataObject.put(
          PdfName.DA,
          new PdfString("/ZaDb 0 Tf 0 0 0 rg")
          );
        widgetDataObject.put(
          PdfName.MK,
          new PdfDictionary(
            new PdfName[]
            {
              PdfName.BG,
              PdfName.BC,
              PdfName.CA
            },
            new PdfDirectObject[]
            {
              new PdfArray(new PdfDirectObject[]{new PdfReal(0.9412),new PdfReal(0.9412),new PdfReal(0.9412)}),
              new PdfArray(new PdfDirectObject[]{new PdfInteger(0),new PdfInteger(0),new PdfInteger(0)}),
              new PdfString("l")
            }
            )
          );
        widgetDataObject.put(
          PdfName.BS,
          new PdfDictionary(
            new PdfName[]
            {
              PdfName.W,
              PdfName.S
            },
            new PdfDirectObject[]
            {
              new PdfReal(0.8),
              PdfName.S
            }
            )
          );
        widgetDataObject.put(
          PdfName.H,
          PdfName.P
          );
      }
View Full Code Here

    Appearance appearance = widget.getAppearance();
    if(appearance == null)
    {widget.setAppearance(appearance = new Appearance(document));}

    {
      PdfDictionary widgetDataObject = widget.getBaseDataObject();
      widgetDataObject.put(
        PdfName.DA,
        new PdfString("/Helv " + getFontSize() + " Tf 0 0 0 rg")
        );
      widgetDataObject.put(
        PdfName.MK,
        new PdfDictionary(
          new PdfName[]
          {
            PdfName.BG,
            PdfName.BC
          },
View Full Code Here

  public FileInfo readInfo(
    ) throws FileFormatException
  {
//TODO:hybrid xref table/stream
    Version version = Version.get(parser.retrieveVersion());
    PdfDictionary trailer = null;
    SortedMap<Integer,XRefEntry> xrefEntries = new TreeMap<Integer,XRefEntry>();
    {
      long sectionOffset = parser.retrieveXRefOffset();
      while(sectionOffset > -1)
      {
        // Move to the start of the xref section!
        parser.seek(sectionOffset);

        PdfDictionary sectionTrailer;
        if(parser.getToken(1).equals(Keyword.XRef)) // XRef-table section.
        {
          // Looping sequentially across the subsections inside the current xref-table section...
          while(true)
          {
            /*
              NOTE: Each iteration of this block represents the scanning of one subsection.
              We get its bounds (first and last object numbers within its range) and then collect
              its entries.
            */
            // 1. First object number.
            parser.moveNext();
            if((parser.getTokenType() == TokenTypeEnum.Keyword)
                && parser.getToken().equals(Keyword.Trailer)) // XRef-table section ended.
              break;
            else if(parser.getTokenType() != TokenTypeEnum.Integer)
              throw new FileFormatException("Neither object number of the first object in this xref subsection nor end of xref section found.",parser.getPosition());

            // Get the object number of the first object in this xref-table subsection!
            int startObjectNumber = (Integer)parser.getToken();

            // 2. Last object number.
            parser.moveNext();
            if(parser.getTokenType() != TokenTypeEnum.Integer)
              throw new FileFormatException("Number of entries in this xref subsection not found.",parser.getPosition());

            // Get the object number of the last object in this xref-table subsection!
            int endObjectNumber = (Integer)parser.getToken() + startObjectNumber;

            // 3. XRef-table subsection entries.
            for(
              int index = startObjectNumber;
              index < endObjectNumber;
              index++
              )
            {
              if(xrefEntries.containsKey(index)) // Already-defined entry.
              {
                // Skip to the next entry!
                parser.moveNext(3);
              }
              else // Undefined entry.
              {
                // Get the indirect object offset!
                int offset = (Integer)parser.getToken(1);
                // Get the object generation number!
                int generation = (Integer)parser.getToken(1);
                // Get the usage tag!
                XRefEntry.UsageEnum usage;
                {
                  String usageToken = (String)parser.getToken(1);
                  if(usageToken.equals(Keyword.InUseXrefEntry))
                    usage = XRefEntry.UsageEnum.InUse;
                  else if(usageToken.equals(Keyword.FreeXrefEntry))
                    usage = XRefEntry.UsageEnum.Free;
                  else
                    throw new FileFormatException("Invalid xref entry.",parser.getPosition());
                }

                // Entry initialization.
                xrefEntries.put(
                  index,
                  new XRefEntry(
                    index,
                    generation,
                    offset,
                    usage
                    )
                  );
              }
            }
          }

          // Get the previous trailer!
          sectionTrailer = (PdfDictionary)parser.parsePdfObject(1);
        }
        else // XRef-stream section.
        {
          XRefStream stream = (XRefStream)parser.parsePdfObject(3); // Gets the xref stream skipping the indirect-object header.
          // Add the xref entries from the current xref stream!
          xrefEntries.putAll(stream);

          // Get the previous trailer!
          sectionTrailer = stream.getHeader();
        }

        if(trailer == null)
        {trailer = sectionTrailer;}

        // Get the previous xref-table section's offset!
        PdfInteger prevXRefOffset = (PdfInteger)sectionTrailer.get(PdfName.Prev);
        sectionOffset = (prevXRefOffset != null ? prevXRefOffset.getValue() : -1);
      }
    }
    return new FileInfo(version, trailer, xrefEntries);
  }
View Full Code Here

        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);
            fieldObjectsIterator = (kidFieldObjects == null ? null : kidFieldObjects.iterator());
            break;
          }
        }
        if(valueFieldReference == null)
View Full Code Here

    {
      PdfReference fieldReference = (PdfReference)fieldObject;
      PdfArray kidReferences = (PdfArray)File.resolve(
        ((PdfDictionary)fieldReference.getDataObject()).get(PdfName.Kids)
        );
      PdfDictionary kidObject;
      if(kidReferences == null)
      {kidObject = null;}
      else
      {kidObject = (PdfDictionary)((PdfReference)kidReferences.get(0)).getDataObject();}
      // Terminal field?
      if(kidObject == null // Merged single widget annotation.
        || (!kidObject.containsKey(PdfName.FT) // Multiple widget annotations.
          && kidObject.containsKey(PdfName.Subtype)
          && kidObject.get(PdfName.Subtype).equals(PdfName.Widget)))
      {values.add(Field.wrap(fieldReference));}
      else // Non-terminal field.
      {retrieveValues(kidReferences, values);}
    }
  }
View Full Code Here

    Document context
    )
  {
    super(
      context.getFile(),
      new PdfDictionary()
      );
  }
View Full Code Here

    PdfDataObject baseDataObject = getBaseDataObject();
    if(baseDataObject instanceof PdfDictionary) // Merged annotation.
    {
      PdfArray widgetsArray = new PdfArray();
      {
        PdfDictionary fieldDictionary = (PdfDictionary)baseDataObject;
        PdfDictionary widgetDictionary = null;
        // Extracting widget entries from the field...
        for(PdfName key : new HashMap<PdfName,PdfDirectObject>(fieldDictionary).keySet())
        {
          // Is it a widget entry?
          if(key.equals(PdfName.Type)
            || key.equals(PdfName.Subtype)
            || key.equals(PdfName.Rect)
            || key.equals(PdfName.Contents)
            || key.equals(PdfName.P)
            || key.equals(PdfName.NM)
            || key.equals(PdfName.M)
            || key.equals(PdfName.F)
            || key.equals(PdfName.BS)
            || key.equals(PdfName.AP)
            || key.equals(PdfName.AS)
            || key.equals(PdfName.Border)
            || key.equals(PdfName.C)
            || key.equals(PdfName.A)
            || key.equals(PdfName.AA)
            || key.equals(PdfName.StructParent)
            || key.equals(PdfName.OC)
            || key.equals(PdfName.H)
            || 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());

              // Add the widget to the page annotations!
              pageAnnotationsArray.add(widgetReference);
              // Add the widget to the field widgets!
              widgetsArray.add(widgetReference);
              // Associate the field to the widget!
              widgetDictionary.put(PdfName.Parent,field.getBaseObject());
            }

            // Transfer the entry from the field to the widget!
            widgetDictionary.put(key,fieldDictionary.get(key));
            fieldDictionary.remove(key);
          }
        }
      }
      setBaseObject(widgetsArray);
View Full Code Here

    // 2. Modifying the document...
    Document document = file.getDocument();
    {
      // Create the action dictionary!
      PdfDictionary action = new PdfDictionary();
      // Define the action type (in this case: go-to)!
      action.put(new PdfName("S"),new PdfName("GoTo"));
      // Defining the action destination...
      {
        // Create the destination array!
        PdfArray destination = new PdfArray();
        // Define the 2nd page as the destination target!
        destination.add(document.getPages().get(1).getBaseObject());
        // Define the location of the document window on the page (fit vertically)!
        destination.add(new PdfName("FitV"));
        // Define the window's left-edge horizontal coordinate!
        destination.add(new PdfInteger(-32768));
        // Associate the destination to the action!
        action.put(new PdfName("D"),destination);
      }
      // Associate the action to the document!
      document.getBaseDataObject().put(
        new PdfName("OpenAction"),
        file.register(action) // Adds the action to the file, returning its reference.
View Full Code Here

      NOTE: This is a factory method for any annotation-derived object.
    */
    if(baseObject == null)
      return null;

    PdfDictionary dataObject = (PdfDictionary)File.resolve(baseObject);
    if(!dataObject.get(PdfName.Type).equals(PdfName.Annot))
      return null;

    PdfName annotationType = (PdfName)dataObject.get(PdfName.Subtype);
    if(annotationType.equals(PdfName.Text))
      return new Note(baseObject,container);
    else if(annotationType.equals(PdfName.Link))
      return new Link(baseObject,container);
    else if(annotationType.equals(PdfName.FreeText))
View Full Code Here

TOP

Related Classes of org.pdfclown.objects.PdfDictionary

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.