Display a PDF viewer.

Method Signatures and Parameters

Jt.pdf(String url)

url (String)

A URL for a hosted PDF, or a path to a PDF in the static folder.

Jt.pdf(byte[] data)

data (byte[])

Raw PDF data.

Jt.pdf(java.nio.file.Path filePath)

filePath (java.nio.file.Path)

A path to a local PDF file. The path can be absolute or relative to the working directory.

Jt.pdf(JtUploadedFile uploadedFile)

uploadedFile (io.javelit.core.JtUploadedFile)

An uploaded PDF file from #fileUploader

Chainable builder methods

height(String height)

The height of the PDF viewer element. This can be one of the following:

  • stretch: The height of the element matches the height of its content or the height of the parent container, whichever is larger. If the element is not in a parent container, the height of the element matches the height of its content.
  • An integer specifying the height in pixels (default: 500): The element has a fixed height.

height(int heightPixels)

The height of the element in pixels. The element will have a fixed height.

key(String key)

A string to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. No two widgets may have the same key.

Only applies to input widgets that have a provided .key(). Disable the persistence of this widget value across runs where the widget does not appear.

use()

Put the widget in the app, in the MAIN container.

use(JtContainer container)

Put the widget in the app, in the provided container.

Examples

Display PDF from URL

import io.javelit.core.Jt;

public class PdfApp {
  public static void main(String[] args) {
    Jt.pdf("https://cdn.jsdelivr.net/gh/javelit/public_assets@main/pdf/dummy.pdf").use();
  }
}

PDF from raw data



import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import io.javelit.core.Jt;

public class BytePdfApp {
  public static void main(String[] args) throws IOException {
    byte[] pdfBytes = Files.readAllBytes(Path.of("document.pdf"));
    Jt.pdf(pdfBytes).use();
  }
}

PDF from local file

import java.nio.file.Path;

import io.javelit.core.Jt;

public class FilePdfApp {
  public static void main(String[] args) {
    // assumes document.pdf is present in the working directory
    Jt.pdf(Path.of("document.pdf")).use();
  }
}

forum

Still have questions?

Go to our discussions forum for helpful information and advice from Javelit experts.