Package org.pdfclown.objects

Examples of org.pdfclown.objects.PdfDictionary


              );
          }
        }
        else if(operand instanceof PdfDictionary)
        {
          PdfDictionary operandEntries = (PdfDictionary)operand;
          int operandEntryIndex = -1;
          for(Map.Entry<PdfName,PdfDirectObject> operandEntry : operandEntries.entrySet())
          {
            model.addRow(
              new Object[]
              {
                "(operand " + index + "." + (++operandEntryIndex) + ") " + operandEntry.getKey().toString(),
View Full Code Here


    )
  {
    if(baseObject == null)
      return null;

    PdfDictionary dataObject = (PdfDictionary)File.resolve(baseObject);
    PdfName actionType = (PdfName)dataObject.get(PdfName.S);
    if(actionType == null
      || (dataObject.containsKey(PdfName.Type)
          && !dataObject.get(PdfName.Type).equals(PdfName.Action)))
      return null;

    if(actionType.equals(PdfName.GoTo))
      return new GoToLocal(baseObject,container);
    else if(actionType.equals(PdfName.GoToR))
      return new GoToRemote(baseObject,container);
    else if(actionType.equals(PdfName.GoToE))
      return new GoToEmbedded(baseObject,container);
    else if(actionType.equals(PdfName.Launch))
      return new Launch(baseObject,container);
    else if(actionType.equals(PdfName.Thread))
      return new GoToThread(baseObject,container);
    else if(actionType.equals(PdfName.URI))
      return new GoToURI(baseObject,container);
    else if(actionType.equals(PdfName.Sound))
      return new PlaySound(baseObject,container);
    else if(actionType.equals(PdfName.Movie))
      return new PlayMovie(baseObject,container);
    else if(actionType.equals(PdfName.Hide))
      return new ToggleVisibility(baseObject,container);
    else if(actionType.equals(PdfName.Named))
    {
      PdfName actionName = (PdfName)dataObject.get(PdfName.N);
      if(actionName.equals(PdfName.NextPage))
        return new GoToNextPage(baseObject,container);
      else if(actionName.equals(PdfName.PrevPage))
        return new GoToPreviousPage(baseObject,container);
      else if(actionName.equals(PdfName.FirstPage))
View Full Code Here

    PdfName actionType
    )
  {
    super(
      context.getFile(),
      new PdfDictionary(
        new PdfName[]
        {
          PdfName.Type,
          PdfName.S
        },
View Full Code Here

      body.append(dataBuffer);
    }

    // 2. Header.
    {
      final PdfDictionary header = getHeader();
      header.put(
        PdfName.N,
        new PdfInteger(getEntries().size())
        );
      header.put(
        PdfName.First,
        new PdfInteger(dataByteOffset)
        );
    }
  }
View Full Code Here

      TargetObject target
      )
    {
      super(
        context.getFile(),
        new PdfDictionary()
        );

      setRelation(relation);
      setEmbeddedFileName(embeddedFileName);
      setAnnotationPageRef(annotationPageRef);
View Full Code Here

        case Literal:
          return new PdfTextString(
            Encoding.encode((String)token)
            );
        case DictionaryBegin:
          PdfDictionary dictionary = new PdfDictionary();
          while(true)
          {
            // Key.
            moveNext(); if(tokenType == TokenTypeEnum.DictionaryEnd) break;
            PdfName key = (PdfName)parsePdfObject();
            // Value.
            moveNext();
            PdfDirectObject value = (PdfDirectObject)parsePdfObject();
            // Add the current entry to the dictionary!
            dictionary.put(key,value);
          }

          int oldOffset = (int)stream.getPosition();
          moveNext();
          // Is this dictionary the header of a stream object [PDF:1.6:3.2.7]?
          if((tokenType == TokenTypeEnum.Keyword)
            && token.equals(Keyword.BeginStream)) // Stream.
          {
            // Keep track of current position!
            long position = stream.getPosition();

            // Get the stream length!
            /*
              NOTE: Indirect reference resolution is an outbound call (stream pointer hazard!),
              so we need to recover our current position after it returns.
            */
            int length = ((PdfInteger)File.resolve(dictionary.get(PdfName.Length))).getRawValue();

            // Move to the stream data beginning!
            stream.seek(position); skipEOL();

            // Copy the stream data to the instance!
            byte[] data = new byte[length];
            try
            {stream.read(data);}
            catch(EOFException e)
            {throw new FileFormatException("Unexpected EOF (malformed stream object).",e,stream.getPosition());}

            moveNext(); // Postcondition (last token should be 'endstream' keyword).

            Object streamType = dictionary.get(PdfName.Type);
            if(PdfName.ObjStm.equals(streamType)) // Object stream [PDF:1.6:3.4.6].
              return new ObjectStream(
                dictionary,
                new Buffer(data),
                file
View Full Code Here

      // Get the data object associated to the indirect object!
      PdfDataObject dataObject = indirectObject.getDataObject();
      // Is this data object a stream?
      if(dataObject instanceof PdfStream)
      {
        PdfDictionary header = ((PdfStream)dataObject).getHeader();
        // Is this stream an image?
        if(header.containsKey(PdfName.Type)
          && header.get(PdfName.Type).equals(PdfName.XObject)
          && header.get(PdfName.Subtype).equals(PdfName.Image))
        {
          // Which kind of image?
          if(header.get(PdfName.Filter).equals(PdfName.DCTDecode)) // JPEG image.
          {
            // Get the image data (keeping it encoded)!
            IBuffer body = ((PdfStream)dataObject).getBody(false);
            // Export the image!
            exportImage(
              body,
              getOutputPath() + java.io.File.separator + "ImageExtractionSample_" + (index++) + ".jpg"
              );
          }
          else // Unsupported image.
          {System.out.println("Image XObject " + indirectObject.getReference() + " couldn't be extracted (filter: " + header.get(PdfName.Filter) + ")");}
        }
      }
    }
   
    return true;
View Full Code Here

  public XRefStream(
    File file
    )
  {
    this(
      new PdfDictionary(
        new PdfName[]
          {PdfName.Type},
        new PdfDirectObject[]
          {PdfName.XRef}
        ),
      new Buffer(),
      file
      );
    PdfDictionary header = getHeader();
    for(Entry<PdfName,PdfDirectObject> entry : file.getTrailer().entrySet())
    {
      PdfName key = entry.getKey();
      if(key.equals(PdfName.Root)
        || key.equals(PdfName.Info)
        || key.equals(PdfName.ID))
      {header.put(key,entry.getValue());}
    }
  }
View Full Code Here

      indexArray.add(new PdfInteger(prevObjectNumber-((PdfInteger)indexArray.get(indexArray.size()-1)).getValue()+1)); // Number of entries in the previous subsection.
    }

    // 2. Header.
    {
      final PdfDictionary header = getHeader();
      header.put(
        PdfName.Index,
        indexArray
        );
      header.put(
        PdfName.Size,
        new PdfInteger(file.getIndirectObjects().size()+1)
        );
      header.put(
        PdfName.W,
        new PdfArray(
          new PdfInteger(entryFieldSizes[0]),
          new PdfInteger(entryFieldSizes[1]),
          new PdfInteger(entryFieldSizes[2])
View Full Code Here

      entries = new TreeMap<Integer,XRefEntry>();

      final IBuffer body = getBody();
      if(body.getLength() > 0)
      {
        final PdfDictionary header = getHeader();
        final int size = ((PdfInteger)header.get(PdfName.Size)).getValue();
        final int[] entryFieldSizes;
        {
          final PdfArray entryFieldSizesObject = (PdfArray)header.get(PdfName.W);
          entryFieldSizes = new int[entryFieldSizesObject.size()];
          for(int index = 0, length = entryFieldSizes.length; index < length; index++)
          {entryFieldSizes[index] = ((PdfInteger)entryFieldSizesObject.get(index)).getValue();}
        }

        final PdfArray subsectionBounds;
        if(header.containsKey(PdfName.Index))
        {subsectionBounds = (PdfArray)header.get(PdfName.Index);}
        else
        {
          subsectionBounds = new PdfArray();
          subsectionBounds.add(new PdfInteger(0));
          subsectionBounds.add(new PdfInteger(size));
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.