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;
}