List of usage examples for org.apache.pdfbox.rendering PDFRenderer PDFRenderer
public PDFRenderer(PDDocument document)
From source file:view.ImagePanel.java
License:Open Source License
public void setDocumentAndComponents(final MainWindow mainWindow, JScrollPane parent, Document document, final JButton btnBackward, final JButton btnForward) { this.mainWindow = mainWindow; this.parent = parent; try {//from w ww. ja v a 2s .c o m this.documentLocation = document.getDocumentLocation(); this.pdfDocument = PDDocument.load(new File(documentLocation)); this.pdfRenderer = new PDFRenderer(pdfDocument); numberOfPages = pdfDocument.getPages().getCount(); if (buf != null) { buf.flush(); buf = null; } System.gc(); Runnable r = new Runnable() { @Override public void run() { status = Status.RENDERING; ImagePanel.this.btnPageBackward = btnBackward; ImagePanel.this.btnPageForward = btnForward; ImagePanel.this.pageNumber = 0; ImagePanel.this.scale = 1f; ImagePanel.this.svList = null; setBorder(null); JLabel lblDocName = new JLabel(documentLocation); lblDocName.setLocation(0, 0); add(lblDocName); lblDocName.setVisible(true); try { buf = pdfRenderer.renderImage(0, 2f, ImageType.RGB); mainWindow.getWorkspacePanel().showPanelComponents(); status = Status.READY; } catch (IOException ex) { return; } refreshParent(); refreshTitle(); } }; Thread t = new Thread(r); t.start(); if (pdfDocument == null) { mainWindow.getWorkspacePanel().setDocument(null); return; } } catch (IOException ex) { controller.Logger.getLogger().addEntry(ex); } }