Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Simple PDF Viewer using PDFRenderer
icon1.gif  Simple PDF Viewer using PDFRenderer [message #985720] Thu, 15 November 2012 14:50 Go to previous message
James Teater is currently offline James Teater
Messages: 17
Registered: July 2011
Junior Member
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
pdfv.openFile(file);


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
 
Read Message icon1.gif
Read Message
Read Message
Read Message
Previous Topic:Integrate external application in SWT application
Next Topic:Using AWT Printing from SWT Application
Goto Forum:
  


Current Time: Thu May 23 23:35:28 EDT 2013

Powered by FUDForum. Page generated in 0.01657 seconds