Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import java.awt.image.BufferedImage;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;
import javafx.application.Application;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class PDFImageViewer extends Application {
public static void main(String[] args) {
int pdfScale = 1;
public void start(Stage primaryStage) throws Exception {
int width = 590;
int height = 840;
PDDocument doc = PDDocument.load(PDFImageViewer.class.getResourceAsStream("sample.pdf"));
PDFRenderer renderer = new PDFRenderer(doc);
BufferedImage img = renderer.renderImage(0, pdfScale);
Pane pane = new Pane();
WritableImage fxImage = SwingFXUtils.toFXImage(img, null);
ImageView imageView = new ImageView(fxImage);
Scene scene = new Scene(pane, width, height);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.