예제 #1
0
  /**
   * Process a content stream.
   *
   * @param contentStream the content stream
   * @throws IOException if there is an exception while processing the stream
   */
  private void processStream(PDContentStream contentStream) throws IOException {
    PDResources parent = pushResources(contentStream);
    Stack<PDGraphicsState> savedStack = saveGraphicsStack();
    Matrix parentMatrix = initialMatrix;

    // transform the CTM using the stream's matrix
    getGraphicsState().getCurrentTransformationMatrix().concatenate(contentStream.getMatrix());

    // the stream's initial matrix includes the parent CTM, e.g. this allows a scaled form
    initialMatrix = getGraphicsState().getCurrentTransformationMatrix().clone();

    // clip to bounding box
    PDRectangle bbox = contentStream.getBBox();
    clipToRect(bbox);

    // processStreamOperators(contentStream);

    initialMatrix = parentMatrix;
    restoreGraphicsStack(savedStack);
    popResources(parent);
  }
예제 #2
0
  /** Pushes the given stream's resources, returning the previous resources. */
  private PDResources pushResources(PDContentStream contentStream) {
    // resource lookup: first look for stream resources, then fallback to the current page
    PDResources parentResources = resources;
    PDResources streamResources = contentStream.getResources();
    if (streamResources != null) {
      resources = streamResources;
    } else if (resources != null) {
      // inherit directly from parent stream, this is not in the PDF spec, but the file from
      // PDFBOX-1359 does this and works in Acrobat
    } else {
      resources = currentPage.getResources();
    }

    // resources are required in PDF
    if (resources == null) {
      resources = new PDResources();
    }
    return parentResources;
  }