package org.jpedal.examples.samples;
import org.jpedal.examples.simpleviewer.Commands;
import org.jpedal.examples.simpleviewer.SimpleViewer;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
/**
* ===========================================
* Java Pdf Extraction Decoding Access Library
* ===========================================
*
* Project Info: http://www.jpedal.org
*
* (C) Copyright 2010, IDRsolutions and Contributors.
*
* This file is part of JPedal
*
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ---------------
* org.jpedal.examples.samples.OpenViewer.java
* ---------------
* (C) Copyright 2010, by IDRsolutions and Contributors.
*
*
* --------------------------
*/
public class OpenViewer {
/**
* exmaple showing how to programatically open a file
*/
public OpenViewer() {
//create and initialise JPedal viewer component
SimpleViewer myViewer =new SimpleViewer();
myViewer.setupViewer();
//code to open when required
File file=null; //example is commented out below
InputStream stream = null;
//open the stream or File
try {
//file = new File("/Users/markee/Desktop/myfile.pdf");
// stream = new FileInputStream("/Users/markee/Desktop/PDF3.pdf");
//stream = new FileInputStream("/Users/markee/Desktop/test.pdf");
} catch (Exception e) {
e.printStackTrace();
}
//debug code
//LogWriter.log_name="/Users/markee/Desktop/log.txt";
//LogWriter.setupLogFile(true,0,"1.0","v",false);
//open the PDF (if linear display first page asap and allow access to other objects)
if(stream !=null)
myViewer.executeCommand(Commands.OPENFILE, new Object[]{stream});
if(file!=null)
myViewer.executeCommand(Commands.OPENFILE, new Object[]{file});
//url case
if(stream==null)
myViewer.executeCommand(Commands.OPENURL, new Object[]{"http://www.jpedal.org/PDF3.pdf"});
}
public static void main(String[] args) {
new OpenViewer();
}
}
|