Ejemplo n.º 1
0
 /**
  * Translate a PRIndirectReference to a PdfIndirectReference In addition, translates the object
  * numbers, and copies the referenced object to the output file. NB: PRIndirectReferences (and
  * PRIndirectObjects) really need to know what file they came from, because each file has its own
  * namespace. The translation we do from their namespace to ours is *at best* heuristic, and
  * guaranteed to fail under some circumstances.
  */
 protected PdfIndirectReference copyIndirect(PRIndirectReference in)
     throws IOException, BadPdfFormatException {
   PdfIndirectReference theRef;
   RefKey key = new RefKey(in);
   IndirectReferences iRef = (IndirectReferences) indirects.get(key);
   if (iRef != null) {
     theRef = iRef.getRef();
     if (iRef.getCopied()) {
       return theRef;
     }
   } else {
     theRef = body.getPdfIndirectReference();
     iRef = new IndirectReferences(theRef);
     indirects.put(key, iRef);
   }
   PdfObject obj = PdfReader.getPdfObjectRelease(in);
   if (obj != null && obj.isDictionary()) {
     PdfObject type = PdfReader.getPdfObjectRelease(((PdfDictionary) obj).get(PdfName.TYPE));
     if (type != null && PdfName.PAGE.equals(type)) {
       return theRef;
     }
   }
   iRef.setCopied();
   obj = copyObject(obj);
   addToBody(obj, theRef);
   return theRef;
 }
Ejemplo n.º 2
0
  /**
   * Add an imported page to our output
   *
   * @param iPage an imported page
   * @throws IOException , BadPdfFormatException
   */
  public void addPage(PdfImportedPage iPage) throws IOException, BadPdfFormatException {
    int pageNum = setFromIPage(iPage);

    PdfDictionary thePage = reader.getPageN(pageNum);
    PRIndirectReference origRef = reader.getPageOrigRef(pageNum);
    reader.releasePage(pageNum);
    RefKey key = new RefKey(origRef);
    PdfIndirectReference pageRef;
    IndirectReferences iRef = (IndirectReferences) indirects.get(key);
    if (iRef != null && !iRef.getCopied()) {
      pageReferences.add(iRef.getRef());
      iRef.setCopied();
    }
    pageRef = getCurrentPage();
    if (iRef == null) {
      iRef = new IndirectReferences(pageRef);
      indirects.put(key, iRef);
    }
    iRef.setCopied();
    PdfDictionary newPage = copyDictionary(thePage);
    root.addPage(newPage);
    ++currentPageNumber;
  }
Ejemplo n.º 3
0
  /**
   * Copy the acroform for an input document. Note that you can only have one, we make no effort to
   * merge them.
   *
   * @param reader The reader of the input file that is being copied
   * @throws IOException , BadPdfFormatException
   */
  public void copyAcroForm(PdfReader reader) throws IOException, BadPdfFormatException {
    setFromReader(reader);

    PdfDictionary catalog = reader.getCatalog();
    PRIndirectReference hisRef = null;
    PdfObject o = catalog.get(PdfName.ACROFORM);
    if (o != null && o.type() == PdfObject.INDIRECT) hisRef = (PRIndirectReference) o;
    if (hisRef == null) return; // bugfix by John Englar
    RefKey key = new RefKey(hisRef);
    PdfIndirectReference myRef;
    IndirectReferences iRef = (IndirectReferences) indirects.get(key);
    if (iRef != null) {
      acroForm = myRef = iRef.getRef();
    } else {
      acroForm = myRef = body.getPdfIndirectReference();
      iRef = new IndirectReferences(myRef);
      indirects.put(key, iRef);
    }
    if (!iRef.getCopied()) {
      iRef.setCopied();
      PdfDictionary theForm = copyDictionary((PdfDictionary) PdfReader.getPdfObject(hisRef));
      addToBody(theForm, myRef);
    }
  }