/*
* Copyright (c) 1997-2019 IDRsolutions (https://www.idrsolutions.com)
*/
package org.jpedal.examples.samples;
import org.jpedal.examples.viewer.Viewer;
import java.io.File;
import java.io.InputStream;
@SuppressWarnings({"unused", "ClassOnlyUsedInOnePackage"})
public class OpenViewer {
/**
* example showing how to programmatically open a file
*/
public OpenViewer() {
//create and initialise JPedal viewer component
final Viewer myViewer = new Viewer();
myViewer.setupViewer();
//code to open when required
final File file = null; //example is commented out below
final 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);
//list of features at this URL http://www.idrsolutions.com/access-pdf-viewer-features-from-your-code/
//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://my.site.org/PDF3.pdf"});
}
/**/
//myViewer.dispose(); // only use at end of usage (and not generally needed)
}
public static void main(final String[] args) {
new OpenViewer();
}
}
|