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 17:18
James Teater is currently offline James Teater
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 Jul 24 04:26:38 EDT 2014

Powered by FUDForum. Page generated in 0.01734 seconds