Fórum gerar um PDF do Java para o client-side #618692
09/09/2022
0
estou criando esse pdf, mas queria saber como fazer que o usuario escolha o local onde o arquivo vai ser salvo, ate o momento so consegui salvar o pdf em um local pre determinado com o FileOutputStream e também o pdf esta sendo salvo do lado do servidor, alem do java estou usando javascript, ajax e struts2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | caminhoPDF = System.getProperty( "user.home" )+ "/Documents/DocumentProcessosAno.pdf" ; SimpleDateFormat dataFormat = new SimpleDateFormat( "dd/MM/yyyy" ); Document document = new Document(); PdfWriter.getInstance(document, ( new FileOutputStream(caminhoPDF))); document.open(); Paragraph preface = new Paragraph(); preface.add( new Paragraph( "Teste" ,catFont)); preface.setAlignment(Element.ALIGN_MIDDLE); preface.add( new Paragraph( " " )); preface.add( new Paragraph( "Solicitado Pelo Usuario: " + System.getProperty( "user.name" ) + ", Data de Expedição: " + dataFormat.format( new Date()) ,smallBold)); preface.setAlignment(Element.ALIGN_MIDDLE); preface.add( new Paragraph( " " )); preface.setAlignment(Element.ALIGN_MIDDLE); document.add(preface); document.close(); |

Vinicius Tork
Curtir tópico
+ 0
Responder
Posts
12/09/2022
Sergio Teixeira
estou criando esse pdf, mas queria saber como fazer que o usuario escolha o local onde o arquivo vai ser salvo, ate o momento so consegui salvar o pdf em um local pre determinado com o FileOutputStream e também o pdf esta sendo salvo do lado do servidor, alem do java estou usando javascript, ajax e struts2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | caminhoPDF = System.getProperty( "user.home" )+ "/Documents/DocumentProcessosAno.pdf" ; SimpleDateFormat dataFormat = new SimpleDateFormat( "dd/MM/yyyy" ); Document document = new Document(); PdfWriter.getInstance(document, ( new FileOutputStream(caminhoPDF))); document.open(); Paragraph preface = new Paragraph(); preface.add( new Paragraph( "Teste" ,catFont)); preface.setAlignment(Element.ALIGN_MIDDLE); preface.add( new Paragraph( " " )); preface.add( new Paragraph( "Solicitado Pelo Usuario: " + System.getProperty( "user.name" ) + ", Data de Expedição: " + dataFormat.format( new Date()) ,smallBold)); preface.setAlignment(Element.ALIGN_MIDDLE); preface.add( new Paragraph( " " )); preface.setAlignment(Element.ALIGN_MIDDLE); document.add(preface); document.close(); |
Responder
Gostei + 0
12/09/2022
Sergio Teixeira
Se você esta utilizando java utilize JFileChooser e seus recursos
JFileChooser jfc = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory());
//int returnValue = jfc.showOpenDialog(null);
int returnValue = jfc.showSaveDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
File selectedFile = jfc.getSelectedFile();
System.out.println(selectedFile.getAbsolutePath());
}
}
}
JFileChooser jfc = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory());
//int returnValue = jfc.showOpenDialog(null);
int returnValue = jfc.showSaveDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
File selectedFile = jfc.getSelectedFile();
System.out.println(selectedFile.getAbsolutePath());
}
}
}
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)