Example #1
0
  /**
   * merges two arrays.
   *
   * @param dest
   * @param source
   */
  private void mergeArray(COSName name, COSDictionary dest, COSDictionary source) {
    COSArray destDict = (COSArray) dest.getDictionaryObject(name);
    COSArray sourceDict = (COSArray) source.getDictionaryObject(name);

    if (destDict == null) {
      destDict = new COSArray();
      dest.setItem(name, destDict);
    }

    for (int sourceDictIdx = 0;
        sourceDict != null && sourceDictIdx < sourceDict.size();
        sourceDictIdx++) {
      COSBase key = sourceDict.get(sourceDictIdx);
      if (key instanceof COSName) {
        COSName keyname = (COSName) key;

        boolean bFound = false;
        for (int destDictIdx = 0; destDictIdx < destDict.size(); destDictIdx++) {
          COSBase destkey = destDict.get(destDictIdx);
          if (destkey instanceof COSName) {
            COSName destkeyname = (COSName) destkey;
            if (destkeyname.equals(keyname)) {
              bFound = true;
              break;
            }
          }
        }
        if (!bFound) {
          destDict.add(keyname);
        }
      }
    }
  }
Example #2
0
  private void processPages(List pages) throws IOException {
    Iterator pageIter = pages.iterator();
    while (pageIter.hasNext()) {
      PDPage page = (PDPage) pageIter.next();
      COSDictionary pageDictionary = page.getCOSDictionary();
      COSBase contents = pageDictionary.getDictionaryObject(COSName.CONTENTS);
      if (contents instanceof COSStream) {
        COSStream contentsStream = (COSStream) contents;
        // System.err.println("stream");

        COSArray array = new COSArray();

        array.add(contentsStream);

        mergePage(array, page);

        pageDictionary.setItem(COSName.CONTENTS, array);
      } else if (contents instanceof COSArray) {
        COSArray contentsArray = (COSArray) contents;

        mergePage(contentsArray, page);
      } else {
        throw new IOException("Contents are unknown type:" + contents.getClass().getName());
      }
      pageCount++;
    }
  }
Example #3
0
  /**
   * merges two dictionaries.
   *
   * @param dest
   * @param source
   */
  private void mergeDictionary(
      COSName name, COSDictionary dest, COSDictionary source, Map objectNameMap) {
    COSDictionary destDict = (COSDictionary) dest.getDictionaryObject(name);
    COSDictionary sourceDict = (COSDictionary) source.getDictionaryObject(name);

    if (destDict == null) {
      destDict = new COSDictionary();
      dest.setItem(name, destDict);
    }
    if (sourceDict != null) {

      for (Map.Entry<COSName, COSBase> entry : sourceDict.entrySet()) {
        COSName mappedKey = (COSName) objectNameMap.get(entry.getKey().getName());
        if (mappedKey != null) {
          destDict.setItem(mappedKey, entry.getValue());
        }
      }
    }
  }