Skip to main content


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 19:50 Go to next message
James Teater is currently offline James TeaterFriend
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
Re: Simple PDF Viewer using PDFRenderer [message #985978 is a reply to message #985720] Fri, 16 November 2012 21:56 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi,

I don't know about com.sun.pdfview.PDFViewer. Are you able to write the
..pdf content to the local file system and count on the user having
Acrobat Reader installed? If so then the easiest approach would be to
invoke Acrobat Reader, which can be counted on to render it well, print
it, and provides various other PDF-viewing functionality:

Program program = Program.findProgram(".pdf");
if (program != null) {
program.launch(<thePDFsFullPath>);
}

If you really need to use PDFViewer, or anything else that's swing-based
for that matter, you need to use the SWT/AWT bridge. For examples of
this see www.eclipse.org/swt/snippets/#awt .

Grant


On 11/15/2012 2:50 PM, James Teater wrote:
> 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
Re: Simple PDF Viewer using PDFRenderer [message #986007 is a reply to message #985978] Sat, 17 November 2012 11:25 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
We are using the SWT-Browser for showing PDFs inside our app ;-)

Tom

Am 16.11.12 22:56, schrieb Grant Gayed:
> Hi,
>
> I don't know about com.sun.pdfview.PDFViewer. Are you able to write the
> .pdf content to the local file system and count on the user having
> Acrobat Reader installed? If so then the easiest approach would be to
> invoke Acrobat Reader, which can be counted on to render it well, print
> it, and provides various other PDF-viewing functionality:
>
> Program program = Program.findProgram(".pdf");
> if (program != null) {
> program.launch(<thePDFsFullPath>);
> }
>
> If you really need to use PDFViewer, or anything else that's swing-based
> for that matter, you need to use the SWT/AWT bridge. For examples of
> this see www.eclipse.org/swt/snippets/#awt .
>
> Grant
>
>
> On 11/15/2012 2:50 PM, James Teater wrote:
>> 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
>
Re: Simple PDF Viewer using PDFRenderer [message #986236 is a reply to message #986007] Mon, 19 November 2012 15:00 Go to previous message
James Teater is currently offline James TeaterFriend
Messages: 17
Registered: July 2011
Junior Member
Thanks for the reply. After much thought I think I have figured out how to make this a much simpler question. The users machines may or may not have acrobat. So I can not use that as a option. But I think my bottom line problem is the bridging. Let me try to explain.

My user clicks a SWT button to run a method that calls the printclass. The printclass is not set up like a typical SWT dialog. But has a section of code that calls a printDialog (AWT). That call is where the problem is. I have read over the bridge information. But I can not get it to work.

How do I run a new thread for the printclass operation and have it use AWT from a SWT GUI? I think that is the main problem I am having?
Previous Topic:Integrate external application in SWT application
Next Topic:Using AWT Printing from SWT Application
Goto Forum:
  


Current Time: Thu Apr 25 07:31:05 GMT 2024

Powered by FUDForum. Page generated in 0.03013 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top