Overview

Previews are calculated in Java from the PDF generated by the native renderer. As other structured document information, previews can be requested from the DocumentMetadata object connected to a OpenedDocument.

We use the apache pdf box library to calculate previews from an existing PDF. At the time, only JPEG previews are supported: all previews returned from metadata (as byte array or DataHandler) are JPEG images.

Spread Previews

String w2mlString = "";
try (OpenedDocument document = ((Renderer) renderer).openDocument(
          "DSN", 
          new TmpCopyFromString(w2mlString, W2MLDocumentType.class))) {
  DocumentMetadata metadata = document.getMetadata();
  // preview of first spread:
  byte[] spreadPreview = metadata.getPreview(0);
}
catch (RendererException e) {
} 
catch (Exception e) {
}

Previews can also be requested in other resolutions:

  // get preview in screen / web resolution:
  byte[] spreadPreview = metadata.getPreview(0, 72.0);

Note: The default preview resolution is 300.0dpi. Previews are always calculated in 300.0dpi in the first step, if you request another resolution, the result is resampled from the original preview.

Previews of CometGroups

DocumentMetadata.getCometGroupPreviews calculates the boundings of the given CometGroups and returns one or several previews for the calculated clippings. Since parts of the CometGroups can be located on several spreads, we retrieve an array of previews:

String w2mlString = "";
int cometGroupId = 123;
try (OpenedDocument document = ((Renderer) renderer).openDocument(
                      "DSN",
                      new TmpCopyFromString(w2mlString, W2MLDocumentType.class))) {
  DocumentMetadata metadata = document.getMetadata();
  // comet group parts can be located on several spreads,
  // so we retrieve an ARRAY of previews.
  DataHandler[] groupPreviews = metadata.getCometGroupPreviews(cometGroupId);
  if (groupPreviews != null && groupPreviews.length > 0) {
    // typically, we are interested in the first preview only:
   DataHandler mainPreview = groupPreviews[0];
   // ...
  }
}
catch (RendererException e) {
} 
catch (Exception e) {
}

Previews of Clippings

Previews of clippings can simply be requested by providing the left / top coordinates and width and height of the clipping:

String w2mlString = "";
try (OpenedDocument document = ((Renderer) renderer).openDocument(
                                "DSN",
                                new TmpCopyFromString(w2mlString))) {
  DocumentMetadata metadata = document.getMetadata();
  DataHandler preview = metadata.getPreviewOfClipping(
                        0,    // spread index 
                        0.0,  // left
                        0.0,  // top
                        50.0, // width
                        50.0, // height
                        90.0  // resolution
                        );
}
catch (RendererException e) {
} 
catch (Exception e) {
}