PDF.js

The PDF.js module integrates with the Wicket Viewer, rendering a Blob property containing a PDF using the PDF.js library.

Setup

Dependency Management

In your application’s top level pom.xml, add a dependency for this module’s own bill of materials (BOM):

pom.xml
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.apache.causeway.extensions</groupId>
            <artifactId>causeway-extensions-pdfjs</artifactId>
            <scope>import</scope>
            <type>pom</type>
            <version>2.1.0</version>
        </dependency>
    </dependencies>
</dependencyManagement>

Dependencies / Imports

In those modules where there are domain objects with Blob properties containing PDF data, add a dependency/import to the applib module:

  • add this dependency:

    pom.xml
    <dependencies>
        <dependency>
            <groupId>org.apache.causeway.extensions</groupId>
            <artifactId>causeway-extensions-pdfjs-applib</artifactId>
        </dependency>
    </dependencies>
  • and @Import this module:

    MyModule.java
    @Configuration
    @Import({
        CausewayModuleExtPdfjsApplib.class,
        // ...
    })
    public class MyModule { ... }

In addition, in the webapp module of your application, add the following dependency:

pom.xml
<dependency>
    <groupId>org.apache.causeway.extensions</groupId>
    <artifactId>causeway-extensions-pdfjs-wicket-ui</artifactId>
</dependency>

And in your application’s App Manifest, import the extension’s implementation module:

AppManifest.java
@Configuration
@Import({
        CausewayModuleExtPdfjsWicketUi.class,
        ...
})
public class AppManifest {
}

Usage

To use the extension, annotate an Blob property with the @PdfJsViewer annotation.

For example:

@PdfJsViewer            (1)
@Property()
@PropertyLayout(fieldSetId = "content", sequence = "1")
public Blob getAttachment() { ... }
1 indicates that the Blob returns a set of bytes that correspond to a PDF, and so should be rendered as such.
The Blob is expected also to have a mime type of application/pdf.

Optionally, you can also provide an implementation of the PdfJsViewerAdvisor SPI, which advises on the size of the viewer (and has callbacks to keep track of which page of the PDF is being viewed). The framework provides a fallback implementation that sets the height to 800px, and scaled to 75% normal size.