2 * This file is part of NixNote/NeighborNote
\r
3 * Copyright 2009 Randy Baumgarte
\r
5 * This file may be licensed under the terms of of the
\r
6 * GNU General Public License Version 2 (the ``GPL'').
\r
8 * Software distributed under the License is distributed
\r
9 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
\r
10 * express or implied. See the GPL for the specific language
\r
11 * governing rights and limitations.
\r
13 * You should have received a copy of the GPL along with this
\r
14 * program. If not, go to http://www.gnu.org/licenses/gpl.html
\r
15 * or write to the Free Software Foundation, Inc.,
\r
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
20 package cx.fbn.nevernote.gui;
\r
22 import java.awt.image.BufferedImage;
\r
23 import java.io.File;
\r
24 import java.io.IOException;
\r
26 import javax.imageio.ImageIO;
\r
28 import org.apache.pdfbox.pdmodel.PDDocument;
\r
29 import org.apache.pdfbox.pdmodel.PDPage;
\r
31 public class PDFPreview {
\r
33 public int getPageCount(String filePath) {
\r
35 String whichOS = System.getProperty("os.name");
\r
36 if (whichOS.contains("Windows")) {
\r
37 filePath = filePath.replace("\\","/");
\r
39 PDDocument document = null;
\r
40 document = PDDocument.load( filePath );
\r
41 return document.getNumberOfPages();
\r
42 } catch (Exception e) {
\r
48 // Setup the preview for PDFs
\r
49 public boolean setupPreview(String filePath, String appl, int pageNumber) {
\r
50 // Fix stupid Windows file separation characters
\r
51 String whichOS = System.getProperty("os.name");
\r
52 if (whichOS.contains("Windows")) {
\r
53 filePath = filePath.replace("\\","/");
\r
55 if (appl.equals("pdf")) {
\r
57 PDDocument document = null;
\r
59 document = PDDocument.load( filePath );
\r
60 if (document.getNumberOfPages() <= pageNumber)
\r
62 if (document.getDocumentCatalog().getAllPages().size() <= pageNumber)
\r
64 PDPage page = (PDPage)document.getDocumentCatalog().getAllPages().get( pageNumber );
\r
65 BufferedImage bi = page.convertToImage();
\r
68 outputfile = new File(filePath +".png");
\r
69 ImageIO.write(bi, "png", outputfile);
\r
72 } catch (IOException e1) {
\r