Jump to content
Changes to the Jaspersoft community edition download ×

convert byte into pdf format in swing client


Recommended Posts

Hi all experts,


is anybody know how to convert the jasper report from byte into pdf format? I manage to generate the pdf report and save in server.. however, when pass to frontend / network rite, it automatically convert the pdf to byte. thus, in order the swing client can download the report in pdf format and save the report into local, i need to convert back the byte to pdf..


currently, the technologies dat im using are EJB3, Swing and jBoss(App Server).


Any help would be highly appreciated.

Thanks in advance..

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic



PDF is a binary format. Those bytes you get on the client side are PDF. I don't understand what conversion do you want to do on them.

If you would save those bytes in a file with the *.pdf extension, you could open it with Acrobat.


I hope this hepls.


Link to comment
Share on other sites

hi teodord,


really thank for your reply again. Yes i save those file with the *.pdf extention.


Below is my code:


public void generatePdfReport(String jasperFileName, String pdfFileName, Map parameters){


Connection conn = null;


try {


DataSource dataSource = ServiceLocator.getInstance().getDataSource("java:DBSERVER");


conn = dataSource.getConnection();


File reportFile = new File(jasperFileName);


byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters, conn);


ByteBuffer buf = ByteBuffer.wrap(bytes);


File file = new File(pdfFileName);

boolean append = false;



FileChannel wChannel = new FileOutputStream(file, append).getChannel();









So if my client want to retrive the pdf file in swing right, is it i just need to return the byte[] and my client could open it with acrobat already? or i still need to call the exportReportToPdf(JasperPrint arg 0) method?



Thanks in advance...

Link to comment
Share on other sites



As I said, there are several ways to do it and it only depends on your client/server type of communication.

You did not give us any details about how your Swing client communicates with the server. Through HTTP? RMI?


Depending on how you want it to work, you could either send PDF byte content to the client or you could send the JasperPrint object. If you send the JasperPrint, the client itself could perform the PDF export locally, using JR again. Or you could even display the report in Swing using the JR viewer, without the need to export it to PDF and open Acrobat.


There are several solutions and it all depends on what you want to do and what architecture you have. You ask us about how to work with binary content and stuff, but you would rather have to clarify how your Swing client talks to your server and what kind of protocol they use and what data they exchange.


I hope this helps.


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...