Link

Draw additional objects in the Java PDF Viewer

JPedals API allows you to add additional content over the rendered PDF. Unlike annotations which are added to the document, additional content is rendered on the PDF pages without altering the underlying document. Additional content can be added to the page when viewing and/or when printing, an example of everything detailed below can be found here.

Adding objects to a displayed page

The method PdfDecoder.drawAdditionalObjectsOverPage(int page, int[] type, Color[] colors, Object[] obj) allows you to specify additional content to be drawn on the displayed page. This method accepts a page number to add the content to and 3 arrays that will hold the content information (described below).

Adding objects to a printed page

The method PdfDecoder.printAdditionalObjectsOverPage(int page, int[] type, Color[] colors, Object[] obj) allows you to specify additional content to be drawn on the displayed page. This method accepts a page number to add the content to and 3 arrays that will hold the content information (described below). In addition to this there is also a method that allows you to print a set of content over all pages called PdfDecoder.printAdditionalObjectsOverAllPages(int[] type, Color[] colors, Object[] obj).

Creating Additional Content

The additional content that can be added comes in several types, each requiring a different type f object to be provided. When specifying additional content you will provide an int, Color object, and an Object to the arrays you provide.

  • Fill Opacity

    • Type: DynamicVectorRenderer.FILLOPACITY
    • Color: Null as the value is not used
    • Object: A Float specifying the opacity where 1 is fully opaque and 0 is transparent
  • Stroke Opacity

    • Type: DynamicVectorRenderer.STROKEOPACITY
    • Color: Null as the value is not used
    • Object: A Float specifying the opacity where 1 is fully opaque and 0 is transparent
  • Stroked Shape

    • Type: DynamicVectorRenderer.STROKEDSHAPE
    • Color: Color object specifying the color to stroke the shape
    • Object: A Shape object to be stroked.
  • Filled Shape

    • Type: DynamicVectorRenderer.FILLEDSHAPE
    • Color: Color object specifying the color to fill the shape
    • Object: A Shape object to be stroked.
  • Image

    • Type: DynamicVectorRenderer.IMAGE
    • Color: Null as the value is not used
    • Object: An ImageObject containing the image to add and its location
  • String

    • Type: DynamicVectorRenderer.STRING
    • Color: Color object specifying the color for the text
    • Object: An TextObject containing the image to add, its font, and its location
  • Custom Objects

    • Type: DynamicVectorRenderer.CUSTOM
    • Color: Null as the value is not used
    • Object: Any object that implements JPedalCustomDrawObject. This allows you to add any content you wish.
      Note: In certain cases, a PDF file can have a clip set on it, in which case some custom objects may not be visible. We suggest setting the clip to null before any additional objects are drawn.

Removing objects from a displayed page

The method PdfDecoder.flushAdditionalObjectsOnPage(int page) removes all additional content from the specified page. When the page is next drawn the content will not longer be present.