My SWT Application allows users to create PDF files of their data. I have a table in a Results GUI that displays the successful files that has created this session. I have added 2 buttons at the bottom of the table.
button 1 = Print Selected PDF
button 2 = View Selected PDF
I have included PDFRenderer to my project.
I created 2 classes PDFPrint and PDFViewer.
PDFViewer :
I can not find any sample code on how to create a simple PDF Viewer using PDFRenderer and SWT.
This is my attempt at a simple viewer.
import java.io.File;
import java.io.IOException;
import org.eclipse.jface.window.ApplicationWindow;
import com.sun.pdfview.PDFViewer;
public class AplotPdfViewer extends ApplicationWindow {
/////////////////////////////////////////////////////////////////////////
// Constructor //
/////////////////////////////////////////////////////////////////////////
public AplotPdfViewer() {
super(null);
}
/////////////////////////////////////////////////////////////////////////
// run() //
/////////////////////////////////////////////////////////////////////////
public void run() {
File file = new File("c:\\Teamcenter\\Tc8.3\\portal\\temp\\james.pdf");
PDFViewer pdfv = new PDFViewer(true);
try {
pdfv.openFile(file) ;
}
catch (IOException e) {
e.printStackTrace();
}
pdfv.setEnabling();
pdfv.pack();
pdfv.setVisible(true);
}
}
In the GUI Dialog I am calling the class with this method
public void startPDFViewer() throws Exception {
AplotPdfViewer pdfView = new AplotPdfViewer();
pdfView.run();
}
When the view button is clicked a window opens with the words SwingLabs PDF Viewer at the top. The window is empty. Then after about 60 secs it goes unresponsive and I get the following error.
ThreadDeadlockReporter:
Swing UI Thread not responding at this line of code
I think one issue may be that the window is Swing and my Application is SWT.
It seems to be there should be more done to get the File ready before placing it in the viewer.
PDFPrint :
I can get the PDF File to print to my local default printer. But I could never figure how to get printDialog() to work. So my users could pick which printer they wanted to print to.
The main error was if printDialog() returned True a printjob would go the printer queue and complete but the printer never activated and nothing would print out. If printDialog() returned false the file would print to my default printer as desired.
I am looking for any suggestions or example code that can help me Print and View my existing PDFs using PDFRenderer in SWT.
I am not a experience coder and need any help and examples as possible.
Thanks in Advance