Exemplo n.º 1
0
  private void mergePage(COSArray array, PDPage page) {
    int layoutPageNum = pageCount % layoutPages.size();
    LayoutPage layoutPage = (LayoutPage) layoutPages.get(layoutPageNum);
    PDResources resources = page.findResources();
    if (resources == null) {
      resources = new PDResources();
      page.setResources(resources);
    }
    COSDictionary docResDict = resources.getCOSDictionary();
    COSDictionary layoutResDict = layoutPage.res;
    mergeArray(COSName.PROC_SET, docResDict, layoutResDict);
    mergeDictionary(COSName.FONT, docResDict, layoutResDict, layoutPage.objectNameMap);
    mergeDictionary(COSName.XOBJECT, docResDict, layoutResDict, layoutPage.objectNameMap);
    mergeDictionary(COSName.EXT_G_STATE, docResDict, layoutResDict, layoutPage.objectNameMap);

    // we are going to wrap the existing content around some save/restore
    // graphics state, so the result is
    //
    // <save graphics state>
    // <all existing content streams>
    // <restore graphics state>
    // <overlay content>
    array.add(0, saveGraphicsStateStream);
    array.add(restoreGraphicsStateStream);
    array.add(layoutPage.contents);
  }
Exemplo n.º 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());
      }
    }
  }