Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Disabling the tool bar in a PDFViewer (PDFRenderer)
icon7.gif  Disabling the tool bar in a PDFViewer (PDFRenderer) [message #987755] Tue, 27 November 2012 22:18
James Teater is currently offline James TeaterFriend
Messages: 17
Registered: July 2011
Junior Member
I am using the class PDFViewer (PDFRenderer) to display a read only view of a PDF File. All I really want is a simple dialog with the PDF File displayed. Plus a way to close the dialog.

I am hoping there is a way to either remove or disable the menu items in the toolbar. Even if I can remove or disable the print option and the full screen option. That would be a great help.

This is the very simple code I am using to open the Viewer.

public void actionPerformed(ActionEvent actionevent) {
        File file = new File(fileName);
        PDFViewer pdfv = new PDFViewer(false);
        try {
           pdfv.openFile(file) ;
        }
        catch (IOException e) {
           e.printStackTrace();
        }

     }
  });


Also do I need to close or dispose the viewer from my code? Right now when I close the viewer using the red X, it closes my main application.

This is the complete method

protected Control startPDFPrint(Composite parent) {
      final Composite swtAwtComponent = new Composite(parent, SWT.EMBEDDED);
      final java.awt.Frame frame = SWT_AWT.new_Frame( swtAwtComponent );
      final javax.swing.JPanel panel = new javax.swing.JPanel( );
      frame.add(panel);
                 
      JButton swingButton = new JButton("Print PDF");
      panel.add(swingButton);
      swingButton.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent actionevent) {
            try {
               File file = new File(userSelectedFile);
               FileInputStream fis = new FileInputStream(file);
               FileChannel fc = fis.getChannel();
               ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
                             
               pdfFile = new PDFFile(bb); 
               pages = new PDFPrintPage(pdfFile);
               
               PrinterJob pjob = PrinterJob.getPrinterJob();
               PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
               PageFormat pfDefault = pjob.pageDialog(aset);
               pjob.setJobName(file.getName());
              
               if (pjob.printDialog(aset)) {
                  pfDefault = pjob.validatePage(pfDefault);
                  Book book = new Book();
                  book.append(pages, pfDefault, pdfFile.getNumPages());
                  pjob.setPageable(book);
                  try {
                     pjob.print(aset);     
                  }
                  catch (PrinterException exc) {
                    System.out.println(exc);
                  }
               }
            }
            catch (IOException e) {
               e.printStackTrace();
            }
         }
      });
      
      JButton viewerButton = new JButton("View PDF");
      panel.add(viewerButton);
      viewerButton.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent actionevent) {
            File viewerFile = new File(userSelectedFile);
            PDFViewer pdfv = new PDFViewer(false);
            
            try {
                pdfv.openFile(viewerFile);
               
            }
            catch (IOException e) {
               e.printStackTrace();
            }
         
         }
      });
      return swtAwtComponent;
   }


Thanks for any help you can give me!!!
Previous Topic:Make table editor behave more like Excel?
Next Topic:visible children of ScrolledComposite
Goto Forum:
  


Current Time: Thu Apr 25 09:26:10 GMT 2024

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

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

Back to the top