예제 #1
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++;
    }
  }
예제 #2
0
  private void collectLayoutPages(List pages) throws IOException {
    Iterator pagesIter = pages.iterator();
    while (pagesIter.hasNext()) {
      PDPage page = (PDPage) pagesIter.next();
      COSBase contents = page.getCOSDictionary().getDictionaryObject(COSName.CONTENTS);
      PDResources resources = page.findResources();
      if (resources == null) {
        resources = new PDResources();
        page.setResources(resources);
      }
      COSDictionary res = resources.getCOSDictionary();

      if (contents instanceof COSStream) {
        COSStream stream = (COSStream) contents;
        Map objectNameMap = new TreeMap();
        stream = makeUniqObjectNames(objectNameMap, stream);

        layoutPages.add(new LayoutPage(stream, res, objectNameMap));
      } else if (contents instanceof COSArray) {
        throw new UnsupportedOperationException(
            "Layout pages with COSArray currently not supported.");
        // layoutPages.add(new LayoutPage(contents, res));
      } else {
        throw new IOException("Contents are unknown type:" + contents.getClass().getName());
      }
    }
  }