Link to home
Create AccountLog in
Avatar of jkteater
jkteaterFlag for United States of America

asked on

Java Application Using SWT - PDF Printing

I have a Java application that is built of SWT.  In my application I allow my users to create a PDF File from their selected data.  This all works great.  Now I need some way to allow the users to Print out the PDF.  I have looked at so much open source PDF projects.

SWT PrintDialog
PDFRenderer
ICEpdf
jPodRender

I can not figure out how to make any of them work.  Right now I am trying to use PDFRenderer in my code.  Seems like PDFRenderer likes AWT/SWING, but I can not figure out how to Bridge SWT and SWING.  I have read over the tutorial on how to do it a couple of times with no luck.  

Main GUI SWT Dialog
   Component - Print Button
       new PrintClass().printFile(String Filename);

Print Class
      open a printDialog for printer selection - which is AWT
           system goes unresponsive with Thread error

Not sure how to fix it.  Should the whole method printFile be a component?
Is there a way to run the printFile on its own thread indepentent of the parent SWT Dialog?

This is a example of all I need for this issue to me resolved.

User selects a PDF Filename from my TableViewer - Done
User clicks a Print selected PDF button at the bottom of the table - Done
A Print Dialog opens - ?
The user is allowed to select a local printer and select printer attributes(copies) - ?
Then the printer prints the selected PDF File?

I have coded such much incomplete code, I have gotten lost.  

Can someone please, please help me with this.  I need to have this working soon and I am not finding much help.  

If you had a SWT application and needed to print existing PDF Files to a local printer -
How would you do it?????

Please show any example code you can
ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of jkteater

ASKER

Yes - I do like the SWT PrintDialog.
But I have not Idea how to print a Existing PDF File using the dialog.  I have goggled and goggled looking for code to show me how to do it.
You need to open the PDF first and then you print it through the print dialogue:

http://stackoverflow.com/questions/4437910/java-pdf-viewer
I would much appreciate it, if you could show or direct me to a example of code.

Thanks Very Much
I am not sure how you can do it, I have never used SWT so I am not familiar with the graphic components SWT uses. But there is a project that you can use and integrate it with your own application, if you have a look at the source code you can take some ideas:

http://www.eclipse4you.com/?q=en/eclipse_plugins/nightlabs_pdf_viewer_screenshot 
http://www.java2s.com/Open-Source/Java/ERP-CRM-Financial/JFire-1.0.1/org/nightlabs/eclipse/ui/pdfviewer/PdfViewer.java.htm

(you will have to download the library in order to run the example on the second link)