1. Jsf A Pdf Sat
  2. Convertir Formato Jsf A Pdf
  3. Jsf A Pdf En Linea

Iii JavaServer Faces Specification. March 2017 1.2.3 Application Developers 1–13 1.2.4 Tool Providers 1–13 1.2.5 JSF Implementors 1–14 1.3 Introduction to JSF APIs 1–14 1.3.1 package javax.faces 1–14. Files of the type JSP or files with the file extension.jsp can be easily converted to PDF with the help of a PDF printer. A PDF printer is a virtual printer which you can use like any other printer. The difference to a normal printer is that a PDF printer creates PDF files. You do not print on physical paper. JavaServer™ Faces (JSF) is the standard component-oriented user interface (UI) framework for the Java EE platform. In terms which may sound more familiar, it's a Java-based web framework. JSF is included in the Java EE platform, so you can create applications that use JSF without adding any extra libraries in your project.

Ranch Hand
Jsf A Pdfposted 15 years ago
  1. JavaServer Faces This IBM® Redpaper™ publication introduces the features, benefits, and architecture of JavaServer Faces (JSF), a framework that simplifies building user interfaces for web applications. This paper is intended for web developers interested in JSF. The paper includes.
  2. Java Server Faces (JSF) technology is a front end framework which makes the creation of user interface components easier by reusing the UI components. JSF is designed based on the Model View Controller pattern (MVC) which segregates the presentation, controller and the business logic.
what is the best way to have pdf if all my pages are in jsf?
i'm planning to let user to print in pdf format when they click the 'print' button.
any suggestions on how to start with it?

Jys<br /><a href='http://jy-s.com' target='_blank'>http://jy-s.com</a><br /> <br />Trying my very best to learn java, please forgive me if i'm asking some really stupid questions.

Ranch Hand
posted 15 years ago
Ranch Hand
posted 15 years ago
i've read the thread. hmm, by using this method provided i can actually convert my stuff into pdf?

and this line. response.getOutputStream().write(yourdata[]);
i will pass all the things i want to retrieve from database here? do u happened to have a complete example for me to refer?
thks in advance.

Jys<br /><a href='http://jy-s.com' target='_blank'>http://jy-s.com</a><br /> <br />Trying my very best to learn java, please forgive me if i'm asking some really stupid questions.

Rancher
posted 15 years ago
The code snippet assumes that the 'yourdata' array holds the contents of a PDF file. To create a PDF file from your database data, you will need to use some PDF library, such as mentioned here.
Ranch Hand
posted 15 years ago
so how will 'yourdata' look like? xml? html?
sorry, this is my first time generating pdf so i'm not really sure what do i need and how do i do that.

Jys<br /><a href='http://jy-s.com' target='_blank'>http://jy-s.com</a><br /> <br />Trying my very best to learn java, please forgive me if i'm asking some really stupid questions.

Rancher
posted 15 years ago
'yourdata' should contain a binary representation of the PDF file. That you can create by using a PDf libraray, as mentioned in my previous post. iText in particular has a thorough introduction.
Ranch Hand
posted 15 years agoJsf pdf export
from the iText eg, i see that most of it are using servlet. just wondering, is it possible to have pdf without using servlet?

Jys<br /><a href='http://jy-s.com' target='_blank'>http://jy-s.com</a><br /> <br />Trying my very best to learn java, please forgive me if i'm asking some really stupid questions.

Rancher
posted 15 years ago
The servlets just serve as examples. iText can be used in any kind of Java program.

Jsf A Pdf Sat

Ranch Hand
posted 15 years ago
So Jolie, any success? I mean, have you actually tried out any of the suggestions and code we've provided?
Ranch Hand
posted 15 years ago

Convertir Formato Jsf A Pdf

i've actually read thru the itext. and one of the example their using jsp with iText to generate..
hmm. might used that, but still not sure how they do column and etc . cos wat i can see is that they only using paragraph. cos i'm generating reports, so they will be a lot of columns and tables involves..
in my jsp page, how can i called the backing bean? cos if i were to use jsp to generate pdf(s), i may need to refer to backing beans to do retrieval from the database. and i think i won't have any jsf tags in that jsp page that generate pdf..

Jys<br /><a href='http://jy-s.com' target='_blank'>http://jy-s.com</a><br /> <br />Trying my very best to learn java, please forgive me if i'm asking some really stupid questions.

Ranch Hand
posted 15 years ago
Jolie, Jolie, Jolie..
Remember that method I showed you?

Ok, lets change that just a bit..

Now, supose you have a commandButton that calls a backing bean method called generatePDF(). Let's take a look at what that method might look like.

And that's it. It can all be done in the backing bean. That is what we have been trying to convey.
Greenhorn
posted 15 years ago
use this.
it will work
am doing this works great with itext.
public void executePDF() {
try {
FacesContext faces = FacesContext.getCurrentInstance();
HttpServletResponse response =
(HttpServletResponse) faces.getExternalContext().getResponse();
// setting some response headers
response.setHeader('Expires', '0');
response.setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
//response.setHeader('Content-disposition','inline; filename=kiran.pdf');
response.setHeader('Pragma', 'public');
response.setContentType( 'application/pdf' );
//response.setHeader('Content-Disposition', 'attachment;filename='ContactList.pdf');
response.addHeader('Content-disposition', 'attachment;filename='DataListBean.pdf');
//step 1: creation of a document-object
Document document = new Document(PageSize.A3.rotate(), 10, 10, 10, 10);
//step 2: we create a writer that listens to the document
// and directs a PDF-stream to a temporary buffer
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
PdfWriter writer = PdfWriter.getInstance( document, baos);
//step 3: we open the document
document.open();
Table datatable = getTable();
int rowCount = data.getRowCount();
// step 4: we add a paragraph to the document
for (int i=0;i<rowCount;i++) {
datatable.setDefaultHorizontalAlignment(Element.ALIGN_LEFT);
List list = (List)data.getRowData();
Iterator iter = list.iterator();
while(iter.hasNext()) {
Object obj = (Object) iter.next();
datatable.addCell(obj.toString());
if (i<=2) {
System.out.println(obj.toString());
}
}
if (!writer.fitsPage(datatable)) {
datatable.deleteLastRow();
i--;
document.add(datatable);
document.newPage();
datatable = getTable();
}
}
document.add(datatable);
//step 5: we close the document
document.close();
//step 6: we output the writer as bytes to the response output
// the contentlength is needed for MSIE!!!
response.setContentLength(baos.size());
// write ByteArrayOutputStream to the ServletOutputStream
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
baos.flush();
faces.responseComplete();
//DataOutput output = new DataOutputStream( response.getOutputStream() );
//byte[] bytes = buffer.toByteArray();
//response.setContentLength(bytes.length);
//for( int i = 0; i < bytes.length; i++ ) { output.writeByte( bytes[i] ); }
} catch(Exception e) {
e.printStackTrace();
}
}
private Table getTable()
throws BadElementException, DocumentException {
int colCount = columnHeaders.getRowCount();
Table datatable = new Table(colCount);
datatable.setPadding(4);
datatable.setSpacing(0);
datatable.setBorder(Rectangle.NO_BORDER);
int headerwidths[] = {14,3,3,9,8,5,14,9,5,3,1,4,4,10,3,3,2,10,10,2};
datatable.setWidths(headerwidths);
datatable.setWidth(140);
// the first cell spans 20 columns
Cell cell = new Cell(new Phrase('NEMO Order Tool Report',
FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD)));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setLeading(10);
cell.setColspan(20);
cell.setBorder(Rectangle.NO_BORDER);
cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
datatable.addCell(cell);
// These cells span n rows
datatable.setDefaultCellBorderWidth(1);
datatable.setDefaultHorizontalAlignment(1);
datatable.setDefaultRowspan(1);
List colList = (List)columnHeaders.getWrappedData();
for (int i=0; i < colList.size();i++) {
ColumnHeader header = (ColumnHeader) colList.get(i);
datatable.addCell(header.getLabel());
}
return datatable;
}
Greenhorn
posted 9 years ago

sridhar panini wrote:use this.
it will work
am doing this works great with itext.
public void executePDF() {
try {
FacesContext faces = FacesContext.getCurrentInstance();
HttpServletResponse response =
(HttpServletResponse) faces.getExternalContext().getResponse();
// setting some response headers
response.setHeader('Expires', '0');
response.setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
//response.setHeader('Content-disposition','inline; filename=kiran.pdf');
response.setHeader('Pragma', 'public');
response.setContentType( 'application/pdf' );
//response.setHeader('Content-Disposition', 'attachment;filename='ContactList.pdf');
response.addHeader('Content-disposition', 'attachment;filename='DataListBean.pdf');
//step 1: creation of a document-object
Document document = new Document(PageSize.A3.rotate(), 10, 10, 10, 10);
//step 2: we create a writer that listens to the document
// and directs a PDF-stream to a temporary buffer
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
PdfWriter writer = PdfWriter.getInstance( document, baos);
//step 3: we open the document
document.open();
Table datatable = getTable();
int rowCount = data.getRowCount();
// step 4: we add a paragraph to the document
for (int i=0;i<rowCount;i++) {
datatable.setDefaultHorizontalAlignment(Element.ALIGN_LEFT);
List list = (List)data.getRowData();
Iterator iter = list.iterator();
while(iter.hasNext()) {
Object obj = (Object) iter.next();
datatable.addCell(obj.toString());
if (i<=2) {
System.out.println(obj.toString());
}
}
if (!writer.fitsPage(datatable)) {
datatable.deleteLastRow();
i--;
document.add(datatable);
document.newPage();
datatable = getTable();
}
}
document.add(datatable);
//step 5: we close the document
document.close();
//step 6: we output the writer as bytes to the response output
// the contentlength is needed for MSIE!!!
response.setContentLength(baos.size());
// write ByteArrayOutputStream to the ServletOutputStream
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
baos.flush();
faces.responseComplete();
//DataOutput output = new DataOutputStream( response.getOutputStream() );
//byte[] bytes = buffer.toByteArray();
//response.setContentLength(bytes.length);
//for( int i = 0; i < bytes.length; i++ ) { output.writeByte( bytes[i] ); }
} catch(Exception e) {
e.printStackTrace();
}
}
private Table getTable()
throws BadElementException, DocumentException {
int colCount = columnHeaders.getRowCount();
Table datatable = new Table(colCount);
datatable.setPadding(4);
datatable.setSpacing(0);
datatable.setBorder(Rectangle.NO_BORDER);
int headerwidths[] = {14,3,3,9,8,5,14,9,5,3,1,4,4,10,3,3,2,10,10,2};
datatable.setWidths(headerwidths);
datatable.setWidth(140);
// the first cell spans 20 columns
Cell cell = new Cell(new Phrase('NEMO Order Tool Report',
FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD)));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setLeading(10);
cell.setColspan(20);
cell.setBorder(Rectangle.NO_BORDER);
cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
datatable.addCell(cell);
// These cells span n rows
datatable.setDefaultCellBorderWidth(1);
datatable.setDefaultHorizontalAlignment(1);
datatable.setDefaultRowspan(1);
List colList = (List)columnHeaders.getWrappedData();
for (int i=0; i < colList.size();i++) {
ColumnHeader header = (ColumnHeader) colList.get(i);
datatable.addCell(header.getLabel());
}
return datatable;
}


Hello sridhar panini,
Please, can you give me the libraries used for this code? Thank you
Ranch Hand
posted 9 years ago
Hello,
I will suggest use Jasper reports, you will get the PDF within no time.
I have the made a sample long ago. If you want let me know.
BR,

Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup

Greenhorn
posted 9 years ago
Hello Prithvi Sehgal,
I tried to use JasperReport 3.7.5 but I got some problemes. This my code with JasperReport

When I run this code, I get an empty pdf. Please can you help me to use Jasperreport to make my Reports.
Thank You
Ranch Hand
posted 9 years ago
Hello Boris,
I didn't look at the code before. Try to pick .jasper directly from IReport and see.
It should work. From where you data is coming?
HTH,

Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup

Ranch Hand
posted 9 years ago
Hello Boris,
I can see that you are using the compiler inside the code. I wanted to know from where
your data is coming?
Checkout my snippet of code.

BR,

Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup

Greenhorn
posted 9 years agoI try your code, but I get always an empty pdf

Eve eft for mac. I wanted to know from where your data is coming?


With ireport, I defined a Database JBDC Connexion. And, in my jrxml file, I used a query whose the database connexion parameters are defined in the Database JBDC Connexion. I hope that I answered correctly to your question. English isn't my mother tongue, so excuse me for my bad english
Jsf Thank you
Ranch Hand
posted 9 years ago
Hello Boris,
Thats true. So basically is your query parameter based, like a criteria query. For example, find all all employees
whose salary is greater then your specified parameter. If you see that, you are passing a empty hashmap to your
jrxml. You are not passing any parameters. You need to put your parameters in the hashmap and send that hashmap.
Be sure that your your parameter in Hashmap is of the same name as in the JRXML.
HTH,

Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup

Greenhorn
posted 9 years ago
I don't pass parameter because my query don't have parameter. You can see my jrxml file

Jsf A Pdf En Linea

Ranch Hand
posted 9 years ago
Hello Boris,
Where are you calling the getConnection() method to get the connection. In your code, i don't see anywhere that you are calling
the getConnection method.
Put in your printPdf() method as

I feel your connection reference is not properly initialized.
Have you checked your SQL in a editor like SQL editor, is it returning any results? Additionally, try to use the .jasper file directly and comment
the JRXML compile. To me your JRXML looks okay. Additionally, check is is your connection object null means is it able to correct to database
properly?
BR,

Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup

Greenhorn
posted 9 years ago
Hello,
Now the report is generated, but I can't open it because it is used by another process. After verification, this is the process 'java.exe' which use the genereted report.
I try to resolve it. Please, don't forget me If you have an idea to resolve the probleme.
I appreciate the attention you have given me
Ranch Hand
posted 9 years ago
Hello Boris,
Can you tell me what exception you are getting exactly? Additionally i would like to know did you try to use
.jasper file directly rather then using the built in compile utility.
BR,

Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup