Last active
December 16, 2015 13:10
-
-
Save c9katayama/bad980d6bfaf5150281d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | |
launch(args); | |
} | |
int pdfScale = 1; | |
@Override | |
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); | |
//PDFBoxでレンダリングして、BufferedImageを作成 | |
BufferedImage img = renderer.renderImage(0, pdfScale); | |
Pane pane = new Pane(); | |
//JavaFXで扱えるように、WritableImageに変換 | |
WritableImage fxImage = SwingFXUtils.toFXImage(img, null); | |
ImageView imageView = new ImageView(fxImage); | |
pane.getChildren().add(imageView); | |
Scene scene = new Scene(pane, width, height); | |
primaryStage.setTitle(getClass().getName()); | |
primaryStage.setScene(scene); | |
primaryStage.show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment