Exemplo n.º 1
0
  /**
   * Reads an object definition, given the first numeric object, which has already been read and is
   * passed as an argument. This is called by the no-argument readObjectDef; the only other case in
   * which it will be called is for a cross-reference stream, which can be distinguished from a
   * cross-reference table only once the first token is read.
   */
  public PdfObject readObjectDef(Numeric objNumTok) throws IOException, PdfException {
    String invDef = "Invalid object definition";
    reset();
    // The start of an object must be <num> <num> obj
    // Numeric objNumTok = (Numeric) getNext (Numeric.class, invDef);
    Numeric genNumTok = (Numeric) getNext(Numeric.class, invDef);
    Keyword objKey = (Keyword) getNext(Keyword.class, invDef);
    if (!"obj".equals(objKey.getValue())) {
      throw new PdfMalformedException(invDef);
    }
    if (_tokenizer.getWSString().length() > 1) {
      _pdfACompliant = false;
    }
    PdfObject obj = readObject();

    // Now a special-case check to read a stream object, which
    // consists of a dictionary followed by a stream token.
    if (obj instanceof PdfDictionary) {
      Stream strm = null;
      try {
        strm = (Stream) getNext(Stream.class, "");
      } catch (Exception e) {
        // if we get an exception, it just means it wasn't a stream
      }
      if (strm != null) {
        // Assimilate the dictionary and the stream token into the
        // object to be returned
        PdfStream strmObj = new PdfStream((PdfDictionary) obj, strm);
        obj = strmObj;
      }
    }

    obj.setObjNumber(objNumTok.getIntegerValue());
    obj.setGenNumber(genNumTok.getIntegerValue());
    return obj;
  }