PDF files

R

Raspberry

Hi,
I'm a beginner java developer, and I'm developing a desktop
application, it contains form generate reports for user in pdf format
and save it in temporary file.
when user view the archived report, he could save it in another path
(for example: myDocuments)... but the new saved file is empty except
from a logo
this is the code to save the pdf ... can anybody help my to find the
problem? thanx in advance

public void export(){
Properties m_ctx=Env.getCtx();
JFileChooser chooser = new JFileChooser();
chooser.setDialogType(JFileChooser.SAVE_DIALOG);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setDialogTitle(Msg.getMsg(Env.getCtx(), "Export"));
chooser.addChoosableFileFilter(new
ExtensionFileFilter("pdf" ,Msg.getMsg(m_ctx, "FilePDF")));

if(chooser.showSaveDialog(this)!= JFileChooser.APPROVE_OPTION)
return;

File file =
ExtensionFileFilter.getFile(chooser.getSelectedFile(),
chooser.getFileFilter());
Viewer viewer = new Viewer();
try{
PDFGenerator.getPDFAsStream(new
FileOutputStream(file),layoutEngine.getPageable(false));
file.createNewFile();

}catch(Exception e){
e.printStackTrace();
}
 
R

rossum

Hi,
I'm a beginner java developer, and I'm developing a desktop
application, it contains form generate reports for user in pdf format
and save it in temporary file.
when user view the archived report, he could save it in another path
(for example: myDocuments)... but the new saved file is empty except
from a logo
this is the code to save the pdf ... can anybody help my to find the
problem? thanx in advance

public void export(){
Properties m_ctx=Env.getCtx();
JFileChooser chooser = new JFileChooser();
chooser.setDialogType(JFileChooser.SAVE_DIALOG);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setDialogTitle(Msg.getMsg(Env.getCtx(), "Export"));
chooser.addChoosableFileFilter(new
ExtensionFileFilter("pdf" ,Msg.getMsg(m_ctx, "FilePDF")));

if(chooser.showSaveDialog(this)!= JFileChooser.APPROVE_OPTION)
return;

File file =
ExtensionFileFilter.getFile(chooser.getSelectedFile(),
chooser.getFileFilter());
Viewer viewer = new Viewer();
try{
PDFGenerator.getPDFAsStream(new
FileOutputStream(file),layoutEngine.getPageable(false));
file.createNewFile();
The documentation for createNewFile says: "creates a new, empty file".
Is that "empty" the source of your problem? After you create it you
seem to exit your method without having put anything into the file.

rossum
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,470
Messages
2,571,807
Members
48,797
Latest member
PeterSimpson
Top